summaryrefslogtreecommitdiff
path: root/package/base-files
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2017-07-10 18:37:25 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2017-07-11 17:26:32 +0200
commit438dcbfe74a6da1a8949d8fb785092d934499b60 (patch)
tree0f455ad4fd7d82cbe7c037afd27d9e9ca9537d12 /package/base-files
parentf464da623db1a53231e5f7d54a51e355c0d32dff (diff)
downloadmtk-20170518-438dcbfe74a6da1a8949d8fb785092d934499b60.zip
mtk-20170518-438dcbfe74a6da1a8949d8fb785092d934499b60.tar.gz
mtk-20170518-438dcbfe74a6da1a8949d8fb785092d934499b60.tar.bz2
base-files: automatically handle paths and symlinks for RAMFS_COPY_BIN
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>
Diffstat (limited to 'package/base-files')
-rw-r--r--package/base-files/files/lib/upgrade/common.sh27
-rwxr-xr-xpackage/base-files/files/lib/upgrade/stage243
-rwxr-xr-xpackage/base-files/files/sbin/sysupgrade2
3 files changed, 33 insertions, 39 deletions
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index c8b7101..428ec73 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -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() {
diff --git a/package/base-files/files/lib/upgrade/stage2 b/package/base-files/files/lib/upgrade/stage2
index 9d12cc8..5a439f1 100755
--- a/package/base-files/files/lib/upgrade/stage2
+++ b/package/base-files/files/lib/upgrade/stage2
@@ -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
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 809e789..359f21f 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -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