Files
rp-bot/SCRIPTS/update/update.sh
2026-06-17 13:38:08 -05:00

126 lines
3.2 KiB
Bash

#!/bin/bash
# OC Bot - Smart Update Script
# Usage: bash update.sh
# Pulls latest code and applies only necessary changes
# Coded by Ball Studios 🎨
set -e
echo "========================================="
echo " OC Bot - Smart Update Script"
echo " Coded by Ball Studios 🎨"
echo "========================================="
echo ""
# Check if this is a git repository
if [ ! -d ".git" ]; then
echo "❌ This is not a Git repository!"
echo "Please clone from GitHub first:"
echo "git clone https://github.com/BallStudios/rp-bot.git"
exit 1
fi
# Check for uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "⚠️ You have uncommitted changes:"
git status --short
echo ""
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Update cancelled."
exit 1
fi
fi
echo "📦 Checking for updates..."
echo ""
# Fetch latest changes from GitHub
echo "🔄 Fetching latest code from GitHub..."
git fetch origin
echo "✅ Fetched latest changes"
echo ""
# Check if there are updates available
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/main)
if [ "$LOCAL" = "$REMOTE" ]; then
echo "✅ Already up to date!"
echo ""
else
echo "📥 Pulling latest changes..."
git pull origin main
echo "✅ Code updated"
echo ""
fi
# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo "📦 Creating virtual environment..."
python3 -m venv venv
echo "✅ Virtual environment created"
fi
echo ""
# Activate virtual environment
echo "🔧 Activating virtual environment..."
source venv/bin/activate
echo "✅ Virtual environment activated"
echo ""
# Check for changed files
echo "🔍 Checking for code changes..."
CHANGED_FILES=$(git diff --name-only HEAD origin/main 2>/dev/null || echo "")
if [ -n "$CHANGED_FILES" ]; then
echo "📝 Changed files:"
echo "$CHANGED_FILES" | sed 's/^/ - /'
echo ""
fi
# Upgrade pip
echo "📦 Upgrading pip..."
pip install --upgrade pip > /dev/null 2>&1
echo "✅ Pip upgraded"
echo ""
# Update requirements if changed
if echo "$CHANGED_FILES" | grep -q "requirements.txt"; then
echo "📦 Installing/updating dependencies (requirements.txt changed)..."
pip install --upgrade -r requirements.txt
echo "✅ Dependencies updated"
echo ""
fi
# Database migration notice
if echo "$CHANGED_FILES" | grep -q "database.py"; then
echo "⚠️ database.py has been updated!"
echo ""
echo "If you encounter database errors after restart, run:"
echo " mysql -u root -p -e 'DROP DATABASE rp_bot; CREATE DATABASE rp_bot;'"
echo ""
fi
# Help system migration notice
if echo "$CHANGED_FILES" | grep -q "cogs/help.py"; then
echo "✅ Help system has been updated (fixed conflict with discord.py)"
echo ""
fi
echo "========================================="
echo " ✅ Update Complete!"
echo "========================================="
echo ""
echo "📝 Summary:"
echo "- Code pulled from GitHub"
echo "- Dependencies updated"
if [ -n "$CHANGED_FILES" ]; then
echo "- Files changed: $(echo \"$CHANGED_FILES\" | wc -l)"
fi
echo ""
echo "⚙️ Next: Restart the bot to apply updates"
echo ""