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