Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
63 lines (55 loc) · 1.67 KB
/
Copy pathinstall.sh
File metadata and controls
63 lines (55 loc) · 1.67 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
58
59
60
61
62
63
#!/usr/bin/env bash
# Build and install the Devzat welcome + remind bot.
#
# Run as root from this directory:
# sudo ./install.sh
#
# Pass config inline to avoid editing the env file afterwards:
# sudo DEVZAT_TOKEN=dvz@... ./install.sh
set -euo pipefail
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BIN=/usr/local/bin/devzat-bot
SVC=/etc/systemd/system/devzat-bot.service
ENV_FILE=/etc/devzat-bot.env
echo "==> Building devzat-bot"
( cd "$SRC_DIR" && go build -o "$BIN" . )
chmod 755 "$BIN"
echo "==> Installing systemd unit"
install -m 0644 "$SRC_DIR/devzat-bot.service" "$SVC"
if [ ! -f "$ENV_FILE" ]; then
echo "==> Creating $ENV_FILE"
install -m 0600 /dev/null "$ENV_FILE"
cat >"$ENV_FILE" <<'EOF'
# Devzat welcome + remind bot
# DEVZAT_TOKEN: mint one per plugin with `grant` (see devzat-deploy README)
DEVZAT_TOKEN=
WELCOME_ENABLED=true
REMIND_ENABLED=true
# WELCOME_FILE=/opt/devzat-bot/welcome.md
EOF
else
echo "==> Keeping existing $ENV_FILE"
fi
update_env() {
local key="$1" val="${2:-}"
[ -n "$val" ] || return 0
if grep -q "^${key}=" "$ENV_FILE"; then
sed -i "s|^${key}=.*|${key}=${val}|" "$ENV_FILE"
else
printf '%s=%s\n' "$key" "$val" >>"$ENV_FILE"
fi
}
update_env DEVZAT_TOKEN "${DEVZAT_TOKEN:-}"
update_env WELCOME_ENABLED "${WELCOME_ENABLED:-}"
update_env REMIND_ENABLED "${REMIND_ENABLED:-}"
chmod 600 "$ENV_FILE"
if ! grep -q '^DEVZAT_TOKEN=.\+' "$ENV_FILE"; then
echo
echo "WARNING: DEVZAT_TOKEN is empty — the bot will fail to start."
fi
echo "==> Starting service"
systemctl daemon-reload
systemctl enable devzat-bot
systemctl restart devzat-bot
echo
systemctl --no-pager --full status devzat-bot || true