snapshot 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/sh
  2. # Copyright (C) 2014 OpenWrt.org
  3. do_snapshot_unpack() {
  4. echo "- snapshot -"
  5. mkdir /tmp/snapshot
  6. cd /tmp/snapshot
  7. snapshot_tool read
  8. block=`ls block*.tar.gz 2> /dev/null`
  9. [ -z "$block" ] || for a in $block; do
  10. tar xzf $a -C /
  11. rm -f $a
  12. done
  13. }
  14. do_config_unpack() {
  15. echo "- config -"
  16. snapshot_tool config_read
  17. [ -f /tmp/config.tar.gz ] && {
  18. tar xzf /tmp/config.tar.gz -C /
  19. rm -f /tmp/config.tar.gz
  20. }
  21. }
  22. do_snapshot_push() {
  23. cd /volatile/upper
  24. tar czf /tmp/snapshot.tar.gz *
  25. snapshot_tool write
  26. reboot
  27. }
  28. do_config_push() {
  29. cd /volatile/upper
  30. tar czf /tmp/config.tar.gz *
  31. snapshot_tool config_write
  32. }
  33. do_snapshot_upgrade() {
  34. opkg update
  35. [ $? -eq 0 ] || exit 1
  36. opkg list-upgradable
  37. [ $? -eq 0 ] || exit 2
  38. UPDATES=`opkg list-upgradable | cut -d" " -f1`
  39. [ -z "${UPDATES}" ] && exit 0
  40. opkg upgrade ${UPDATES}
  41. [ $? -eq 0 ] || exit 3
  42. do_snapshot_push
  43. sleep 5
  44. reboot
  45. sleep 10
  46. }
  47. do_convert_jffs2() {
  48. snapshot_tool write
  49. sleep 2
  50. reboot -f
  51. }
  52. do_convert() {
  53. . /lib/functions.sh
  54. . /lib/upgrade/common.sh
  55. ubus call system upgrade
  56. touch /tmp/sysupgrade
  57. cd /overlay/upper
  58. tar czf /tmp/snapshot.tar.gz *
  59. kill_remaining TERM
  60. sleep 3
  61. kill_remaining KILL
  62. run_ramfs '. /sbin/snapshot; do_convert_jffs2'
  63. }
  64. [ -n "$(cat /proc/mounts|grep /overlay|grep jffs2)" ] && {
  65. case $1 in
  66. convert)
  67. do_convert
  68. ;;
  69. esac
  70. }
  71. [ -d /volatile/upper ] && {
  72. case $1 in
  73. push)
  74. do_snapshot_push
  75. ;;
  76. config)
  77. do_config_push
  78. ;;
  79. upgrade)
  80. do_snapshot_upgrade
  81. ;;
  82. info)
  83. snapshot_tool info
  84. ;;
  85. esac
  86. }
  87. [ "$SNAPSHOT" = "magic" ] && {
  88. case $1 in
  89. unpack)
  90. do_snapshot_unpack
  91. ;;
  92. config_unpack)
  93. do_config_unpack
  94. ;;
  95. esac
  96. }