3 .
/lib
/functions
/system.sh
6 RAMFS_COPY_BIN
="" # extra programs for temporary ramfs root
7 RAMFS_COPY_DATA
="" # extra data files
8 export MTD_CONFIG_ARGS
=""
13 export SAVE_PARTITIONS
=1
16 export CONF_BACKUP_LIST
=0
27 -i) export INTERACTIVE
=1;;
28 -d) export DELAY
="$2"; shift;;
29 -v) export VERBOSE
="$(($VERBOSE + 1))";;
30 -q) export VERBOSE
="$(($VERBOSE - 1))";;
31 -n) export SAVE_CONFIG
=0;;
32 -c) export SAVE_OVERLAY
=1;;
33 -p) export SAVE_PARTITIONS
=0;;
34 -b|
--create-backup) export CONF_BACKUP
="$2" NEED_IMAGE
=1; shift;;
35 -r|
--restore-backup) export CONF_RESTORE
="$2" NEED_IMAGE
=1; shift;;
36 -l|
--list-backup) export CONF_BACKUP_LIST
=1; break;;
37 -f) export CONF_IMAGE
="$2"; shift;;
38 -F|
--force) export FORCE
=1;;
39 -T|
--test) export TEST
=1;;
40 -h|
--help) export HELP
=1; break;;
42 echo "Invalid option: $1"
50 export CONFFILES
=/tmp
/sysupgrade.conffiles
51 export CONF_TAR
=/tmp
/sysupgrade.tgz
56 [ -z "$ARGV" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
58 Usage: $0 [<upgrade-option>...] <image file or URL>
59 $0 [-q] [-i] <backup-command> <file>
62 -d <delay> add a delay before rebooting
63 -f <config> restore configuration from .tar.gz (file or url)
65 -c attempt to preserve all changed files in /etc/
66 -n do not save configuration over reflash
67 -p do not attempt to restore the partition table after flash.
69 Verify image and config .tar.gz but do not actually flash.
71 Flash image even if image checks fail, this is dangerous!
74 -h | --help display this help
77 -b | --create-backup <file>
78 create .tar.gz of files specified in sysupgrade.conf
79 then exit. Does not flash an image. If file is '-',
80 i.e. stdout, verbosity is set to 0 (i.e. quiet).
81 -r | --restore-backup <file>
82 restore a .tar.gz created with sysupgrade -b
83 then exit. Does not flash an image. If file is '-',
84 the archive is read from stdin.
86 list the files that would be backed up when calling
87 sysupgrade -b. Does not create a backup file.
93 [ -n "$ARGV" -a -n "$NEED_IMAGE" ] && {
95 -b|--create-backup and -r|--restore-backup do not perform a firmware upgrade.
96 Do not specify both -b|-r and a firmware image.
101 # prevent messages from clobbering the tarball when using stdout
102 [ "$CONF_BACKUP" = "-" ] && export VERBOSE
=0
104 add_uci_conffiles
() {
106 ( find $
(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
107 /etc
/sysupgrade.conf
/lib
/upgrade
/keep.d
/* 2>/dev
/null
) \
108 -type f
-o -type l
2>/dev
/null
;
109 opkg list-changed-conffiles
) |
sort -u > "$file"
115 if [ -d /overlay
/upper
]; then
116 local overlaydir
="/overlay/upper"
118 local overlaydir
="/overlay"
120 find $overlaydir/etc
/ -type f
-o -type l |
sed \
121 -e 's,^/overlay\/upper/,/,' \
122 -e 's,^/overlay/,/,' \
123 -e '\,/META_[a-zA-Z0-9]*$,d' \
124 -e '\,/functions.sh$,d' \
125 -e '\,/[^/]*-opkg$,d' \
131 sysupgrade_image_check
="fwtool_check_image platform_check_image"
132 sysupgrade_pre_upgrade
="fwtool_pre_upgrade"
133 [ $SAVE_OVERLAY = 0 -o ! -d /overlay
/etc
] && \
134 sysupgrade_init_conffiles
="add_uci_conffiles" || \
135 sysupgrade_init_conffiles
="add_overlayfiles"
139 [ "$1" = "nand" ] && nand_upgrade_stage2 $@
141 do_save_conffiles
() {
142 local conf_tar
="${1:-$CONF_TAR}"
144 [ -z "$(rootfs_type)" ] && {
145 echo "Cannot save config while running from ramdisk."
146 ask_bool
0 "Abort" && exit
149 run_hooks
"$CONFFILES" $sysupgrade_init_conffiles
150 ask_bool
0 "Edit config file list" && vi
"$CONFFILES"
152 v
"Saving config files..."
153 [ "$VERBOSE" -gt 1 ] && TAR_V
="v" || TAR_V
=""
154 tar c
${TAR_V}zf
"$conf_tar" -T "$CONFFILES" 2>/dev
/null
159 if [ $CONF_BACKUP_LIST -eq 1 ]; then
160 add_uci_conffiles
"$CONFFILES"
166 if [ -n "$CONF_BACKUP" ]; then
167 do_save_conffiles
"$CONF_BACKUP"
171 if [ -n "$CONF_RESTORE" ]; then
172 if [ "$CONF_RESTORE" != "-" ] && [ ! -f "$CONF_RESTORE" ]; then
173 echo "Backup archive '$CONF_RESTORE' not found."
177 [ "$VERBOSE" -gt 1 ] && TAR_V
="v" || TAR_V
=""
178 tar -C / -x${TAR_V}zf
"$CONF_RESTORE"
182 type platform_check_image
>/dev
/null
2>/dev
/null ||
{
183 echo "Firmware upgrade is not implemented for this platform."
187 for check
in $sysupgrade_image_check; do
188 ( eval "$check \"\$ARGV\"" ) ||
{
189 if [ $FORCE -eq 1 ]; then
190 echo "Image check '$check' failed but --force given - will update anyway!"
193 echo "Image check '$check' failed."
199 if [ -n "$CONF_IMAGE" ]; then
200 case "$(get_magic_word $CONF_IMAGE cat)" in
204 echo "Invalid config file. Please use only .tar.gz files"
208 get_image
"$CONF_IMAGE" "cat" > "$CONF_TAR"
210 elif ask_bool
$SAVE_CONFIG "Keep config files over reflash"; then
211 [ $TEST -eq 1 ] || do_save_conffiles
217 if [ $TEST -eq 1 ]; then
221 run_hooks
"" $sysupgrade_pre_upgrade
223 # Some platforms/devices may want different sysupgrade process, e.g. without
224 # killing processes yet or calling ubus system upgrade method.
225 # This is needed e.g. on NAND devices where we just want to trigger stage1 at
227 if type 'platform_pre_upgrade' >/dev
/null
2>/dev
/null
; then
228 platform_pre_upgrade
"$ARGV"
231 ubus call system upgrade
232 touch /tmp
/sysupgrade
234 if [ ! -f /tmp
/failsafe
] ; then
240 if [ -n "$(rootfs_type)" ]; then
241 v
"Switching to ramdisk..."
242 run_ramfs
'. /lib/functions.sh; include /lib/upgrade; do_upgrade'