aboutsummaryrefslogtreecommitdiff
path: root/scripts/install.sh
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2008-02-24 01:34:01 -0600
committerRob Landley <rob@landley.net>2008-02-24 01:34:01 -0600
commitb15365a407868b24c602fd7e24a867e3df10e600 (patch)
treeb905741f7e18d7d9639afd104ead0ee450ebcc4e /scripts/install.sh
parent7a585c67ec5f62de1e5bb1a1e44ea8adc5919d28 (diff)
downloadtoybox-b15365a407868b24c602fd7e24a867e3df10e600.tar.gz
Add an install script, with --long --symlink --force and --uninstall options.
Diffstat (limited to 'scripts/install.sh')
-rwxr-xr-xscripts/install.sh92
1 files changed, 92 insertions, 0 deletions
diff --git a/scripts/install.sh b/scripts/install.sh
new file mode 100755
index 00000000..b8e03689
--- /dev/null
+++ b/scripts/install.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# Grab default values for $CFLAGS and such.
+
+source ./configure
+
+# Parse command line arguments.
+
+[ -z "$PREFIX" ] && PREFIX="."
+
+LONG_PATH=""
+while [ ! -z "$1" ]
+do
+ # Create symlinks instead of hardlinks?
+
+ [ "$1" == "--symlink" ] && LINK_TYPE="-s"
+
+ # Uninstall?
+
+ [ "$1" == "--uninstall" ] && UNINSTALL=1
+
+ # Delete destination command if it exists?
+
+ [ "$1" == "--force" ] && DO_FORCE="-f"
+
+ # Use {,usr}/{bin,sbin} paths instead of all files in one directory?
+
+ if [ "$1" == "--long" ]
+ then
+ LONG_PATH="bin/"
+ fi
+
+ shift
+done
+
+echo "Compile instlist..."
+
+$DEBUG $HOSTCC $CCFLAGS -I . scripts/install.c -o instlist || exit 1
+COMMANDS="$(./instlist $LONG_PATH)"
+
+echo "Install commands..."
+
+# Copy toybox itself
+
+if [ -z "$UNINSTALL" ]
+then
+ mkdir -p ${PREFIX}/${LONG_PATH} || exit 1
+ cp toybox ${PREFIX}/${LONG_PATH} || exit 1
+else
+ rm "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null
+ rmdir "${PREFIX}/${LONG_PATH}" 2>/dev/null
+fi
+cd "${PREFIX}"
+
+# Make links to toybox
+
+for i in $COMMANDS
+do
+ # Figure out target of link
+
+ if [ -z "$LONG_PATH" ]
+ then
+ DOTPATH=""
+ else
+ # Create subdirectory for command to go in (if necessary)
+
+ DOTPATH="$(echo $i | sed 's@\(.*/\).*@\1@')"
+ if [ -z "$UNINSTALL" ]
+ then
+ mkdir -p "$DOTPATH" || exit 1
+ else
+ rmdir "$DOTPATH" 2>/dev/null
+ fi
+
+ if [ -z "$LINK_TYPE" ]
+ then
+ dotpath="bin/"
+ else
+ if [ "$DOTPATH" != "$LONG_PATH" ]
+ then
+ DOTPATH="$(echo $DOTPATH | sed -e 's@[^/]*/@../@g')"$LONG_PATH
+ else
+ DOTPATH=""
+ fi
+ fi
+ fi
+
+ # Create link
+ [ -z "$UNINSTALL" ] &&
+ ln $DO_FORCE $LINK_TYPE ${DOTPATH}toybox $i ||
+ rm $i 2>/dev/null
+done