4 .
/lib
/functions
/system.sh
7 RAMFS_COPY_BIN
="" # extra programs for temporary ramfs root
8 RAMFS_COPY_DATA
="" # extra data files
9 export MTD_CONFIG_ARGS
=""
14 export SAVE_PARTITIONS
=1
16 export CONF_BACKUP_LIST
=0
27 -i) export INTERACTIVE
=1;;
28 -v) export VERBOSE
="$(($VERBOSE + 1))";;
29 -q) export VERBOSE
="$(($VERBOSE - 1))";;
30 -n) export SAVE_CONFIG
=0;;
31 -c) export SAVE_OVERLAY
=1;;
32 -p) export SAVE_PARTITIONS
=0;;
33 -b|
--create-backup) export CONF_BACKUP
="$2" NEED_IMAGE
=1; shift;;
34 -r|
--restore-backup) export CONF_RESTORE
="$2" NEED_IMAGE
=1; shift;;
35 -l|
--list-backup) export CONF_BACKUP_LIST
=1; break;;
36 -f) export CONF_IMAGE
="$2"; shift;;
37 -F|
--force) export FORCE
=1;;
38 -T|
--test) export TEST
=1;;
39 -h|
--help) export HELP
=1; break;;
41 echo "Invalid option: $1"
49 export CONFFILES
=/tmp
/sysupgrade.conffiles
50 export CONF_TAR
=/tmp
/sysupgrade.tgz
54 [ -z "$IMAGE" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
56 Usage: $0 [<upgrade-option>...] <image file or URL>
57 $0 [-q] [-i] <backup-command> <file>
60 -d <delay> add a delay before rebooting
61 -f <config> restore configuration from .tar.gz (file or url)
63 -c attempt to preserve all changed files in /etc/
64 -n do not save configuration over reflash
65 -p do not attempt to restore the partition table after flash.
67 Verify image and config .tar.gz but do not actually flash.
69 Flash image even if image checks fail, this is dangerous!
72 -h | --help display this help
75 -b | --create-backup <file>
76 create .tar.gz of files specified in sysupgrade.conf
77 then exit. Does not flash an image. If file is '-',
78 i.e. stdout, verbosity is set to 0 (i.e. quiet).
79 -r | --restore-backup <file>
80 restore a .tar.gz created with sysupgrade -b
81 then exit. Does not flash an image. If file is '-',
82 the archive is read from stdin.
84 list the files that would be backed up when calling
85 sysupgrade -b. Does not create a backup file.
91 [ -n "$IMAGE" -a -n "$NEED_IMAGE" ] && {
93 -b|--create-backup and -r|--restore-backup do not perform a firmware upgrade.
94 Do not specify both -b|-r and a firmware image.
99 # prevent messages from clobbering the tarball when using stdout
100 [ "$CONF_BACKUP" = "-" ] && export VERBOSE
=0
102 add_uci_conffiles
() {
104 ( find $
(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
105 /etc
/sysupgrade.conf
/lib
/upgrade
/keep.d
/* 2>/dev
/null
) \
106 -type f
-o -type l
2>/dev
/null
;
107 opkg list-changed-conffiles
) |
sort -u > "$file"
113 if [ -d /overlay
/upper
]; then
114 local overlaydir
="/overlay/upper"
116 local overlaydir
="/overlay"
118 find $overlaydir/etc
/ -type f
-o -type l |
sed \
119 -e 's,^/overlay\/upper/,/,' \
120 -e 's,^/overlay/,/,' \
121 -e '\,/META_[a-zA-Z0-9]*$,d' \
122 -e '\,/functions.sh$,d' \
123 -e '\,/[^/]*-opkg$,d' \
129 sysupgrade_image_check
="fwtool_check_image platform_check_image"
130 sysupgrade_pre_upgrade
="fwtool_pre_upgrade"
131 [ $SAVE_OVERLAY = 0 -o ! -d /overlay
/etc
] && \
132 sysupgrade_init_conffiles
="add_uci_conffiles" || \
133 sysupgrade_init_conffiles
="add_overlayfiles"
137 do_save_conffiles
() {
138 local conf_tar
="${1:-$CONF_TAR}"
140 [ -z "$(rootfs_type)" ] && {
141 echo "Cannot save config while running from ramdisk."
142 ask_bool
0 "Abort" && exit
146 run_hooks
"$CONFFILES" $sysupgrade_init_conffiles
147 ask_bool
0 "Edit config file list" && vi
"$CONFFILES"
149 v
"Saving config files..."
150 [ "$VERBOSE" -gt 1 ] && TAR_V
="v" || TAR_V
=""
151 tar c
${TAR_V}zf
"$conf_tar" -T "$CONFFILES" 2>/dev
/null
156 if [ $CONF_BACKUP_LIST -eq 1 ]; then
157 add_uci_conffiles
"$CONFFILES"
163 if [ -n "$CONF_BACKUP" ]; then
164 do_save_conffiles
"$CONF_BACKUP"
168 if [ -n "$CONF_RESTORE" ]; then
169 if [ "$CONF_RESTORE" != "-" ] && [ ! -f "$CONF_RESTORE" ]; then
170 echo "Backup archive '$CONF_RESTORE' not found."
174 [ "$VERBOSE" -gt 1 ] && TAR_V
="v" || TAR_V
=""
175 tar -C / -x${TAR_V}zf
"$CONF_RESTORE"
179 type platform_check_image
>/dev
/null
2>/dev
/null ||
{
180 echo "Firmware upgrade is not implemented for this platform."
186 wget
-O/tmp
/sysupgrade.img
"$IMAGE"
187 IMAGE
=/tmp
/sysupgrade.img
191 IMAGE
="$(readlink -f "$IMAGE")"
195 echo "Image file not found."
200 v
"Image not in /tmp, copying..."
201 cp -f "$IMAGE" /tmp
/sysupgrade.img
202 IMAGE
=/tmp
/sysupgrade.img
209 for check
in $sysupgrade_image_check; do
210 ( $check "$IMAGE" ) ||
{
211 if [ $FORCE -eq 1 ]; then
212 echo "Image check '$check' failed but --force given - will update anyway!"
215 echo "Image check '$check' failed."
221 if [ -n "$CONF_IMAGE" ]; then
222 case "$(get_magic_word $CONF_IMAGE cat)" in
226 echo "Invalid config file. Please use only .tar.gz files"
230 get_image
"$CONF_IMAGE" "cat" > "$CONF_TAR"
232 elif ask_bool
$SAVE_CONFIG "Keep config files over reflash"; then
233 [ $TEST -eq 1 ] || do_save_conffiles
236 [ $TEST -eq 1 ] ||
rm -f "$CONF_TAR"
240 if [ $TEST -eq 1 ]; then
244 if [ $SAVE_PARTITIONS -eq 0 ]; then
245 touch /tmp
/sysupgrade.always.overwrite.bootdisk.partmap
247 rm -f /tmp
/sysupgrade.always.overwrite.bootdisk.partmap
250 run_hooks
"" $sysupgrade_pre_upgrade
252 install_bin
/sbin
/upgraded
253 v
"Commencing upgrade. All shell sessions will be closed now."
254 ubus call system sysupgrade
"{
255 \"prefix\": \"$RAM_ROOT\",
256 \"path\": $(json_string "$IMAGE"),
257 \"command\": \". /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2\"