aboutsummaryrefslogtreecommitdiffstats
path: root/testing/ubase/setup-ubase.in
diff options
context:
space:
mode:
Diffstat (limited to 'testing/ubase/setup-ubase.in')
-rw-r--r--testing/ubase/setup-ubase.in125
1 files changed, 125 insertions, 0 deletions
diff --git a/testing/ubase/setup-ubase.in b/testing/ubase/setup-ubase.in
new file mode 100644
index 00000000000..68463e7e94d
--- /dev/null
+++ b/testing/ubase/setup-ubase.in
@@ -0,0 +1,125 @@
+#!/bin/sh
+#---help---
+# Usage:
+# setup-ubase install [-d <dest>] [-f] [-v] [<applet>...]
+# setup-ubase uninstall [-d <dest>] [-v] [<applet>...]
+# setup-ubase status [-d <dest>]
+# setup-ubase (-h | -V)
+#
+# Install or uninstall applet symlinks for ubase-box.
+#
+# Arguments:
+# <applet> Name of the applet(s) to (un)install or show status for.
+# Defaults to all ubase-box applets.
+#
+# Options:
+# -d <dest> Path to directory where to install ubase symlinks. If not given,
+# symlinks are created in the same directories as busybox symlinks
+# (if busybox is installed, otherwise /usr/bin).
+# -f If the symlink destination exists, replace it.
+# -v Be verbose.
+# -h Show this message and exit.
+# -V Print ubox version and exit.
+#
+# Report bugs at <https://gitlab.alpinelinux.org/alpine/aports/-/issues>
+#---help---
+set -eu
+
+PROGNAME='setup-ubase'
+VERSION=@@VERSION@@
+UBASE_BOX='/bin/ubase-box'
+
+
+help() {
+ sed -n '/^#---help---/,/^#---help---/p' "$0" | sed 's/^# \?//; 1d;$d;'
+}
+
+die() {
+ echo "$PROGNAME: $2" >&2
+ exit $1
+}
+
+bb_appletdir() {
+ local path=$(/bin/busybox --list-full | grep "/$1$" 2>/dev/null) || :
+ path=${path%/*}
+
+ echo "/${path:-usr/bin}"
+}
+
+if [ $# -eq 0 ]; then
+ help; exit 1
+fi
+
+ACTION=
+case "${1:-}" in
+ -*);;
+ *) ACTION=$1; shift;;
+esac
+
+DESTDIR=
+FORCE=false
+VERBOSE=false
+while getopts ':d:fvhV' OPT; do
+ case "$OPT" in
+ d) DESTDIR="$OPTARG";;
+ f) FORCE=true;;
+ v) VERBOSE=true;;
+ h) help; exit 0;;
+ V) echo "ubase $VERSION"; exit 0;;
+ \?) die 10 "unknown option: -$OPTARG";;
+ esac
+done
+shift $((OPTIND - 1))
+
+[ "$ACTION" ] || { ACTION=${1:-}; shift; }
+[ "$ACTION" ] || die 10 "invalid arguments, missing <action> (see $PROGNAME -h)"
+
+[ -x $UBASE_BOX ] || die 10 "ERROR: $UBASE_BOX does not exist or is not executable!"
+
+[ $# -eq 0 ] && set -- $($UBASE_BOX)
+
+rc=0
+for applet in "$@"; do
+ applet_link="${DESTDIR:-$(bb_appletdir $applet)}/$applet"
+
+ case "$ACTION" in
+ install)
+ [ "$applet_link" -ef "$UBASE_BOX" ] && continue
+
+ if [ -e "$applet_link" ] && ! $FORCE; then
+ $VERBOSE && echo "Skipping $applet - file $applet_link exists" >&2
+ continue
+ fi
+
+ $VERBOSE && echo "Creating symlink $applet_link -> $UBASE_BOX"
+ ln -fs "$UBASE_BOX" "$applet_link" || rc=11
+ ;;
+ uninstall)
+ if [ "$applet_link" -ef "$UBASE_BOX" ]; then
+ $VERBOSE && echo "Removing $applet_link"
+ rm "$applet_link" || rc=11
+ fi
+ ;;
+ status)
+ state=
+ if [ "$applet_link" -ef "$UBASE_BOX" ]; then
+ state='installed'
+ elif [ -e "$applet_link" ]; then
+ state="not-installed ($applet_link exists)"
+ else
+ state='not-installed'
+ fi
+ printf '%-13s%s\n' "$applet" "$state"
+ ;;
+ *)
+ die 10 "invalid action: $ACTION"
+ ;;
+ esac
+done
+
+if [ "$ACTION" = 'uninstall' ] && [ -x /bin/busybox ]; then
+ # Restore possibly overwritten busybox symlinks.
+ /bin/busybox --install -s
+fi
+
+exit $rc