[OpenWrt-Devel] [PATCH 1/2] treewide: don't hardcode "sysupgrade.tgz" file name
Rafał Miłecki
zajec5 at gmail.com
Wed Sep 4 10:57:39 EDT 2019
From: Rafał Miłecki <rafal at milecki.pl>
1) Add BACKUP_FILE and use it when copying an archive to be restored
after sysupgrade (on the next preinit).
2) Use CONF_TAR for copying backup prepared by the /sbin/sysupgrade
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
package/base-files/files/lib/upgrade/common.sh | 2 ++
package/base-files/files/lib/upgrade/nand.sh | 2 +-
.../apm821xx/base-files/lib/preinit/79_move_config | 3 ++-
.../brcm2708/base-files/lib/preinit/79_move_config | 4 +++-
.../linux/imx6/base-files/lib/preinit/79_move_config | 3 ++-
target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh | 2 +-
.../mediatek/base-files/lib/preinit/79_move_config | 4 +++-
.../linux/mvebu/base-files/lib/preinit/79_move_config | 2 +-
.../mvebu/base-files/lib/preinit/81_linksys_syscfg | 10 +++++-----
target/linux/mvebu/base-files/lib/preinit/82_uDPU | 8 ++++----
target/linux/mvebu/base-files/lib/upgrade/linksys.sh | 2 +-
target/linux/mvebu/base-files/lib/upgrade/uDPU.sh | 4 ++--
.../linux/octeon/base-files/lib/preinit/79_move_config | 3 ++-
.../linux/omap/base-files/lib/preinit/79_move_config | 4 ++--
.../linux/sunxi/base-files/lib/preinit/79_move_config | 4 ++--
.../linux/tegra/base-files/lib/preinit/79_move_config | 4 ++--
target/linux/x86/base-files/lib/preinit/79_move_config | 4 ++--
17 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index efa301cd95..279470fcd8 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -2,6 +2,8 @@
RAM_ROOT=/tmp/root
+export BACKUP_FILE=sysupgrade.tgz # file extracted by preinit
+
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; }
diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
index fbc2b5c19a..e7d7bf8d13 100644
--- a/package/base-files/files/lib/upgrade/nand.sh
+++ b/package/base-files/files/lib/upgrade/nand.sh
@@ -109,7 +109,7 @@ nand_restore_config() {
rmdir /tmp/new_root
return 1
fi
- mv "$1" "/tmp/new_root/sysupgrade.tgz"
+ mv "$1" "/tmp/new_root/$BACKUP_FILE"
umount /tmp/new_root
sync
rmdir /tmp/new_root
diff --git a/target/linux/apm821xx/base-files/lib/preinit/79_move_config b/target/linux/apm821xx/base-files/lib/preinit/79_move_config
index cb5e5c759d..37d35b663b 100644
--- a/target/linux/apm821xx/base-files/lib/preinit/79_move_config
+++ b/target/linux/apm821xx/base-files/lib/preinit/79_move_config
@@ -4,13 +4,14 @@ BOOTPART=/dev/sda1
move_config() {
. /lib/functions.sh
+ . /lib/upgrade/common.sh
case "$(board_name)" in
wd,mybooklive)
if [ -b $BOOTPART ]; then
mkdir -p /boot
mount -t ext4 -o rw,noatime $BOOTPART /boot
- [ -f /boot/sysupgrade.tgz ] && mv -f /boot/sysupgrade.tgz /
+ [ -f "/boot/$BACKUP_FILE" ] && mv -f "/boot/$BACKUP_FILE" /
fi
;;
*)
diff --git a/target/linux/brcm2708/base-files/lib/preinit/79_move_config b/target/linux/brcm2708/base-files/lib/preinit/79_move_config
index b0ee62a809..b8738b645e 100644
--- a/target/linux/brcm2708/base-files/lib/preinit/79_move_config
+++ b/target/linux/brcm2708/base-files/lib/preinit/79_move_config
@@ -1,6 +1,8 @@
#!/bin/sh
# Copyright (C) 2015 OpenWrt.org
+. /lib/upgrade/common.sh
+
BOOTPART=/dev/mmcblk0p1
move_config() {
@@ -11,7 +13,7 @@ move_config() {
insmod vfat
mkdir -p /boot
mount -t vfat -o rw,noatime $BOOTPART /boot
- [ -f /boot/sysupgrade.tgz ] && mv -f /boot/sysupgrade.tgz /
+ [ -f "/boot/$BACKUP_FILE" ] && mv -f "/boot/$BACKUP_FILE" /
fi
}
diff --git a/target/linux/imx6/base-files/lib/preinit/79_move_config b/target/linux/imx6/base-files/lib/preinit/79_move_config
index 6b66fbd42d..bdf397c4fc 100644
--- a/target/linux/imx6/base-files/lib/preinit/79_move_config
+++ b/target/linux/imx6/base-files/lib/preinit/79_move_config
@@ -2,6 +2,7 @@
. /lib/imx6.sh
. /lib/functions.sh
+. /lib/upgrade/common.sh
move_config() {
local board=$(board_name)
@@ -10,7 +11,7 @@ move_config() {
apalis*)
if [ -b $(bootpart_from_uuid) ]; then
apalis_mount_boot
- [ -f /boot/sysupgrade.tgz ] && mv -f /boot/sysupgrade.tgz /
+ [ -f "/boot/$BACKUP_FILE" ] && mv -f "/boot/$BACKUP_FILE" /
umount /boot
fi
;;
diff --git a/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh b/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
index 33cd98339c..8888ec7d04 100644
--- a/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
+++ b/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
@@ -60,7 +60,7 @@ zyxel_do_flash() {
mkdir /tmp/new_root
mount -t ext4 $loopdev /tmp/new_root && {
echo "Saving config to rootfs_data at position ${offset}."
- cp -v /tmp/sysupgrade.tgz /tmp/new_root/
+ cp -v "$CONF_TAR" /tmp/new_root/
umount /tmp/new_root
}
diff --git a/target/linux/mediatek/base-files/lib/preinit/79_move_config b/target/linux/mediatek/base-files/lib/preinit/79_move_config
index e8e62883dc..617336583e 100644
--- a/target/linux/mediatek/base-files/lib/preinit/79_move_config
+++ b/target/linux/mediatek/base-files/lib/preinit/79_move_config
@@ -1,6 +1,8 @@
#!/bin/sh
# Copyright (C) 2015 OpenWrt.org
+. /lib/upgrade/common.sh
+
RECOVERY_PART=/dev/mmcblk0p1
move_config() {
@@ -11,7 +13,7 @@ move_config() {
insmod vfat
mkdir -p /recovery
mount -o rw,noatime $RECOVERY_PART /recovery
- [ -f /recovery/sysupgrade.tgz ] && mv -f /recovery/sysupgrade.tgz /
+ [ -f "/recovery/$BACKUP_FILE" ] && mv -f "/recovery/$BACKUP_FILE" /
umount /recovery
fi
}
diff --git a/target/linux/mvebu/base-files/lib/preinit/79_move_config b/target/linux/mvebu/base-files/lib/preinit/79_move_config
index 640fb5cdad..195be0e137 100644
--- a/target/linux/mvebu/base-files/lib/preinit/79_move_config
+++ b/target/linux/mvebu/base-files/lib/preinit/79_move_config
@@ -18,7 +18,7 @@ move_config() {
esac
mkdir -p /boot
mount -o rw,noatime "/dev/$partdev" /boot
- [ -f /boot/sysupgrade.tgz ] && mv -f /boot/sysupgrade.tgz /
+ [ -f "/boot/$BACKUP_FILE" ] && mv -f "/boot/$BACKUP_FILE" /
umount /boot
fi
}
diff --git a/target/linux/mvebu/base-files/lib/preinit/81_linksys_syscfg b/target/linux/mvebu/base-files/lib/preinit/81_linksys_syscfg
index b107eacb11..83448e5ace 100644
--- a/target/linux/mvebu/base-files/lib/preinit/81_linksys_syscfg
+++ b/target/linux/mvebu/base-files/lib/preinit/81_linksys_syscfg
@@ -4,8 +4,8 @@
#
preinit_mount_syscfg() {
-
. /lib/functions.sh
+ . /lib/upgrade/common.sh
case $(board_name) in
linksys,caiman|linksys,cobra|linksys,mamba|linksys,rango|linksys,shelby|linksys,venom)
@@ -22,12 +22,12 @@ preinit_mount_syscfg() {
fi
mkdir /tmp/syscfg
mount -t ubifs ubi1:syscfg /tmp/syscfg
- [ -f /tmp/syscfg/sysupgrade.tgz ] && {
+ [ -f "/tmp/syscfg/$BACKUP_FILE" ] && {
echo "- config restore -"
cd /
- mv /tmp/syscfg/sysupgrade.tgz /tmp
- tar xzf /tmp/sysupgrade.tgz
- rm -f /tmp/sysupgrade.tgz
+ mv "/tmp/syscfg/$BACKUP_FILE" /tmp
+ tar xzf "/tmp/$BACKUP_FILE"
+ rm -f "/tmp/$BACKUP_FILE"
sync
}
;;
diff --git a/target/linux/mvebu/base-files/lib/preinit/82_uDPU b/target/linux/mvebu/base-files/lib/preinit/82_uDPU
index 937a0a5f21..12bbfc3725 100644
--- a/target/linux/mvebu/base-files/lib/preinit/82_uDPU
+++ b/target/linux/mvebu/base-files/lib/preinit/82_uDPU
@@ -4,8 +4,8 @@
#
preinit_mount_udpu() {
-
. /lib/functions.sh
+ . /lib/upgrade/common.sh
case $(board_name) in
methode,udpu)
@@ -15,10 +15,10 @@ preinit_mount_udpu() {
if [ -b "${mmcdev}p4" ]; then
mkdir /misc
mount -t f2fs ${mmcdev}p4 /misc
- [ -f "/misc/sysupgrade.tgz" ] && {
+ [ -f "/misc/$BACKUP_FILE" ] && {
echo "- Restoring configuration files -"
- tar xzf /misc/sysupgrade.tgz -C /
- rm -f /misc/sysupgrade.tgz
+ tar xzf "/misc/$BACKUP_FILE" -C /
+ rm -f "/misc/$BACKUP_FILE"
sync
}
[ -f "/misc/firmware/recovery.itb" ] && {
diff --git a/target/linux/mvebu/base-files/lib/upgrade/linksys.sh b/target/linux/mvebu/base-files/lib/upgrade/linksys.sh
index 3f45d6cac5..857c550c73 100644
--- a/target/linux/mvebu/base-files/lib/upgrade/linksys.sh
+++ b/target/linux/mvebu/base-files/lib/upgrade/linksys.sh
@@ -93,6 +93,6 @@ platform_do_upgrade_linksys() {
}
platform_copy_config_linksys() {
- cp -f /tmp/sysupgrade.tgz /tmp/syscfg/sysupgrade.tgz
+ cp -f "$CONF_TAR" /tmp/syscfg/
sync
}
diff --git a/target/linux/mvebu/base-files/lib/upgrade/uDPU.sh b/target/linux/mvebu/base-files/lib/upgrade/uDPU.sh
index 48c3209a99..f87ff4f9ca 100644
--- a/target/linux/mvebu/base-files/lib/upgrade/uDPU.sh
+++ b/target/linux/mvebu/base-files/lib/upgrade/uDPU.sh
@@ -149,8 +149,8 @@ platform_do_upgrade_uDPU() {
platform_copy_config_uDPU() {
# Config is saved on the /misc partition and copied on the rootfs after the reboot
- if [ -f "/tmp/sysupgrade.tgz" ]; then
- cp -f /tmp/sysupgrade.tgz /misc
+ if [ -f "$CONF_TAR" ]; then
+ cp -f "$CONF_TAR" /misc
sync
fi
}
diff --git a/target/linux/octeon/base-files/lib/preinit/79_move_config b/target/linux/octeon/base-files/lib/preinit/79_move_config
index ec63d9f5ff..a4130e26d8 100644
--- a/target/linux/octeon/base-files/lib/preinit/79_move_config
+++ b/target/linux/octeon/base-files/lib/preinit/79_move_config
@@ -3,11 +3,12 @@
move_config() {
. /lib/functions.sh
+ . /lib/upgrade/common.sh
case "$(board_name)" in
erlite)
mount -t vfat /dev/sda1 /mnt
- [ -f /mnt/sysupgrade.tgz ] && mv -f /mnt/sysupgrade.tgz /
+ [ -f "/mnt/$BACKUP_FILE" ] && mv -f "/mnt/$BACKUP_FILE" /
umount /mnt
;;
esac
diff --git a/target/linux/omap/base-files/lib/preinit/79_move_config b/target/linux/omap/base-files/lib/preinit/79_move_config
index 83171b3ba9..74caee8a8a 100644
--- a/target/linux/omap/base-files/lib/preinit/79_move_config
+++ b/target/linux/omap/base-files/lib/preinit/79_move_config
@@ -8,8 +8,8 @@ move_config() {
if export_bootdevice && export_partdevice partdev 1; then
if mount -t vfat -o rw,noatime "/dev/$partdev" /mnt; then
- if [ -f /mnt/sysupgrade.tgz ]; then
- mv -f /mnt/sysupgrade.tgz /
+ if [ -f "/mnt/$BACKUP_FILE" ]; then
+ mv -f "/mnt/$BACKUP_FILE" /
fi
umount /mnt
fi
diff --git a/target/linux/sunxi/base-files/lib/preinit/79_move_config b/target/linux/sunxi/base-files/lib/preinit/79_move_config
index 83171b3ba9..74caee8a8a 100644
--- a/target/linux/sunxi/base-files/lib/preinit/79_move_config
+++ b/target/linux/sunxi/base-files/lib/preinit/79_move_config
@@ -8,8 +8,8 @@ move_config() {
if export_bootdevice && export_partdevice partdev 1; then
if mount -t vfat -o rw,noatime "/dev/$partdev" /mnt; then
- if [ -f /mnt/sysupgrade.tgz ]; then
- mv -f /mnt/sysupgrade.tgz /
+ if [ -f "/mnt/$BACKUP_FILE" ]; then
+ mv -f "/mnt/$BACKUP_FILE" /
fi
umount /mnt
fi
diff --git a/target/linux/tegra/base-files/lib/preinit/79_move_config b/target/linux/tegra/base-files/lib/preinit/79_move_config
index 2a451a5efd..d17e734ac8 100644
--- a/target/linux/tegra/base-files/lib/preinit/79_move_config
+++ b/target/linux/tegra/base-files/lib/preinit/79_move_config
@@ -8,9 +8,9 @@ move_config() {
if export_bootdevice && export_partdevice partdev 1; then
mkdir -p /boot
if mount -o ro,noatime "/dev/$partdev" /boot; then
- if [ -f /boot/sysupgrade.tgz ]; then
+ if [ -f "/boot/$BACKUP_FILE" ]; then
mount /boot -o remount,rw,noatime
- mv -f /boot/sysupgrade.tgz /
+ mv -f "/boot/$BACKUP_FILE" /
fi
umount /boot
rm -fR /boot
diff --git a/target/linux/x86/base-files/lib/preinit/79_move_config b/target/linux/x86/base-files/lib/preinit/79_move_config
index aff720a52c..702da9e873 100644
--- a/target/linux/x86/base-files/lib/preinit/79_move_config
+++ b/target/linux/x86/base-files/lib/preinit/79_move_config
@@ -9,8 +9,8 @@ move_config() {
if export_bootdevice && export_partdevice partdev 1; then
mkdir -p /boot
mount -t ext4 -o rw,noatime "/dev/$partdev" /boot
- if [ -f /boot/sysupgrade.tgz ]; then
- mv -f /boot/sysupgrade.tgz /
+ if [ -f "/boot/$BACKUP_FILE" ]; then
+ mv -f "/boot/$BACKUP_FILE" /
fi
mount --bind /boot/boot /boot
fi
--
2.21.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list