adkupdate 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. system=$(awk '/system type/ { print $5 }' /proc/cpuinfo 2>/dev/null)
  8. if [ -x /sbin/mtd ];then
  9. if [ "$system" == "AR7" ];then
  10. updatecmd="dd bs=16 skip=3 | mtd -r write - linux"
  11. else
  12. updatecmd="mtd -r write - linux"
  13. fi
  14. else
  15. updatecmd="gunzip -c | tar -xf -"
  16. fi
  17. check_exit() {
  18. if [ $? -ne 0 ];then
  19. echo "Update failed."
  20. exit 1
  21. fi
  22. }
  23. prepare() {
  24. cd /
  25. if [ -x /sbin/cfgfs ];then
  26. mount -o bind /tmp/.cfgfs/root /etc
  27. check_exit
  28. mount -o remount,rw /etc
  29. check_exit
  30. fi
  31. mount -o remount,rw /
  32. check_exit
  33. if [ "$system" == "RB532" ];then
  34. mount -t yaffs2 /dev/mtdblock0 /boot
  35. elif [ "$system" == "AR7130" ];then
  36. mount -t yaffs2 /dev/mtdblock1 /boot
  37. elif [ "$system" == "FOXG20" ];then
  38. mount -t vfat /dev/mmcblk0p1 /boot
  39. fi
  40. }
  41. extract_from_file() {
  42. prepare
  43. cat $1 | eval $updatecmd
  44. check_exit
  45. }
  46. extract_from_ssh() {
  47. prepare
  48. ssh $1 "cat $2" | eval $updatecmd
  49. check_exit
  50. }
  51. extract_from_http() {
  52. prepare
  53. wget -O - $1 | eval $updatecmd
  54. check_exit
  55. }
  56. case $1 in
  57. file://*|/*)
  58. url=$(echo $1|sed -e "s#file://##")
  59. echo "Updating system from $1"
  60. extract_from_file $url
  61. ;;
  62. ssh://*)
  63. host=$(echo $1|sed -e "s#ssh://\(.*\):.*#\1#")
  64. file=$(echo $1|sed -e "s#ssh://.*:\(.*\)#\1#")
  65. echo "Updating system from $1"
  66. extract_from_ssh $host $file
  67. ;;
  68. http://*|ftp://*)
  69. echo "Updating system from $1"
  70. extract_from_http $1
  71. ;;
  72. *)
  73. echo "No or wrong uri given. exit."
  74. echo "Use one of the following uri:"
  75. echo "http://myserver/myupdate.tar.gz"
  76. echo "ssh://myuser@myserver:/my/path/myupdate.tar.gz"
  77. echo "file:///mypath/myupdate.tar.gz"
  78. exit 1
  79. ;;
  80. esac
  81. # fix permissions
  82. if [ -f /usr/bin/sudo ];then
  83. chmod 4755 /usr/bin/sudo
  84. fi
  85. if [ -f /usr/bin/Xorg ];then
  86. chmod 4755 /usr/bin/Xorg
  87. fi
  88. sync
  89. if [ -x /sbin/cfgfs ];then
  90. umount /etc
  91. fi
  92. if [ "$system" == "RB532" ];then
  93. umount -f /boot
  94. elif [ "$system" == "AR7130" ];then
  95. umount -f /boot
  96. elif [ "$system" == "FOXG20" ];then
  97. umount -f /boot
  98. fi
  99. echo "Update sucessful. You should reboot now."