-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·58 lines (46 loc) · 1.34 KB
/
install.sh
File metadata and controls
executable file
·58 lines (46 loc) · 1.34 KB
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
#!/bin/bash
set -euo pipefail
# Install UnityBotV4 as a systemd service on Linux
SERVICE_NAME="unitybot"
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
# Run the service as the invoking user instead of root when using sudo
RUN_USER="${SUDO_USER:-$(id -un)}"
RUN_GROUP="$(id -gn "$RUN_USER")"
if [ "$(id -u)" -eq 0 ]; then
SUDO=""
else
SUDO="sudo"
fi
if ! command -v systemctl >/dev/null; then
echo "systemctl not found. This installer requires systemd." >&2
exit 1
fi
if [ ! -d /run/systemd/system ]; then
echo "systemd is not running. Cannot install service." >&2
exit 1
fi
VENV_PYTHON="${SCRIPT_DIR}/.venv/bin/python"
if [ ! -x "$VENV_PYTHON" ]; then
echo "Virtual environment not found. Run setup.sh before installing the service." >&2
exit 1
fi
cat <<EOF | $SUDO tee "/etc/systemd/system/${SERVICE_NAME}.service" >/dev/null
[Unit]
Description=UnityBot Discord Bot
After=network.target
[Service]
Type=simple
User="${RUN_USER}"
Group="${RUN_GROUP}"
WorkingDirectory="${SCRIPT_DIR}"
EnvironmentFile=-"${SCRIPT_DIR}/.env"
EnvironmentFile=-/etc/environment
ExecStart="${VENV_PYTHON}" "${SCRIPT_DIR}/bot.py"
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
$SUDO systemctl daemon-reload
$SUDO systemctl enable "${SERVICE_NAME}"
$SUDO systemctl start "${SERVICE_NAME}"
echo "Service ${SERVICE_NAME} installed and started."