-
Notifications
You must be signed in to change notification settings - Fork 37
/
post-install.sh
executable file
·78 lines (67 loc) · 1.91 KB
/
post-install.sh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e
HOME_DIR="$(eval echo "~$(logname)")"
# Argument parsing
NO_SUDO=false
SHORT=d:,s:,h
LONG=dest-dir:,sysconf-dir:,no-sudo,help
VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi
DEST_DIR="/usr"
SYSCONF_DIR="/etc"
eval set -- "$VALID_ARGS"
while true; do
case "$1" in
'--dest-dir' | '-d')
DEST_DIR=$2
shift
;;
'--sysconf-dir' | '-s')
SYSCONF_DIR=$2
shift
;;
'--no-sudo')
NO_SUDO=true
;;
'--help' | '-h')
echo "Usage: $0 [--dest-dir,-d <installation destination directory (defaults to $DEST_DIR)>] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-sudo]" 1>&2
exit 0
;;
--)
break
;;
esac
shift
done
# Root check
if [ "$EUID" -ne 0 ] && [ "$NO_SUDO" = false ]
then echo "This program requires root permissions or use the '--no-sudo' option"
exit 1
fi
SERVICES_DIR="./services"
SERVICE_EXTENSION=".service"
SERVICES="$(cd "$SERVICES_DIR" && find . -maxdepth 1 -maxdepth 1 -type f -name "*$SERVICE_EXTENSION" -exec basename {} "$SERVICE_EXTENSION" \;)"
function sanitizePath() {
local SANITIZED_PATH="$1"
local SANITIZED_PATH=${SANITIZED_PATH//..\//}
local SANITIZED_PATH=${SANITIZED_PATH#./}
local SANITIZED_PATH=${SANITIZED_PATH#/}
echo "$SANITIZED_PATH"
}
# move remaining legacy files
function move_legacy() {
echo "moving legacy files to their new destination"
(cp "$HOME_DIR/.config/fw-fanctrl"/* "$DEST_DIR$SYSCONF_DIR/fw-fanctrl/" && rm -rf "$HOME_DIR/.config/fw-fanctrl") 2> "/dev/null" || true
}
move_legacy
echo "enabling services"
systemctl daemon-reload
for SERVICE in $SERVICES ; do
SERVICE=$(sanitizePath "$SERVICE")
echo "enabling [$SERVICE]"
systemctl enable "$SERVICE"
echo "starting [$SERVICE]"
systemctl start "$SERVICE"
done