base-files: automatically handle paths and symlinks for RAMFS_COPY_BIN
authorMatthias Schiffer <mschiffer@universe-factory.net>
Mon, 10 Jul 2017 16:37:25 +0000 (18:37 +0200)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Tue, 11 Jul 2017 15:26:32 +0000 (17:26 +0200)
Depending on busybox applet selection, paths of basic utiilties may differ,
and may not work as symlinks to busybox. Simply using whatever binary is
found in PATH and detecting symlinks automatically is more robust and
easier to maintain.

The list of binaries is also slightly cleaned up and duplicates are
removed.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
package/base-files/files/lib/upgrade/common.sh
package/base-files/files/lib/upgrade/stage2
package/base-files/files/sbin/sysupgrade
target/linux/ar71xx/base-files/lib/upgrade/platform.sh
target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
target/linux/ipq806x/base-files/lib/upgrade/platform.sh
target/linux/kirkwood/base-files/lib/upgrade/platform.sh
target/linux/mvebu/base-files/lib/upgrade/platform.sh
target/linux/pistachio/base-files/lib/upgrade/platform.sh
target/linux/rb532/base-files/lib/upgrade/platform.sh

index c8b71015c2e44210696a4e28a5b7babbd0233184..428ec735d62e8a2fd7cad973dacc20c0a81b5826 100644 (file)
@@ -6,28 +6,33 @@ RAM_ROOT=/tmp/root
 libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; }
 
 install_file() { # <file> [ <file> ... ]
+       local target dest dir
        for file in "$@"; do
+               if [ -L "$file" ]; then
+                       target="$(readlink -f "$file")"
+                       dest="$RAM_ROOT/$file"
+                       [ ! -f "$dest" ] && {
+                               dir="$(dirname "$dest")"
+                               mkdir -p "$dir"
+                               ln -s "$target" "$dest"
+                       }
+                       file="$target"
+               fi
                dest="$RAM_ROOT/$file"
-               [ -f $file -a ! -f $dest ] && {
-                       dir="$(dirname $dest)"
+               [ -f "$file" -a ! -f "$dest" ] && {
+                       dir="$(dirname "$dest")"
                        mkdir -p "$dir"
-                       cp $file $dest
+                       cp "$file" "$dest"
                }
        done
 }
 
-install_bin() { # <file> [ <symlink> ... ]
+install_bin() {
+       local src files
        src=$1
        files=$1
        [ -x "$src" ] && files="$src $(libs $src)"
        install_file $files
-       shift
-       for link in "$@"; do {
-               dest="$RAM_ROOT/$link"
-               dir="$(dirname $dest)"
-               mkdir -p "$dir"
-               [ -f "$dest" ] || ln -s $src $dest
-       }; done
 }
 
 run_hooks() {
index 9d12cc801cf97b8adb2a28b0dc43a198ede2f315..5a439f1201b1dc452493a7ce6129d41aa206b072 100755 (executable)
@@ -17,6 +17,9 @@ export VERBOSE=1
 export CONFFILES=/tmp/sysupgrade.conffiles
 export CONF_TAR=/tmp/sysupgrade.tgz
 
+RAMFS_COPY_BIN=                # extra programs for temporary ramfs root
+RAMFS_COPY_DATA=       # extra data files
+
 
 [ -f "$CONF_TAR" ] || export SAVE_CONFIG=0
 [ -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap ] && export SAVE_PARTITIONS=0
@@ -41,32 +44,20 @@ supivot() { # <new_root> <old_root>
 }
 
 switch_to_ramfs() {
-       install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount        \
-               /sbin/pivot_root /sbin/reboot /bin/sync /bin/dd /bin/grep       \
-               /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" /bin/dd   \
-               /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump          \
-               /bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc \
-               /bin/cut /usr/bin/printf /bin/sync /bin/mkdir /bin/rmdir        \
-               /bin/rm /usr/bin/basename /bin/kill /bin/chmod /usr/bin/find \
-               /bin/mknod /bin/touch /bin/sed
-
-       install_bin /sbin/mtd
-       install_bin /sbin/mount_root
-       install_bin /sbin/snapshot
-       install_bin /sbin/snapshot_tool
-       install_bin /usr/sbin/ubiupdatevol
-       install_bin /usr/sbin/ubiattach
-       install_bin /usr/sbin/ubiblock
-       install_bin /usr/sbin/ubiformat
-       install_bin /usr/sbin/ubidetach
-       install_bin /usr/sbin/ubirsvol
-       install_bin /usr/sbin/ubirmvol
-       install_bin /usr/sbin/ubimkvol
-       install_bin /usr/sbin/partx
-       install_bin /usr/sbin/losetup
-       install_bin /usr/sbin/mkfs.ext4
-       for file in $RAMFS_COPY_BIN; do
-               install_bin ${file//:/ }
+       for binary in \
+               /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount    \
+               pivot_root mount_root reboot sync kill sleep            \
+               md5sum hexdump cat zcat bzcat dd tar                    \
+               ls basename find cp mv rm mkdir rmdir mknod touch chmod \
+               '[' printf wc grep awk sed cut                          \
+               mtd partx losetup mkfs.ext4                             \
+               ubiupdatevol ubiattach ubiblock ubiformat               \
+               ubidetach ubirsvol ubirmvol ubimkvol                    \
+               snapshot snapshot_tool                                  \
+               $RAMFS_COPY_BIN
+       do
+               local file="$(which "$binary" 2>/dev/null)"
+               [ -n "$file" ] && install_bin "$file"
        done
        install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
 
index 809e789f9f436aaeb47a906d46c94d5952583e5a..359f21f51c3d5491f8bfcc9bf96819d2e91c11cc 100755 (executable)
@@ -4,8 +4,6 @@
 . /lib/functions/system.sh
 
 # initialize defaults
-RAMFS_COPY_BIN=""      # extra programs for temporary ramfs root
-RAMFS_COPY_DATA=""     # extra data files
 export MTD_CONFIG_ARGS=""
 export INTERACTIVE=0
 export VERBOSE=1
index cf51fe2d80593479c39a26de3642bf5d15b48b36..ba65a790060c5d0db40860befce74ae4b05432e0 100755 (executable)
@@ -7,7 +7,7 @@
 
 PART_NAME=firmware
 RAMFS_COPY_DATA=/lib/ar71xx.sh
-[ -x /usr/sbin/nandwrite ] && RAMFS_COPY_BIN=/usr/sbin/nandwrite
+RAMFS_COPY_BIN='nandwrite'
 
 CI_BLKSZ=65536
 CI_LDADR=0x80060000
index 6a9e4950450cb896db7ebb3eb901b5cf51030295..1f778c72b6892b9accace01be00e11dcd11bf907 100644 (file)
@@ -1,4 +1,4 @@
-RAMFS_COPY_BIN='/usr/bin/osafeloader /usr/bin/oseama'
+RAMFS_COPY_BIN='osafeloader oseama'
 
 PART_NAME=firmware
 
index 141058f7bae2775397c9fdf8224f8f9d035795fb..246361bbf6018b60563439dda142aec08f1e8048 100644 (file)
@@ -3,7 +3,7 @@
 PART_NAME=firmware
 REQUIRE_IMAGE_METADATA=1
 
-RAMFS_COPY_BIN='/usr/sbin/fw_printenv /usr/sbin/fw_setenv'
+RAMFS_COPY_BIN='fw_printenv fw_setenv'
 RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
 
 platform_check_image() {
index c8c66c1b9d67759305ee836f9d84b9a2968a9493..f75acb0d61e197ea9f4ad38334e37d3ead35b9ff 100644 (file)
@@ -1,6 +1,6 @@
 . /lib/kirkwood.sh
 
-RAMFS_COPY_BIN='/usr/sbin/fw_printenv /usr/sbin/fw_setenv'
+RAMFS_COPY_BIN='fw_printenv fw_setenv'
 RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
 
 platform_check_image() {
index 8085634dca647b3aa7ba47768a8f6bb8087cbc36..dd21c0958e3664504662b664c376225da71cd074 100755 (executable)
@@ -5,7 +5,7 @@
 
 . /lib/mvebu.sh
 
-RAMFS_COPY_BIN='/usr/sbin/fw_printenv /usr/sbin/fw_setenv'
+RAMFS_COPY_BIN='fw_printenv fw_setenv'
 RAMFS_COPY_DATA='/lib/mvebu.sh /etc/fw_env.config /var/lock/fw_printenv.lock'
 REQUIRE_IMAGE_METADATA=1
 
index ee5d5066c3417ecaedba96a7e40c39c052e104f5..4edc06bf9f874d4526f24110d39ad505d6e75b8c 100755 (executable)
@@ -6,7 +6,7 @@
 # See /LICENSE for more information.
 #
 
-RAMFS_COPY_BIN="/usr/sbin/fw_printenv /usr/sbin/fw_setenv /bin/mkdir /bin/dmesg /bin/sed /bin/grep"
+RAMFS_COPY_BIN='fw_printenv fw_setenv dmesg'
 RAMFS_COPY_DATA="/etc/fw_env.config"
 REQUIRE_IMAGE_METADATA=0
 
index 29fe18de30411c9c75e1faf8c7542a8ef2548be4..bfa73a7a246da01f99cedd6eee92cebd354f2e7f 100644 (file)
@@ -1,5 +1,5 @@
 REQUIRE_IMAGE_METADATA=1
-RAMFS_COPY_BIN=/usr/sbin/nandwrite
+RAMFS_COPY_BIN='nandwrite'
 CI_KERNPART=none
 
 platform_check_image() {