The install.sh has the useful capabilty to suppress clobbering
of files during installation.  Unfortunately, this feature is
hard to enable because (1) the Makefile.custom does not provide a
way to specify --noclobber and (2) the install.sh only looks at
the second positional argument.

This patch adds a kconfig switch to specify --noclobber when
configured to install with soft or hard links, and modifies the
install.sh to process all the input arguments.

Signed-off-by: Danomi Manchego <[email protected]>
---
 Config.in          |    8 ++++++++
 Makefile.custom    |    3 +++
 applets/install.sh |   26 +++++++++++++++-----------
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/Config.in b/Config.in
index b6eaea5..5698ce1 100644
--- a/Config.in
+++ b/Config.in
@@ -787,6 +787,14 @@ config INSTALL_SH_APPLET_SCRIPT_WRAPPER
 
 endchoice
 
+config INSTALL_SH_LINK_NOCLOBBER
+       bool "Do not clobber existing files"
+       default n
+       depends on INSTALL_APPLET_SYMLINKS || INSTALL_APPLET_HARDLINKS
+       help
+         Selecting this will prevent clobbering of existing files during
+         link installation.
+
 config PREFIX
        string "BusyBox installation prefix"
        default "./_install"
diff --git a/Makefile.custom b/Makefile.custom
index 8c95ef2..bb23fb3 100644
--- a/Makefile.custom
+++ b/Makefile.custom
@@ -28,6 +28,9 @@ ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
 INSTALL_OPTS:= --scriptwrapper
 endif
 endif
+ifeq ($(CONFIG_INSTALL_SH_LINK_NOCLOBBER),y)
+INSTALL_OPTS+= --noclobber
+endif
 install: $(srctree)/applets/install.sh busybox busybox.links
        $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
                $(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
diff --git a/applets/install.sh b/applets/install.sh
index 95b4719..ec01a9c 100755
--- a/applets/install.sh
+++ b/applets/install.sh
@@ -15,17 +15,21 @@ linkopts=""
 scriptwrapper="n"
 cleanup="0"
 noclobber="0"
-case "$2" in
-       --hardlinks)     linkopts="-f";;
-       --symlinks)      linkopts="-fs";;
-       --scriptwrapper) scriptwrapper="y";swrapall="y";;
-       --sw-sh-hard)    scriptwrapper="y";linkopts="-f";;
-       --sw-sh-sym)     scriptwrapper="y";linkopts="-fs";;
-       --cleanup)       cleanup="1";;
-       --noclobber)     noclobber="1";;
-       "")              h="";;
-       *)               echo "Unknown install option: $2"; exit 1;;
-esac
+
+while [ -n "$2" ]; do
+       case "$2" in
+               --hardlinks)     linkopts="-f";;
+               --symlinks)      linkopts="-fs";;
+               --scriptwrapper) scriptwrapper="y";swrapall="y";;
+               --sw-sh-hard)    scriptwrapper="y";linkopts="-f";;
+               --sw-sh-sym)     scriptwrapper="y";linkopts="-fs";;
+               --cleanup)       cleanup="1";;
+               --noclobber)     noclobber="1";;
+               "")              h="";;
+               *)               echo "Unknown install option: $2"; exit 1;;
+       esac
+       shift
+done
 
 if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
        # get the target dir for the libs
-- 
1.7.9.5

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to