fix directory creation issue

This commit is contained in:
2026-01-28 11:27:19 -05:00
parent b4fced29f6
commit e8ac5f2316
2 changed files with 86 additions and 40 deletions

View File

@@ -1,6 +1,17 @@
#!/bin/bash
# Production Setup Script for Faction War Dispatch Bot
# Run this script on your Linux server
# Run this script on your Linux server as root (sudo bash setup_production.sh)
#
# This script will:
# - Create a service user 'factionwar' (no password by default)
# - Clone the repository from https://git.jerick.xyz/jerick/faction_war_dispatch_bot.git
# - Install all dependencies
# - Configure Nginx with SSL
# - Set up systemd service
# - Configure firewall
#
# Note: To set a password for the factionwar user later (if needed for SSH):
# sudo passwd factionwar
set -e # Exit on error
@@ -37,23 +48,36 @@ apt install -y python3 python3-pip python3-venv nginx certbot python3-certbot-ng
echo ""
echo "Creating application user..."
if ! id "factionwar" &>/dev/null; then
adduser --group --home /opt/faction-war factionwar
# Create user without password (non-interactive)
adduser --disabled-password --gecos "" --home /opt/faction-war factionwar
echo "Created user: factionwar"
fi
echo ""
echo "Setting up application directory..."
mkdir -p /opt/faction-war
cd /opt/faction-war
mkdir -p /opt/faction-war/app
cd /opt/faction-war/app
# If app directory doesn't exist, clone or expect user to upload files
if [ ! -d "app" ]; then
echo "Please upload your application files to /opt/faction-war/app"
echo "Or clone from git repository"
exit 1
# Clone repository if directory is empty
if [ -z "$(ls -A /opt/faction-war/app)" ]; then
echo "Cloning repository from https://git.jerick.xyz/jerick/faction_war_dispatch_bot.git"
git clone https://git.jerick.xyz/jerick/faction_war_dispatch_bot.git .
if [ $? -ne 0 ]; then
echo "Failed to clone repository. Please check:"
echo " - Repository URL is correct"
echo " - You have access to the repository"
echo " - Network connection is working"
exit 1
fi
# Set ownership
chown -R factionwar:factionwar /opt/faction-war/app
echo "Repository cloned successfully"
else
echo "Application directory already exists, skipping clone"
fi
cd app
echo ""
echo "Setting up Python virtual environment..."
if [ ! -d "venv" ]; then
@@ -138,11 +162,17 @@ chmod +x /opt/faction-war/backup.sh
echo ""
echo "========================================"
echo "Setup Complete!"
echo "Setup Complete!"
echo "========================================"
echo ""
echo "Your application should now be running at: https://$DOMAIN"
echo ""
echo "User Account Information:"
echo " - Service user: factionwar (no password by default)"
echo " - Work as this user: sudo -u factionwar bash"
echo " - Set password (if needed): sudo passwd factionwar"
echo " - Application directory: /opt/faction-war/app"
echo ""
echo "Important next steps:"
echo "1. Visit https://$DOMAIN and log in with your AUTH_PASSWORD"
echo "2. Configure your API keys in the Settings page"
@@ -152,7 +182,8 @@ echo "Useful commands:"
echo " - Check status: sudo systemctl status faction-war"
echo " - View logs: sudo journalctl -u faction-war -f"
echo " - Restart: sudo systemctl restart faction-war"
echo " - Update code: cd /opt/faction-war/app && git pull && sudo systemctl restart faction-war"
echo " - Update code: cd /opt/faction-war/app && sudo -u factionwar git pull && sudo systemctl restart faction-war"
echo " - Edit config: sudo -u factionwar nano /opt/faction-war/app/.env"
echo ""
echo "Security reminders:"
echo " - Keep your .env file secure (chmod 600)"