Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9fc646

Browse files
authored
Merge pull request #8 from Unity-Lab-AI/codex/2025-08-08-test-and-fix-discord-bot-errors
Handle missing env vars in setup and systemd check
2 parents 804a989 + 73ddcc5 commit b9fc646

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

install.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@ set -e
66
SERVICE_NAME="unitybot"
77
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
88

9+
if [ "$(id -u)" -eq 0 ]; then
10+
SUDO=""
11+
else
12+
SUDO="sudo"
13+
fi
14+
15+
if ! command -v systemctl >/dev/null; then
16+
echo "systemctl not found. This installer requires systemd." >&2
17+
exit 1
18+
fi
19+
if [ ! -d /run/systemd/system ]; then
20+
echo "systemd is not running. Cannot install service." >&2
21+
exit 1
22+
fi
23+
924
VENV_PYTHON="${SCRIPT_DIR}/.venv/bin/python"
1025
if [ ! -x "$VENV_PYTHON" ]; then
1126
echo "Virtual environment not found. Run setup.sh before installing the service." >&2
1227
exit 1
1328
fi
1429

15-
cat <<EOF | sudo tee /etc/systemd/system/${SERVICE_NAME}.service >/dev/null
30+
cat <<EOF | $SUDO tee /etc/systemd/system/${SERVICE_NAME}.service >/dev/null
1631
[Unit]
1732
Description=UnityBot Discord Bot
1833
After=network.target
@@ -29,9 +44,9 @@ Restart=on-failure
2944
WantedBy=multi-user.target
3045
EOF
3146

32-
sudo systemctl daemon-reload
33-
sudo systemctl enable ${SERVICE_NAME}
34-
sudo systemctl start ${SERVICE_NAME}
47+
$SUDO systemctl daemon-reload
48+
$SUDO systemctl enable ${SERVICE_NAME}
49+
$SUDO systemctl start ${SERVICE_NAME}
3550

3651
echo "Service ${SERVICE_NAME} installed and started."
3752

setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ source .venv/bin/activate
6666
prompt_var() {
6767
local var_name=$1
6868
local env_val
69-
env_val=$(printenv "$var_name")
69+
env_val=$(printenv "$var_name" 2>/dev/null || true)
7070
local file_val=""
71-
[[ -f .env ]] && file_val=$(grep -E "^${var_name}=" .env | cut -d'=' -f2-)
71+
[[ -f .env ]] && file_val=$(grep -E "^${var_name}=" .env | cut -d'=' -f2- 2>/dev/null || true)
7272

7373
if [[ "$TARGET" == "env" ]]; then
7474
if [[ -n "$file_val" ]]; then

0 commit comments

Comments
 (0)