1
0

update 1.4 KB

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