-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-service.sh
executable file
·76 lines (57 loc) · 1.95 KB
/
install-service.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
#!/bin/bash
SERVICE_PATH="/etc/systemd/system/EpitechIntranetProjectUpdateNotifier.service"
LOCAL_SERVICE_PATH="EpitechIntranetProjectUpdateNotifier/EpitechIntranetProjectUpdateNotifier.service"
echo "Installing EpitechIntranetProjectUpdateNotifier and creating a service"
if [[ $EUID -ne 0 ]]; then
if [ -z $(which npm) ]; then
echo "You need npm to run this project" 1>&2
exit 1
fi
if [ -z $(which node) ]; then
echo "You need node to run this project" 1>&2
exit 1
fi
if [ -z $(which systemctl) ]; then
echo "You need systemctl to setup the service" 1>&2
exit 1
fi
if [ -z $(which git) ]; then
echo "You need git to clone this project" 1>&2
exit 1
fi
if [ -z $(which sed) ]; then
echo "You need sed to setup the service" 1>&2
exit 1
fi
echo "Cloning project in the current directory..."
git clone https://github.com/alwyn974/EpitechIntranetProjectUpdateNotifier
echo "Replacing %USER% to '$USER'"
GROUP=$(id -Gn | cut -d' ' -f1)
echo "Replacing %GROUP% to '$GROUP'"
NPM_PATH=$(which npm)
echo "Replacing %NPM_PATH% to '$NPM_PATH'"
PROJECT_PATH="$(pwd)/EpitechIntranetProjectUpdateNotifier"
echo "Replacing %PATH% to '$PROJECT_PATH'"
SERVICE="[Unit]
Description=EpitechIntranetProjectUpdateNotifier service.
After=network-online.target
[Service]
Type=simple
User=$USER
Group=$GROUP
ExecStart=$NPM_PATH --prefix $PROJECT_PATH start
Restart=on-failure
[Install]
WantedBy=multi-user.target
"
echo "$SERVICE" > "$LOCAL_SERVICE_PATH"
echo "Sudo permission is needed now..."
echo "Please restart the script with sudo"
else
sudo mv "$LOCAL_SERVICE_PATH" "$SERVICE_PATH"
sudo chmod 644 "$SERVICE_PATH"
sudo systemctl enable "$SERVICE_PATH"
sudo systemctl start EpitechIntranetProjectUpdateNotifier
echo "The service has been setup and started"
echo "Check the service with systemctl status EpitechIntranetProjectUpdateNotifier"
fi