-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-install.sh
executable file
·114 lines (97 loc) · 2.81 KB
/
service-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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
#
# copy and chmod the systemd service files
# optionally, enable the service
#
# assumes goto_http_redirect_server has been installed and is in the $PATH
set -e
set -u
set -o pipefail
GOTO_FILE_REDIRECTS=/usr/local/share/goto_http_redirect_server.csv
GOTO_FILE_SCRIPT=/usr/local/bin/goto_http_redirect_server
GOTO_SYSTEMD_SH=/usr/local/bin/goto_http_redirect_server.sh
GOTO_CONFIG=/etc/goto_http_redirect_server.conf
GOTO_SERVICE=goto_http_redirect_server.service
GOTO_FILE_SERVICE=/etc/systemd/user/${GOTO_SERVICE}
enable=false
start=false
if ! which getopt &>/dev/null; then
echo "ERROR: GNU getopt not found. It is part of util-linux package." >&2
exit 1
fi
options=$(getopt -n "$(basename -- "${0}")" -o "esh?" -l "enable,start,help" -- "${@}")
eval set -- "${options}"
while true; do
case "${1-}" in
-e|--enable)
enable=true
shift
;;
-s|--start)
start=true
shift
;;
--)
shift
break
;;
*)
;&
h|help)
;&
\?)
(
echo "Usage: ${0} [-e|--enable] [-s|--start]"
echo
echo " -e enable systemd service"
echo " -s start systemd service (requires -e)"
echo
echo "Usage: ${0} [-h|--help|-?]"
echo
echo " This help message"
) >&2
exit 4
;;
esac
done
if ${start} && ! ${enable}; then
echo "Warning: --start without --enable will probably fail" >&2
fi
cd "$(dirname -- "${0}")/.."
# create redirects file
touch "${GOTO_FILE_REDIRECTS}"
chmod -v 0644 -- "${GOTO_FILE_REDIRECTS}"
# cp or link goto_http_redirect_server
if which goto_http_redirect_server &>/dev/null; then
ln -fvs -- "$(which goto_http_redirect_server)" "${GOTO_FILE_SCRIPT}"
else
cp -v -- ./goto_http_redirect_server/goto_http_redirect_server.py "${GOTO_FILE_SCRIPT}"
fi
# copy systemd wrapper
cp -v -- ./service/goto_http_redirect_server.sh "$(dirname -- "${GOTO_SYSTEMD_SH}")"
chmod -v 0755 -- "${GOTO_SYSTEMD_SH}"
# copy systemd wrapper configuration
cp -v -- ./service/goto_http_redirect_server.conf "${GOTO_CONFIG}"
chmod -v 0600 -- "${GOTO_CONFIG}"
# copy systemd service
cp -v -- ./service/goto_http_redirect_server.service "$(dirname -- "${GOTO_FILE_SERVICE}")"
chmod -v 0444 -- "${GOTO_FILE_SERVICE}"
# note settings of important files
ls -l \
"${GOTO_FILE_REDIRECTS}" \
"${GOTO_FILE_SCRIPT}" \
"${GOTO_SYSTEMD_SH}" \
"${GOTO_CONFIG}" \
"${GOTO_FILE_SERVICE}"
if ${enable}; then
(
set -x
systemctl enable "${GOTO_FILE_SERVICE}"
)
fi
if ${start}; then
(
set -x
systemctl start "${GOTO_SERVICE}"
)
fi