update 1.4 KB

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