adkupdate 2.0 KB

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