58 lines
1.4 KiB
Bash
58 lines
1.4 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
set -e
|
||
|
|
|
||
|
|
BOTDIR="/root/code/discordBot"
|
||
|
|
SERVICE_NAME="discord-bot"
|
||
|
|
|
||
|
|
echo "[Discord Bot] Pulling latest code..."
|
||
|
|
|
||
|
|
# Backup .env if it exists
|
||
|
|
if [ -f "$BOTDIR/.env" ]; then
|
||
|
|
cp "$BOTDIR/.env" /tmp/.env.backup
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Backup media and logs folders
|
||
|
|
if [ -d "$BOTDIR/media" ]; then
|
||
|
|
cp -r "$BOTDIR/media" /tmp/media.backup
|
||
|
|
fi
|
||
|
|
if [ -d "$BOTDIR/logs" ]; then
|
||
|
|
cp -r "$BOTDIR/logs" /tmp/logs.backup
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ ! -d "$BOTDIR/.git" ]; then
|
||
|
|
echo "Directory not a git repo — performing initial clone..."
|
||
|
|
rm -rf "$BOTDIR"
|
||
|
|
git clone https://code.lotusguild.org/LotusGuild/discordBot.git "$BOTDIR"
|
||
|
|
else
|
||
|
|
echo "Updating existing repo..."
|
||
|
|
cd "$BOTDIR"
|
||
|
|
git fetch --all
|
||
|
|
git reset --hard origin/main
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Restore .env if it was backed up
|
||
|
|
if [ -f /tmp/.env.backup ]; then
|
||
|
|
mv /tmp/.env.backup "$BOTDIR/.env"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Restore media and logs folders
|
||
|
|
if [ -d /tmp/media.backup ]; then
|
||
|
|
rm -rf "$BOTDIR/media"
|
||
|
|
mv /tmp/media.backup "$BOTDIR/media"
|
||
|
|
fi
|
||
|
|
if [ -d /tmp/logs.backup ]; then
|
||
|
|
rm -rf "$BOTDIR/logs"
|
||
|
|
mv /tmp/logs.backup "$BOTDIR/logs"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[Discord Bot] Installing/updating dependencies..."
|
||
|
|
cd "$BOTDIR"
|
||
|
|
pip3 install -r requirements.txt 2>/dev/null || echo "No requirements.txt found, skipping..."
|
||
|
|
|
||
|
|
echo "[Discord Bot] Restarting service..."
|
||
|
|
systemctl restart "$SERVICE_NAME"
|
||
|
|
|
||
|
|
echo "[Discord Bot] Deployment complete!"
|
||
|
|
echo "[Discord Bot] Service status:"
|
||
|
|
systemctl status "$SERVICE_NAME" --no-pager
|