diff options
author | Luiz Angelo Daros de Luca <luizluca@gmail.com> | 2018-08-17 20:49:52 -0300 |
---|---|---|
committer | Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk> | 2018-12-09 18:04:11 +0000 |
commit | 96392e5da4251454ae5b921754cc35fab1bfce85 (patch) | |
tree | 5a7b1fc8e5b0e443d96bc429a051a8ab338c4a1b /package/base-files | |
parent | 20b23270b712ba0c22e204b1347f04b2206d7018 (diff) | |
download | upstream-96392e5da4251454ae5b921754cc35fab1bfce85.tar.gz upstream-96392e5da4251454ae5b921754cc35fab1bfce85.tar.bz2 upstream-96392e5da4251454ae5b921754cc35fab1bfce85.zip |
base-files: add sysupgrade -o to save all overlay files
Add sysupgrade '-o' option in order to include all overlay files in
backup, except for those that are from packages but including files
listed in conffiles, sysupgrade.conf or /lib/upgrade/keep.d.
With '-u' option, it will skip files equals to /rom and conffiles that
were not changed.
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Diffstat (limited to 'package/base-files')
-rwxr-xr-x | package/base-files/files/sbin/sysupgrade | 52 |
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 } |