update 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. check_exit() {
  13. if [ $? -ne 0 ];then
  14. echo "Update failed."
  15. exit 1
  16. fi
  17. }
  18. prepare() {
  19. cd /
  20. umount -f /etc
  21. mount -o remount,rw /
  22. }
  23. extract_from_file() {
  24. prepare
  25. cat $1 | eval $updatecmd
  26. check_exit
  27. }
  28. extract_from_ssh() {
  29. prepare
  30. ssh $1 "cat $2" | eval $updatecmd
  31. check_exit
  32. }
  33. extract_from_http() {
  34. prepare
  35. wget -O - $1 | eval $updatecmd
  36. check_exit
  37. }
  38. case $1 in
  39. file://*|/*)
  40. url=$(echo $1|sed -e "s#file://##")
  41. echo "Updating system from $1"
  42. extract_from_file $url
  43. ;;
  44. ssh://*)
  45. host=$(echo $1|sed -e "s#ssh://\(.*\):.*#\1#")
  46. file=$(echo $1|sed -e "s#ssh://.*:\(.*\)#\1#")
  47. echo "Updating system from $1"
  48. extract_from_ssh $host $file
  49. ;;
  50. http://*|ftp://*)
  51. echo "Updating system from $1"
  52. extract_from_http $1
  53. ;;
  54. *)
  55. echo "No or wrong uri given. exit."
  56. echo "Use one of the following uri:"
  57. echo "http://myserver/myupdate.tar.gz"
  58. echo "ssh://myuser@myserver:/my/path/myupdate.tar.gz"
  59. echo "file:///mypath/myupdate.tar.gz"
  60. exit 1
  61. ;;
  62. esac
  63. sync
  64. mount -o bind /etc /tmp/.cfgfs/root
  65. echo "Update sucessful. You should reboot now."