base-files: sysupgrade: handle errors when generating backup
1. Return error if any step of generating tar file fails
2. Use pipefail to avoid calling "gzip" if tar failed
Fixes: e36cc53092
("base-files: sysupgrade: use tar helper to include installed_packages.txt")
Reported-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
parent
93610492b6
commit
4efbfcd996
1 changed files with 30 additions and 17 deletions
|
@ -237,6 +237,7 @@ include /lib/upgrade
|
||||||
create_backup_archive() {
|
create_backup_archive() {
|
||||||
local conf_tar="$1"
|
local conf_tar="$1"
|
||||||
local disabled
|
local disabled
|
||||||
|
local err
|
||||||
|
|
||||||
[ "$(rootfs_type)" = "tmpfs" ] && {
|
[ "$(rootfs_type)" = "tmpfs" ] && {
|
||||||
echo "Cannot save config while running from ramdisk." >&2
|
echo "Cannot save config while running from ramdisk." >&2
|
||||||
|
@ -251,16 +252,22 @@ create_backup_archive() {
|
||||||
v "Saving config files..."
|
v "Saving config files..."
|
||||||
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
|
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
|
||||||
sed -i -e 's,^/,,' "$CONFFILES"
|
sed -i -e 's,^/,,' "$CONFFILES"
|
||||||
|
set -o pipefail
|
||||||
{
|
{
|
||||||
|
local ret=0
|
||||||
|
|
||||||
|
if [ $ret -eq 0 ]; then
|
||||||
for service in /etc/init.d/*; do
|
for service in /etc/init.d/*; do
|
||||||
if ! $service enabled; then
|
if ! $service enabled; then
|
||||||
disabled="$disabled$service disable\n"
|
disabled="$disabled$service disable\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
disabled="$disabled\nexit 0"
|
disabled="$disabled\nexit 0"
|
||||||
tar_print_member "/etc/uci-defaults/10_disable_services" "$(echo -e $disabled)"
|
tar_print_member "/etc/uci-defaults/10_disable_services" "$(echo -e $disabled)" || ret=1
|
||||||
|
fi
|
||||||
|
|
||||||
# Part of archive with installed packages info
|
# Part of archive with installed packages info
|
||||||
|
if [ $ret -eq 0 ]; then
|
||||||
if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
|
if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
|
||||||
# Format: pkg-name<TAB>{rom,overlay,unknown}
|
# Format: pkg-name<TAB>{rom,overlay,unknown}
|
||||||
# rom is used for pkgs in /rom, even if updated later
|
# rom is used for pkgs in /rom, even if updated later
|
||||||
|
@ -268,14 +275,20 @@ create_backup_archive() {
|
||||||
\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
|
\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
|
||||||
\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
|
\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
|
||||||
\( -exec echo {} unknown \; \) \
|
\( -exec echo {} unknown \; \) \
|
||||||
\) | sed -e 's,.*/,,;s/\.control /\t/')"
|
\) | sed -e 's,.*/,,;s/\.control /\t/')" || ret=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Rest of archive with config files and ending padding
|
# Rest of archive with config files and ending padding
|
||||||
tar c${TAR_V} -C / -T "$CONFFILES"
|
if [ $ret -eq 0 ]; then
|
||||||
} | gzip > "${conf_tar:-/proc/self/fd/1}"
|
tar c${TAR_V} -C / -T "$CONFFILES" || ret=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ $ret -eq 0 ]
|
||||||
|
} | gzip > "${conf_tar:-/proc/self/fd/1}"
|
||||||
|
err=$?
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
local err=$?
|
|
||||||
if [ "$err" -ne 0 ]; then
|
if [ "$err" -ne 0 ]; then
|
||||||
echo "Failed to create the configuration backup."
|
echo "Failed to create the configuration backup."
|
||||||
[ -f "$conf_tar" ] && rm -f "$conf_tar"
|
[ -f "$conf_tar" ] && rm -f "$conf_tar"
|
||||||
|
|
Loading…
Reference in a new issue