5 RAMFS_COPY_BIN="" # extra programs for temporary ramfs root
6 RAMFS_COPY_DATA="" # extra data files
21 -i) export INTERACTIVE=1;;
22 -d) export DELAY="$2"; shift;;
23 -v) export VERBOSE="$(($VERBOSE + 1))";;
24 -q) export VERBOSE="$(($VERBOSE - 1))";;
25 -n) export SAVE_CONFIG=0;;
26 -c) export SAVE_OVERLAY=1;;
27 -b|--create-backup) export CONF_BACKUP="$2"; shift;;
28 -r|--restore-backup) export CONF_RESTORE="$2"; shift;;
29 -f) export CONF_IMAGE="$2"; shift;;
30 -F|--force) export FORCE=1;;
31 -h|--help) export HELP=1; break;;
33 echo "Invalid option: $1"
41 export CONFFILES=/tmp/sysupgrade.conffiles
42 export CONF_TAR=/tmp/sysupgrade.tgz
47 [ -z "$ARGV" -a -z "$CONF_BACKUP" -o $HELP -gt 0 ] && {
49 Usage: $0 [options] <image file or URL>
52 -d <delay> add a delay before rebooting
53 -f <config> restore configuration from .tar.gz (file or url)
55 -c attempt to preserve all changed files in /etc/
56 -b / --create-backup <file>
57 create .tar.gz of files specified in sysupgrade.conf
58 then exit. Does not flash an image. If file is '-',
59 i.e. stdout, verbosity is set to 0 (i.e. quiet).
60 -r / --restore-backup <file>
61 restore a .tar.gz created with sysupgrade -b
62 then exit. Does not flash an image. If file is '-',
63 the archive is read from stdin.
64 -n do not save configuration over reflash
66 Flash image even if image checks fail, this is dangerous!
69 -h / --help display this help
75 [ -n "$ARGV" -a -n "$CONF_BACKUP" ] && {
77 -b/--create-backup does not perform a firmware upgrade. Do not
78 specify both -b and a firmware image.
83 # prevent messages from clobbering the tarball when using stdout
84 [ "$CONF_BACKUP" = "-" ] && export VERBOSE=0
88 ( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
89 /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
91 opkg list-changed-conffiles ) | sort -u > "$file"
97 find /overlay/etc/ -type f | sed \
98 -e 's,^/overlay/,/,' \
99 -e '\,/META_[a-zA-Z0-9]*$,d' \
100 -e '\,/functions.sh$,d' \
101 -e '\,/[^/]*-opkg$,d' \
107 sysupgrade_image_check="platform_check_image"
108 [ $SAVE_OVERLAY = 0 -o ! -d /overlay/etc ] && \
109 sysupgrade_init_conffiles="add_uci_conffiles" || \
110 sysupgrade_init_conffiles="add_overlayfiles"
114 do_save_conffiles() {
115 local conf_tar="${1:-$CONF_TAR}"
117 [ -z "$(rootfs_type)" ] && {
118 echo "Cannot save config while running from ramdisk."
119 ask_bool 0 "Abort" && exit
122 run_hooks "$CONFFILES" $sysupgrade_init_conffiles
123 ask_bool 0 "Edit config file list" && vi "$CONFFILES"
125 v "Saving config files..."
126 [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
127 tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
130 if [ -n "$CONF_BACKUP" ]; then
131 do_save_conffiles "$CONF_BACKUP"
135 if [ -f "$CONF_RESTORE" ] || [ "$CONF_RESTORE" = "-" ]; then
136 [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
137 tar -C / -x${TAR_V}zf "$CONF_RESTORE"
141 type platform_check_image >/dev/null 2>/dev/null || {
142 echo "Firmware upgrade is not implemented for this platform."
146 for check in $sysupgrade_image_check; do
147 ( eval "$check \"\$ARGV\"" ) || {
148 if [ $FORCE -eq 1 ]; then
149 echo "Image check '$check' failed but --force given - will update anyway!"
152 echo "Image check '$check' failed."
158 if [ -n "$CONF_IMAGE" ]; then
159 case "$(get_magic_word $CONF_IMAGE cat)" in
163 echo "Invalid config file. Please use only .tar.gz files"
167 get_image "$CONF_IMAGE" "cat" > "$CONF_TAR"
169 elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
176 run_hooks "" $sysupgrade_pre_upgrade
182 if [ -n "$(rootfs_type)" ]; then
183 v "Switching to ramdisk..."
184 run_ramfs '. /lib/functions.sh; include /lib/upgrade; do_upgrade'