aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files
diff options
context:
space:
mode:
Diffstat (limited to 'package/base-files')
-rwxr-xr-xpackage/base-files/files/sbin/sysupgrade52
1 files changed, 48 insertions, 4 deletions
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index d4bb7a164f..55c323d001 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -9,6 +9,7 @@ export INTERACTIVE=0
export VERBOSE=1
export SAVE_CONFIG=1
export SAVE_OVERLAY=0
+export SAVE_OVERLAY_PATH=
export SAVE_PARTITIONS=1
export SKIP_UNCHANGED=0
export CONF_IMAGE=
@@ -27,7 +28,8 @@ while [ -n "$1" ]; do
-v) export VERBOSE="$(($VERBOSE + 1))";;
-q) export VERBOSE="$(($VERBOSE - 1))";;
-n) export SAVE_CONFIG=0;;
- -c) export SAVE_OVERLAY=1;;
+ -c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
+ -o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
@@ -54,12 +56,14 @@ IMAGE="$1"
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && {
cat <<EOF
Usage: $0 [<upgrade-option>...] <image file or URL>
- $0 [-q] [-i] [-c] [-u] <backup-command> <file>
+ $0 [-q] [-i] [-c] [-u] [-o] <backup-command> <file>
upgrade-option:
-f <config> restore configuration from .tar.gz (file or url)
-i interactive mode
-c attempt to preserve all changed files in /etc/
+ -o attempt to preserve all changed files in /, except those
+ from packages but including changed confs.
-u skip from backup files that are equal to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
@@ -129,12 +133,52 @@ add_conffiles() {
add_overlayfiles() {
local file="$1"
- ( cd /overlay/upper/; find ./etc \( -type f -o -type l \) $find_filter | sed \
+
+ local packagesfiles=$1.packagesfiles
+ touch "$packagesfiles"
+
+ if [ "$SAVE_OVERLAY_PATH" = / ]; then
+ local conffiles=$1.conffiles
+ local keepfiles=$1.keepfiles
+
+ list_conffiles | cut -f2 -d ' ' | sort -u > "$conffiles"
+
+ # backup files from /etc/sysupgrade.conf and /lib/upgrade/keep.d, but
+ # ignore those aready controlled by opkg conffiles
+ find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
+ /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
+ \( -type f -o -type l \) 2>/dev/null | sort -u |
+ grep -h -v -x -F -f $conffiles > "$keepfiles"
+
+ # backup conffiles, but only those changed if '-u'
+ [ $SKIP_UNCHANGED = 1 ] &&
+ list_changed_conffiles | sort -u > "$conffiles"
+
+ # do not backup files from packages, except those listed
+ # in conffiles and keep.d
+ {
+ find /usr/lib/opkg/info -type f -name "*.list" -exec cat {} \;
+ find /usr/lib/opkg/info -type f -name "*.control" -exec sed \
+ -ne '/^Alternatives/{s/^Alternatives: //;s/, /\n/g;p}' {} \; |
+ cut -f2 -d:
+ } | grep -v -x -F -f $conffiles |
+ grep -v -x -F -f $keepfiles | sort -u > "$packagesfiles"
+ rm -f "$keepfiles" "$conffiles"
+ fi
+
+ # busybox grep bug when file is empty
+ [ -s "$packagesfiles" ] || echo > $packagesfiles
+
+ ( cd /overlay/upper/; find .$SAVE_OVERLAY_PATH \( -type f -o -type l \) $find_filter | sed \
-e 's,^\.,,' \
-e '\,^/etc/board.json$,d' \
-e '\,/[^/]*-opkg$,d' \
-e '\,^/etc/urandom.seed$,d' \
- )> "$file"
+ -e '\,^/usr/lib/opkg/.*,d' \
+ ) | grep -v -x -F -f $packagesfiles > "$file"
+
+ rm -f "$packagesfiles"
+
return 0
}