-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·46 lines (37 loc) · 863 Bytes
/
build.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
APP_ROOT=/opt/barracuda
SERVICE_FILE=/etc/systemd/system/barracuda.service
SERVICE_EXISTS=0
read -r -d '' SERVICE_TEMPLATE << EOF
[Unit]
Description=Barracuda Server
After=network.target
[Service]
ExecStart=%s/bin/barracuda
User=%s
Type=simple
Restart=always
[Install]
WantedBy=multi-user.target\n
EOF
if [[ $(id -u) > 0 ]]; then
echo "script must be run as root" >&2
exit 1
fi
if [[ -e "$SERVICE_FILE" ]]; then
echo "stopping service"
SERVICE_EXISTS=1
# systemctl stop barracuda
else
echo "creating service"
printf "$SERVICE_TEMPLATE" $APP_ROOT $USER > $SERVICE_FILE
fi
echo "building application"
go build -o ${APP_ROOT}/bin/barracuda ./cmd
echo "build success"
if [[ $SERVICE_EXISTS == 1 ]]; then
echo "restarting service"
systemctl restart barracuda
exit 0
fi
echo "starting service"
systemctl start barracuda