-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_bot.sh
executable file
·53 lines (33 loc) · 1.12 KB
/
update_bot.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
#!/bin/bash
# This script is used to update the bot from the git repository and start the bot.
# This is used by the systemd service.
# And the cronjob will use the systemd service to restart the bot at 02 AM.
# check if it is for lavalink
if [ "$1" == "lavalink" ]; then
if [ "$PWD" != "$HOME/critbot/config" ]; then
cd $HOME/critbot/config
fi
if tmux has-session -t lavalink 2>/dev/null; then
tmux kill-session -t lavalink
fi
tmux new-session -d -s lavalink "$HOME/.sdkman/candidates/java/current/bin/java -jar Lavalink.jar" # using sdkman
exit 0
fi
if [ "$PWD" != "$HOME/critbot" ]; then
cd $HOME/critbot
fi
# check if there are any changes
git fetch
if [ "$(git rev-parse HEAD)" == "$(git rev-parse @{u})" ]; then
echo "No changes"
exit 0
fi
# update the bot
git pull
export PATH=/home/$USER/.local/bin:$PATH # for pdm
if tmux has-session -t critbot 2>/dev/null; then
tmux kill-session -t critbot
fi
tmux new-session -d -s critbot "source .venv/bin/activate && pdm start -l 0.0.0.0:2333"
# crontab -e
# 0 2 * * * /usr/bin/systemctl --user restart critbot.service