summaryrefslogtreecommitdiff
path: root/tests/bin/rc-update
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2022-05-19 13:04:37 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2022-05-19 13:04:37 +0200
commit8885850cab6cecf83d65ff7233677827e16762fa (patch)
treedf7fa2f9aebfb1a3dc40facd7a63cf3922fcefa1 /tests/bin/rc-update
parentbc01f011019828ffda721ba2078ee75f216e4ae7 (diff)
downloadalpine-conf-8885850cab6cecf83d65ff7233677827e16762fa.zip
tests: add fake rc-update binary
and add tests for it to verify that it actually works as expected We can use this for the other tests later
Diffstat (limited to 'tests/bin/rc-update')
-rwxr-xr-xtests/bin/rc-update67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/bin/rc-update b/tests/bin/rc-update
new file mode 100755
index 0000000..cb7ee36
--- /dev/null
+++ b/tests/bin/rc-update
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+prog=$0
+usage() {
+ echo "usage: rc-update [--quiet] add|del|delete SVC RUNLEVEL"
+ exit $1
+}
+
+msg() {
+ if ! [ -n "$quiet" ]; then
+ echo "$@"
+ fi
+}
+
+OPTS=$(getopt -l quiet,help -o "qh" -n $prog -- "$@") || usage "1" >&2
+
+quiet=
+eval set -- "$OPTS"
+for opt; do
+ case "$opt" in
+ -h|--help)
+ usage 0
+ ;;
+ --quiet)
+ quiet=1
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *) usage "1" >&2
+ ;;
+ esac
+ shift
+done
+
+cmd="$1"
+svc="$2"
+runlevel="${3:-default}"
+
+if [ -z "$cmd" ] || [ -z "$svc" ]; then
+ usage "1" >&2
+fi
+
+case "$cmd" in
+ add)
+ if [ -L "$ROOT"/etc/runlevels/$runlevel/$svc ]; then
+ msg " * rc-update: $svc already installed in runlevel \`$runlevel'; skipping"
+ exit 0
+ fi
+ mkdir -p "$ROOT"/etc/runlevels/$runlevel
+ ln -sf ../../init.d/$svc "$ROOT"/etc/runlevels/$runlevel/$svc
+ msg " * service $svc added to runlevel $runlevel"
+ ;;
+ del|delete)
+ if ! [ -L "$ROOT"/etc/runlevels/$runlevel/$svc ]; then
+ msg " * rc-update: service \`$svc' is not in the runlevel \`$runlevel'" >&2
+ exit 1
+ fi
+ rm "$ROOT"/etc/runlevels/$runlevel/$svc
+ msg " * service foo removed from runlevel $runlevel"
+ ;;
+ *) usage "1" >&2
+ ;;
+esac
+
+