adkupdate 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. who=$(id -u)
  3. if [ $who -ne 0 ]; then
  4. echo 'Exit. System update must be run as root.'
  5. exit 1
  6. fi
  7. if [ -x /sbin/mtd ];then
  8. updatecmd="mtd -r write - linux"
  9. else
  10. updatecmd="gunzip -c | tar -xf -"
  11. fi
  12. system=$(awk '/system type/ { print $5 }' /proc/cpuinfo 2>/dev/null)
  13. check_exit() {
  14. if [ $? -ne 0 ];then
  15. echo "Update failed."
  16. exit 1
  17. fi
  18. }
  19. prepare() {
  20. cd /
  21. umount -f /etc
  22. mount -o remount,rw /
  23. if [ "$system" == "RB532" ];then
  24. mount -t yaffs2 /dev/mtdblock0 /boot
  25. fi
  26. }
  27. extract_from_file() {
  28. prepare
  29. cat $1 | eval $updatecmd
  30. check_exit
  31. }
  32. extract_from_ssh() {
  33. prepare
  34. ssh $1 "cat $2" | eval $updatecmd
  35. check_exit
  36. }
  37. extract_from_http() {
  38. prepare
  39. wget -O - $1 | eval $updatecmd
  40. check_exit
  41. }
  42. case $1 in
  43. file://*|/*)
  44. url=$(echo $1|sed -e "s#file://##")
  45. echo "Updating system from $1"
  46. extract_from_file $url
  47. ;;
  48. ssh://*)
  49. host=$(echo $1|sed -e "s#ssh://\(.*\):.*#\1#")
  50. file=$(echo $1|sed -e "s#ssh://.*:\(.*\)#\1#")
  51. echo "Updating system from $1"
  52. extract_from_ssh $host $file
  53. ;;
  54. http://*|ftp://*)
  55. echo "Updating system from $1"
  56. extract_from_http $1
  57. ;;
  58. *)
  59. echo "No or wrong uri given. exit."
  60. echo "Use one of the following uri:"
  61. echo "http://myserver/myupdate.tar.gz"
  62. echo "ssh://myuser@myserver:/my/path/myupdate.tar.gz"
  63. echo "file:///mypath/myupdate.tar.gz"
  64. exit 1
  65. ;;
  66. esac
  67. sync
  68. mount -o bind /etc /tmp/.cfgfs/root
  69. echo "Update sucessful. You should reboot now."