adkupdate 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. umount -f /etc
  27. fi
  28. mount -o remount,rw /
  29. if [ "$system" == "RB532" ];then
  30. mount -t yaffs2 /dev/mtdblock0 /boot
  31. elif [ "$system" == "AR7130" ];then
  32. mount -t yaffs2 /dev/mtdblock1 /boot
  33. elif [ "$system" == "FOXG20" ];then
  34. mount -t vfat /dev/mmcblk0p1 /boot
  35. fi
  36. }
  37. extract_from_file() {
  38. prepare
  39. cat $1 | eval $updatecmd
  40. check_exit
  41. }
  42. extract_from_ssh() {
  43. prepare
  44. ssh $1 "cat $2" | eval $updatecmd
  45. check_exit
  46. }
  47. extract_from_http() {
  48. prepare
  49. wget -O - $1 | eval $updatecmd
  50. check_exit
  51. }
  52. case $1 in
  53. file://*|/*)
  54. url=$(echo $1|sed -e "s#file://##")
  55. echo "Updating system from $1"
  56. extract_from_file $url
  57. ;;
  58. ssh://*)
  59. host=$(echo $1|sed -e "s#ssh://\(.*\):.*#\1#")
  60. file=$(echo $1|sed -e "s#ssh://.*:\(.*\)#\1#")
  61. echo "Updating system from $1"
  62. extract_from_ssh $host $file
  63. ;;
  64. http://*|ftp://*)
  65. echo "Updating system from $1"
  66. extract_from_http $1
  67. ;;
  68. *)
  69. echo "No or wrong uri given. exit."
  70. echo "Use one of the following uri:"
  71. echo "http://myserver/myupdate.tar.gz"
  72. echo "ssh://myuser@myserver:/my/path/myupdate.tar.gz"
  73. echo "file:///mypath/myupdate.tar.gz"
  74. exit 1
  75. ;;
  76. esac
  77. sync
  78. if [ -x /sbin/cfgfs ];then
  79. mount -o bind /etc /tmp/.cfgfs/root
  80. fi
  81. if [ "$system" == "RB532" ];then
  82. umount -f /boot
  83. elif [ "$system" == "AR7130" ];then
  84. umount -f /boot
  85. elif [ "$system" == "FOXG20" ];then
  86. umount -f /boot
  87. fi
  88. echo "Update sucessful. You should reboot now."