-
Notifications
You must be signed in to change notification settings - Fork 0
/
autostart_shelfslide.sh
executable file
·49 lines (38 loc) · 1.08 KB
/
autostart_shelfslide.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
#!/bin/bash
# Path to the Python program
PROGRAM_PATH="$(readlink -f ".")/shelfslide.py"
echo $PROGRAM_PATH
exit 1
# Name of the systemd service
SERVICE_NAME="shelfslide"
# Get the username of the person running the script
CURRENT_USER="$USER"
# Check if the service already exists
if systemctl is-active --quiet ${SERVICE_NAME}.service; then
echo "The service ${SERVICE_NAME} already exists."
exit 1
fi
# Check if the script is executed with root privileges
if [ "$EUID" -ne 0 ]; then
echo "This script requires root privileges. Please run it as root."
exit 1
fi
# Create the unit file
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
[Unit]
Description=ShelfSlide Python Program
[Service]
ExecStart=/usr/bin/python3 ${PROGRAM_PATH}
WorkingDirectory=$HOME/ShelfSlide
User=$CURRENT_USER
Group=$CURRENT_USER
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd
systemctl daemon-reload
# Enable and start the service
systemctl enable ${SERVICE_NAME}.service
systemctl start ${SERVICE_NAME}.service
# Display the status of the service
systemctl status ${SERVICE_NAME}.service