base-files: add sysupgrade -k to save list of pkgs
When '-k' is used, sysupgrade inserts into backup a new file /etc/backup/installed_packages.txt which contains pkgname and origin (rom, overlay, unknown) without touching rootfs. It's mainly used to reinstall all extra packages: # opkg update # grep "\toverlay" /etc/backup/installed_packages.txt | cut -f1 | xargs -r opkg install # rm /etc/backup/installed_packages.txt Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
This commit is contained in:
parent
96392e5da4
commit
5cb1dce542
|
@ -11,6 +11,7 @@ export SAVE_CONFIG=1
|
||||||
export SAVE_OVERLAY=0
|
export SAVE_OVERLAY=0
|
||||||
export SAVE_OVERLAY_PATH=
|
export SAVE_OVERLAY_PATH=
|
||||||
export SAVE_PARTITIONS=1
|
export SAVE_PARTITIONS=1
|
||||||
|
export SAVE_INSTALLED_PKGS=0
|
||||||
export SKIP_UNCHANGED=0
|
export SKIP_UNCHANGED=0
|
||||||
export CONF_IMAGE=
|
export CONF_IMAGE=
|
||||||
export CONF_BACKUP_LIST=0
|
export CONF_BACKUP_LIST=0
|
||||||
|
@ -20,6 +21,7 @@ export NEED_IMAGE=
|
||||||
export HELP=0
|
export HELP=0
|
||||||
export FORCE=0
|
export FORCE=0
|
||||||
export TEST=0
|
export TEST=0
|
||||||
|
export UMOUNT_ETCBACKUP_DIR=0
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while [ -n "$1" ]; do
|
while [ -n "$1" ]; do
|
||||||
|
@ -31,6 +33,7 @@ while [ -n "$1" ]; do
|
||||||
-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
|
-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
|
||||||
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
|
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
|
||||||
-p) export SAVE_PARTITIONS=0;;
|
-p) export SAVE_PARTITIONS=0;;
|
||||||
|
-k) export SAVE_INSTALLED_PKGS=1;;
|
||||||
-u) export SKIP_UNCHANGED=1;;
|
-u) export SKIP_UNCHANGED=1;;
|
||||||
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
|
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
|
||||||
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
|
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
|
||||||
|
@ -50,13 +53,15 @@ done
|
||||||
|
|
||||||
export CONFFILES=/tmp/sysupgrade.conffiles
|
export CONFFILES=/tmp/sysupgrade.conffiles
|
||||||
export CONF_TAR=/tmp/sysupgrade.tgz
|
export CONF_TAR=/tmp/sysupgrade.tgz
|
||||||
|
export ETCBACKUP_DIR=/etc/backup
|
||||||
|
export INSTALLED_PACKAGES=${ETCBACKUP_DIR}/installed_packages.txt
|
||||||
|
|
||||||
IMAGE="$1"
|
IMAGE="$1"
|
||||||
|
|
||||||
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && {
|
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: $0 [<upgrade-option>...] <image file or URL>
|
Usage: $0 [<upgrade-option>...] <image file or URL>
|
||||||
$0 [-q] [-i] [-c] [-u] [-o] <backup-command> <file>
|
$0 [-q] [-i] [-c] [-u] [-o] [-k] <backup-command> <file>
|
||||||
|
|
||||||
upgrade-option:
|
upgrade-option:
|
||||||
-f <config> restore configuration from .tar.gz (file or url)
|
-f <config> restore configuration from .tar.gz (file or url)
|
||||||
|
@ -67,6 +72,8 @@ upgrade-option:
|
||||||
-u skip from backup files that are equal to those in /rom
|
-u skip from backup files that are equal to those in /rom
|
||||||
-n do not save configuration over reflash
|
-n do not save configuration over reflash
|
||||||
-p do not attempt to restore the partition table after flash.
|
-p do not attempt to restore the partition table after flash.
|
||||||
|
-k include in backup a list of current installed packages at
|
||||||
|
$INSTALLED_PACKAGES
|
||||||
-T | --test
|
-T | --test
|
||||||
Verify image and config .tar.gz but do not actually flash.
|
Verify image and config .tar.gz but do not actually flash.
|
||||||
-F | --force
|
-F | --force
|
||||||
|
@ -174,6 +181,7 @@ add_overlayfiles() {
|
||||||
-e '\,^/etc/board.json$,d' \
|
-e '\,^/etc/board.json$,d' \
|
||||||
-e '\,/[^/]*-opkg$,d' \
|
-e '\,/[^/]*-opkg$,d' \
|
||||||
-e '\,^/etc/urandom.seed$,d' \
|
-e '\,^/etc/urandom.seed$,d' \
|
||||||
|
-e "\,^$INSTALLED_PACKAGES$,d" \
|
||||||
-e '\,^/usr/lib/opkg/.*,d' \
|
-e '\,^/usr/lib/opkg/.*,d' \
|
||||||
) | grep -v -x -F -f $packagesfiles > "$file"
|
) | grep -v -x -F -f $packagesfiles > "$file"
|
||||||
|
|
||||||
|
@ -218,6 +226,27 @@ do_save_conffiles() {
|
||||||
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
||||||
ask_bool 0 "Edit config file list" && vi "$CONFFILES"
|
ask_bool 0 "Edit config file list" && vi "$CONFFILES"
|
||||||
|
|
||||||
|
if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
|
||||||
|
echo "${INSTALLED_PACKAGES}" >> "$CONFFILES"
|
||||||
|
mkdir -p "$ETCBACKUP_DIR"
|
||||||
|
# Avoid touching filesystem on each backup
|
||||||
|
RAMFS="$(mktemp -d -t sysupgrade.XXXXXX)"
|
||||||
|
mkdir -p "$RAMFS/upper" "$RAMFS/work"
|
||||||
|
mount -t overlay overlay -o lowerdir=$ETCBACKUP_DIR,upperdir=$RAMFS/upper,workdir=$RAMFS/work $ETCBACKUP_DIR &&
|
||||||
|
UMOUNT_ETCBACKUP_DIR=1 || {
|
||||||
|
echo "Cannot mount '$ETCBACKUP_DIR' as tmpfs to avoid touching disk while saving the list of installed packages." >&2
|
||||||
|
ask_bool 0 "Abort" && exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Format: pkg-name<TAB>{rom,overlay,unkown}
|
||||||
|
# rom is used for pkgs in /rom, even if updated later
|
||||||
|
find /usr/lib/opkg/info -name "*.control" \( \
|
||||||
|
\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
|
||||||
|
\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
|
||||||
|
\( -exec echo {} unknown \; \) \
|
||||||
|
\) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES}
|
||||||
|
fi
|
||||||
|
|
||||||
v "Saving config files..."
|
v "Saving config files..."
|
||||||
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
|
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
|
||||||
tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
|
tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
|
||||||
|
@ -227,11 +256,16 @@ do_save_conffiles() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ "$UMOUNT_ETCBACKUP_DIR" -eq 1 ] && {
|
||||||
|
umount "$ETCBACKUP_DIR"
|
||||||
|
rm -rf "$RAMFS"
|
||||||
|
}
|
||||||
rm -f "$CONFFILES"
|
rm -f "$CONFFILES"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $CONF_BACKUP_LIST -eq 1 ]; then
|
if [ $CONF_BACKUP_LIST -eq 1 ]; then
|
||||||
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
||||||
|
[ "$SAVE_INSTALLED_PKGS" -eq 1 ] && echo ${INSTALLED_PACKAGES} >> "$CONFFILES"
|
||||||
cat "$CONFFILES"
|
cat "$CONFFILES"
|
||||||
rm -f "$CONFFILES"
|
rm -f "$CONFFILES"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue