update 1.3 KB

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