Completed clean root directory structure: - Root now contains only: .git, .env, docs/, orig/ - Moved all remaining files and directories to orig/: - Config files (.claude, .dockerignore, .drone.yml, etc.) - All .env variants (except active .env) - Git config (.gitconfig, .github, .gitignore, etc.) - Tool configs (.golangci.yml, .revive.toml, etc.) - Documentation (*.md files, @prompts) - Build files (Dockerfiles, Makefile, go.mod, go.sum) - Docker compose files - All source directories (scripts, tests, tools, etc.) - Runtime directories (logs, monitoring, reports) - Dependency files (node_modules, lib, cache) - Special files (--delete) - Removed empty runtime directories (bin/, data/) V2 structure is now clean: - docs/planning/ - V2 planning documents - orig/ - Complete V1 codebase preserved - .env - Active environment config (not in git) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
150 lines
4.6 KiB
Bash
Executable File
150 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Setup Auto-Update System for MEV Bot
|
|
# This script installs git hooks and optionally systemd timers for automatic updates
|
|
|
|
set -e
|
|
|
|
PROJECT_DIR=$(cd "$(dirname "$0")/.." && pwd)
|
|
|
|
# Color codes
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${BLUE}========================================="
|
|
echo "MEV Bot Auto-Update Setup"
|
|
echo "=========================================${NC}"
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
IS_ROOT=false
|
|
if [ "$EUID" -eq 0 ]; then
|
|
IS_ROOT=true
|
|
echo -e "${YELLOW}Running as root - will setup systemd timer${NC}"
|
|
else
|
|
echo -e "${YELLOW}Not running as root - will skip systemd timer${NC}"
|
|
echo -e "${YELLOW}Run with sudo to enable automatic periodic updates${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 1: Install git hooks
|
|
echo -e "${BLUE}Step 1: Installing Git Hooks${NC}"
|
|
echo "-------------------------------------------"
|
|
cd "$PROJECT_DIR"
|
|
|
|
if [ -f "$PROJECT_DIR/scripts/install-git-hooks.sh" ]; then
|
|
"$PROJECT_DIR/scripts/install-git-hooks.sh"
|
|
echo -e "${GREEN}✓ Git hooks installed${NC}"
|
|
else
|
|
echo -e "${RED}✗ Git hooks installation script not found${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Step 2: Setup systemd timer (if root)
|
|
if [ "$IS_ROOT" = true ]; then
|
|
echo -e "${BLUE}Step 2: Setting up Systemd Timer${NC}"
|
|
echo "-------------------------------------------"
|
|
|
|
# Update WorkingDirectory in service files
|
|
sed "s|WorkingDirectory=/docker/mev-beta|WorkingDirectory=$PROJECT_DIR|g" \
|
|
"$PROJECT_DIR/scripts/mev-bot-auto-update.service" > /tmp/mev-bot-auto-update.service
|
|
|
|
sed "s|/docker/mev-beta|$PROJECT_DIR|g" \
|
|
/tmp/mev-bot-auto-update.service > /tmp/mev-bot-auto-update.service.tmp
|
|
mv /tmp/mev-bot-auto-update.service.tmp /tmp/mev-bot-auto-update.service
|
|
|
|
# Copy service and timer files
|
|
cp /tmp/mev-bot-auto-update.service /etc/systemd/system/
|
|
cp "$PROJECT_DIR/scripts/mev-bot-auto-update.timer" /etc/systemd/system/
|
|
|
|
# Reload systemd
|
|
systemctl daemon-reload
|
|
|
|
# Enable and start the timer
|
|
systemctl enable mev-bot-auto-update.timer
|
|
systemctl start mev-bot-auto-update.timer
|
|
|
|
echo -e "${GREEN}✓ Systemd timer enabled and started${NC}"
|
|
echo ""
|
|
|
|
# Show timer status
|
|
echo -e "${YELLOW}Timer status:${NC}"
|
|
systemctl status mev-bot-auto-update.timer --no-pager | head -10
|
|
echo ""
|
|
|
|
# Show next scheduled run
|
|
echo -e "${YELLOW}Next scheduled update check:${NC}"
|
|
systemctl list-timers mev-bot-auto-update.timer --no-pager
|
|
echo ""
|
|
else
|
|
echo -e "${BLUE}Step 2: Systemd Timer (Skipped)${NC}"
|
|
echo "-------------------------------------------"
|
|
echo -e "${YELLOW}Run 'sudo ./scripts/setup-auto-update.sh' to enable automatic updates${NC}"
|
|
echo ""
|
|
fi
|
|
|
|
# Step 3: Create logs directory
|
|
echo -e "${BLUE}Step 3: Creating Logs Directory${NC}"
|
|
echo "-------------------------------------------"
|
|
mkdir -p "$PROJECT_DIR/logs"
|
|
echo -e "${GREEN}✓ Logs directory created${NC}"
|
|
echo ""
|
|
|
|
# Summary
|
|
echo -e "${GREEN}========================================="
|
|
echo "Auto-Update Setup Complete!"
|
|
echo "=========================================${NC}"
|
|
echo ""
|
|
|
|
echo "What's been configured:"
|
|
echo ""
|
|
echo "1. Git Hooks:"
|
|
echo " ✓ post-merge hook installed"
|
|
echo " → Triggers auto-rebuild after 'git pull'"
|
|
echo ""
|
|
|
|
if [ "$IS_ROOT" = true ]; then
|
|
echo "2. Systemd Timer:"
|
|
echo " ✓ Checks for updates every 5 minutes"
|
|
echo " ✓ Starts automatically on boot"
|
|
echo " ✓ Pulls and rebuilds when updates detected"
|
|
echo ""
|
|
echo "Manage the timer:"
|
|
echo " sudo systemctl status mev-bot-auto-update.timer"
|
|
echo " sudo systemctl stop mev-bot-auto-update.timer"
|
|
echo " sudo systemctl start mev-bot-auto-update.timer"
|
|
echo " sudo journalctl -u mev-bot-auto-update -f"
|
|
echo ""
|
|
else
|
|
echo "2. Manual Updates:"
|
|
echo " Run: ./scripts/auto-update.sh"
|
|
echo " Or: git pull (hooks will auto-rebuild)"
|
|
echo ""
|
|
fi
|
|
|
|
echo "3. Logs:"
|
|
echo " Auto-update log: tail -f logs/auto-update.log"
|
|
echo " Container log: docker compose logs -f mev-bot"
|
|
echo ""
|
|
|
|
echo -e "${BLUE}Optional: Webhook Receiver${NC}"
|
|
echo "-------------------------------------------"
|
|
echo "For immediate updates via GitHub/GitLab webhooks:"
|
|
echo ""
|
|
echo "1. Configure webhook in your Git provider:"
|
|
echo " URL: http://your-server:9000/webhook"
|
|
echo " Events: Push events (master branch)"
|
|
echo ""
|
|
echo "2. Start the webhook receiver:"
|
|
echo " ./scripts/webhook-receiver.sh"
|
|
echo ""
|
|
echo "Or run as systemd service (advanced setup needed)"
|
|
echo ""
|
|
|
|
echo -e "${GREEN}Your MEV bot will now auto-update! 🚀${NC}"
|
|
echo ""
|