-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·69 lines (57 loc) · 1.51 KB
/
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
#!/usr/bin/bash
pip install pygame
pip install keyboard
sudo cat > config.py <<EOF
PATH="`pwd`"
EOF
sudo cat > delete.sh <<EOF
#!/bin/bash
echo "-----------------------------"
echo "Press END key to STOP Service"
echo "-----------------------------"
sudo systemctl stop keyboard_prank
sudo rm /etc/systemd/system/keyboard_prank.service
sudo rm `pwd`/config.py
sudo systemctl daemon-reload
echo " "
echo "-----------------------------"
echo "The Service Deleted."
echo "-----------------------------"
sudo rm delete.sh
EOF
# remove the double quotes
DESCRIPTION="keyboard_prank"
SERVICE_NAME="keyboard_prank"
PKG_PATH="/usr/bin/python3"
SERVICE_PATH=`pwd`"/main.py"
# check if service is active
IS_ACTIVE=$(sudo systemctl is-active $SERVICE_NAME)
if [ "$IS_ACTIVE" == "active" ]; then
# restart the service
echo "Service is running"
echo "Restarting service"
sudo systemctl restart $SERVICE_NAME
echo "Service restarted"
else
# create service file
echo "Creating service file"
sudo cat > /etc/systemd/system/${SERVICE_NAME//'"'/}.service << EOF
[Unit]
Description=$DESCRIPTION
After=network.target
[Service]
ExecStart=$PKG_PATH $SERVICE_PATH
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable ${SERVICE_NAME//'.service'/} # remove the extension
sudo systemctl start ${SERVICE_NAME//'.service'/}
echo "Service Started"
fi
sudo chmod +x main.py
sudo chmod +x install.sh
sudo chmod +x config.py
sudo chmod +x delete.sh
exit 0