Enhance frontend installation script with improved system packages and static backend URL

- Add essential system packages and networking tools
- Install official Docker CE with proper configuration
- Configure backend connection to static IP 192.168.0.105
- Generate secure random AUTH_SECRET during installation
- Add environment example file for version control
- Improve post-installation information and helpful commands

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Till Tomczak 2025-03-26 13:20:44 +01:00
parent aad1be90ee
commit 8366a9295e

View File

@ -24,6 +24,14 @@ command_exists() {
log "===== Starting MYP Frontend Installation ====="
log "Installation directory: $SCRIPT_DIR"
# Display system information
log "System information:"
uname -a >> "$LOG_FILE" 2>&1
lsb_release -a >> "$LOG_FILE" 2>&1 || cat /etc/os-release >> "$LOG_FILE" 2>&1
log "CPU: $(grep "model name" /proc/cpuinfo | head -n1 | cut -d':' -f2 | sed 's/^ *//')"
log "Memory: $(free -h | grep "Mem:" | awk '{print $2}')"
log "Disk space: $(df -h / | awk 'NR==2 {print $4}') free on /"
# Check for root privileges
if [ "$EUID" -ne 0 ]; then
log "ERROR: This script must be run as root"
@ -36,8 +44,39 @@ apt update -y >> "$LOG_FILE" 2>&1
apt upgrade -y >> "$LOG_FILE" 2>&1
# Install required packages
log "Installing required system packages..."
apt install -y curl git docker.io docker-compose xz-utils sqlite3 >> "$LOG_FILE" 2>&1
log "Installing essential system packages and network tools..."
apt install -y curl git wget htop net-tools iptables iputils-ping traceroute nmap tcpdump nftables \
netcat-openbsd dnsutils whois vim nano rsync zip unzip xz-utils sqlite3 \
apt-transport-https ca-certificates gnupg lsb-release >> "$LOG_FILE" 2>&1
# Install Docker using the official Docker repository
log "Installing Docker from official repository..."
if ! command_exists docker; then
# Remove any old Docker versions
apt remove -y docker docker-engine docker.io containerd runc >> "$LOG_FILE" 2>&1 || true
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg >> "$LOG_FILE" 2>&1
# Set up the stable repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update apt and install Docker
apt update -y >> "$LOG_FILE" 2>&1
apt install -y docker-ce docker-ce-cli containerd.io >> "$LOG_FILE" 2>&1
# Install Docker Compose
log "Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose >> "$LOG_FILE" 2>&1
chmod +x /usr/local/bin/docker-compose >> "$LOG_FILE" 2>&1
ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose >> "$LOG_FILE" 2>&1
else
log "Docker already installed: $(docker --version)"
log "Docker Compose already installed: $(docker-compose --version)"
fi
# Install Node.js 20.x
if ! command_exists node || [ $(node -v | cut -d. -f1 | tr -d 'v') -lt 20 ]; then
@ -118,23 +157,42 @@ if [ ! -d "/srv/myp-env" ]; then
fi
if [ ! -f "/srv/myp-env/github.env" ]; then
log "Creating GitHub OAuth credentials template..."
log "Creating GitHub OAuth credentials file with static backend URL..."
cat > /srv/myp-env/github.env << EOF
# GitHub OAuth Credentials
# Replace these with your actual GitHub OAuth app credentials
AUTH_GITHUB_ID=your_github_client_id
AUTH_GITHUB_SECRET=your_github_client_secret
AUTH_SECRET=generate_a_secure_random_string
AUTH_SECRET=$(openssl rand -hex 32)
AUTH_TRUST_HOST=true
NEXT_PUBLIC_BACKEND_URL=http://backend:5000
NEXT_PUBLIC_BACKEND_URL=http://192.168.0.105:5000
# Add additional environment variables as needed
EOF
log "ATTENTION: GitHub OAuth credentials file created with placeholder values"
log "ATTENTION: GitHub OAuth credentials file created with generated AUTH_SECRET"
log " Backend URL set to http://192.168.0.105:5000"
log " Please edit /srv/myp-env/github.env with your actual GitHub OAuth app credentials"
fi
# Create a copy of the environment file in the git repository
log "Creating a copy of the environment file for version control..."
if [ ! -f "$SCRIPT_DIR/.env.example" ]; then
cat > "$SCRIPT_DIR/.env.example" << EOF
# GitHub OAuth Credentials Example
# This is a template for the required environment variables
AUTH_GITHUB_ID=your_github_client_id
AUTH_GITHUB_SECRET=your_github_client_secret
AUTH_SECRET=random_string_generated_during_installation
AUTH_TRUST_HOST=true
NEXT_PUBLIC_BACKEND_URL=http://192.168.0.105:5000
# Add additional environment variables as needed
EOF
log "Environment example file created at $SCRIPT_DIR/.env.example"
fi
# Create database directory if it doesn't exist
log "Setting up database directory..."
mkdir -p /srv/MYP-DB
@ -148,7 +206,7 @@ if [ "$production_mode" = "y" ] || [ "$production_mode" = "Y" ]; then
# Create docker-compose file if it doesn't exist
if [ ! -f "$SCRIPT_DIR/docker/compose.yml" ]; then
log "Creating docker-compose.yml file..."
log "Creating docker-compose.yml file with network configuration..."
cat > "$SCRIPT_DIR/docker/compose.yml" << EOF
version: '3.8'
@ -164,6 +222,7 @@ services:
- /srv/MYP-DB:/app/.next/cache/drizzle
networks:
- myp-network
- backend-network # Network for communicating with backend
caddy:
image: caddy:2.8
@ -183,12 +242,18 @@ services:
networks:
myp-network:
driver: bridge
backend-network: # Network for connecting to the backend at 192.168.0.105
driver: bridge
ipam:
config:
- subnet: 192.168.0.0/24
gateway: 192.168.0.1
volumes:
caddy_data:
caddy_config:
EOF
log "docker-compose.yml created"
log "docker-compose.yml created with backend network configuration"
fi
# Build Docker image
@ -230,20 +295,21 @@ else
# Create .env.local file for development
if [ ! -f "$SCRIPT_DIR/.env.local" ]; then
log "Creating development environment file..."
log "Creating development environment file with static backend URL..."
cat > "$SCRIPT_DIR/.env.local" << EOF
# Development Environment Variables
# GitHub OAuth
AUTH_GITHUB_ID=your_github_client_id
AUTH_GITHUB_SECRET=your_github_client_secret
AUTH_SECRET=generate_a_secure_random_string
AUTH_SECRET=$(openssl rand -hex 32)
AUTH_TRUST_HOST=true
# Backend URL
NEXT_PUBLIC_BACKEND_URL=http://localhost:5000
# Backend URL - Static IP for backend
NEXT_PUBLIC_BACKEND_URL=http://192.168.0.105:5000
EOF
log "ATTENTION: Development environment file created with placeholder values"
log "ATTENTION: Development environment file created with generated AUTH_SECRET"
log " Backend URL set to http://192.168.0.105:5000"
log " Please edit $SCRIPT_DIR/.env.local with your actual GitHub OAuth credentials"
fi
@ -283,4 +349,24 @@ EOF
fi
log "For issues, check the log file at: $LOG_FILE"
log "Done!"
# Add helpful commands for post-installation management
log "===== Post-Installation Information ====="
log "Here are some helpful commands for managing your installation:"
log ""
log "System management:"
log " - Check system status: htop, free -h, df -h"
log " - Network status: ip a, netstat -tulpn, ss -tulpn"
log " - View logs: tail -f /var/log/syslog, journalctl -f"
log ""
log "Docker management:"
log " - List containers: docker ps -a"
log " - Container logs: docker logs <container_id>"
log " - Stop containers: docker-compose -f $SCRIPT_DIR/docker/compose.yml down"
log " - Start containers: docker-compose -f $SCRIPT_DIR/docker/compose.yml up -d"
log " - Restart containers: docker-compose -f $SCRIPT_DIR/docker/compose.yml restart"
log ""
log "Backend connection:"
log " - Test backend connection: curl -I http://192.168.0.105:5000/api/test"
log " - Check backend accessibility: ping 192.168.0.105"
log ""
log "Installation Complete! 🎉"