-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebind-devices-setup
executable file
·59 lines (50 loc) · 1.21 KB
/
rebind-devices-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Installer script
# (C) Mark Blakeney, Feb 2021.
PROG="$(basename $0)"
NAME=${PROG%-*}
SHRDIR="/usr/share/$NAME"
SYSDIR="/usr/lib/systemd/system"
usage() {
echo "Usage:"
echo "As root: sudo $PROG install|uninstall"
echo
echo "(-d option sets DESTDIR for install/uninstall)"
exit 1
}
# Process command line options
DESTDIR=""
while getopts d: c; do
case $c in
d) DESTDIR="$OPTARG";;
\?) usage;;
esac
done
shift $((OPTIND - 1))
if [[ $# -ne 1 ]]; then
usage
fi
cmd="$1"
if [[ $cmd == install || $cmd == uninstall ]]; then
DESTDIR="${DESTDIR%%+(/)}"
if [[ -z $DESTDIR && $(id -un) != root ]]; then
echo "Install or uninstall must be run as sudo/root."
exit 1
fi
if [[ $cmd == install ]]; then
install -CDv -m 755 -t $DESTDIR/usr/bin $NAME
install -CDv -m 644 -t $DESTDIR$SYSDIR $NAME.service
install -CDv -m 644 -t $DESTDIR$SHRDIR $NAME.conf
install -CDv -m 644 -t $DESTDIR$SHRDIR README.md
if [[ -z $DESTDIR && ! -f /etc/$NAME.conf ]]; then
echo "Now copy $SHRDIR/$NAME.conf to /etc/ and edit appropriately"
fi
else
rm -rfv $DESTDIR$SHRDIR
rm -fv $DESTDIR$SYSDIR/$NAME.service
rm -fv $DESTDIR/usr/bin/$NAME
fi
else
usage
fi
exit 0