#!/bin/bash # Ubuntu Server Setup Script for Church Song Lyric System # This script automates the initial setup on a fresh Ubuntu server set -e # Exit on error echo "==========================================" echo "Church Song Lyric - Ubuntu Setup" echo "==========================================" echo "" # Color codes for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check if running as root if [ "$EUID" -eq 0 ]; then echo -e "${RED}Please do not run as root. Run as regular user with sudo privileges.${NC}" exit 1 fi # Get user input echo -e "${YELLOW}Please provide the following information:${NC}" read -p "Enter your domain name (or press Enter to skip): " DOMAIN_NAME read -p "Enter the installation directory [/var/www/church-songlyric]: " INSTALL_DIR INSTALL_DIR=${INSTALL_DIR:-/var/www/church-songlyric} echo "" echo -e "${GREEN}Installation directory: $INSTALL_DIR${NC}" if [ ! -z "$DOMAIN_NAME" ]; then echo -e "${GREEN}Domain name: $DOMAIN_NAME${NC}" else echo -e "${YELLOW}No domain name provided. Will use IP address.${NC}" fi echo "" read -p "Continue with installation? (y/n): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi echo "" echo "==========================================" echo "Step 1: Updating system packages..." echo "==========================================" sudo apt update sudo apt upgrade -y echo "" echo "==========================================" echo "Step 2: Installing required packages..." echo "==========================================" sudo apt install -y \ python3 \ python3-pip \ python3-venv \ nodejs \ npm \ nginx \ git \ curl \ wget \ ufw \ tesseract-ocr \ poppler-utils \ libtesseract-dev \ libleptonica-dev \ software-properties-common # Check Node.js version NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) if [ "$NODE_VERSION" -lt 16 ]; then echo -e "${YELLOW}Node.js version is too old. Installing Node.js 18 LTS...${NC}" curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt install -y nodejs fi echo "" echo "==========================================" echo "Step 3: Configuring firewall..." echo "==========================================" sudo ufw --force enable sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' sudo ufw status echo "" echo "==========================================" echo "Step 4: Creating project directory..." echo "==========================================" sudo mkdir -p "$INSTALL_DIR" sudo chown $USER:www-data "$INSTALL_DIR" sudo chmod 755 "$INSTALL_DIR" echo "" echo "==========================================" echo "Step 5: Setting up Python environment..." echo "==========================================" cd "$INSTALL_DIR" # Check if project files exist if [ ! -d "backend" ]; then echo -e "${YELLOW}Backend directory not found.${NC}" echo -e "${YELLOW}Please transfer your project files to $INSTALL_DIR${NC}" echo -e "${YELLOW}You can use: scp -r /path/to/project/* user@server:$INSTALL_DIR/${NC}" read -p "Press Enter when files are transferred..." fi if [ -d "backend" ]; then cd backend # Create virtual environment echo "Creating Python virtual environment..." python3 -m venv venv # Activate and install dependencies echo "Installing Python dependencies..." source venv/bin/activate pip install --upgrade pip if [ -f "requirements.txt" ]; then pip install -r requirements.txt else echo -e "${YELLOW}requirements.txt not found. Skipping Python package installation.${NC}" fi deactivate cd .. else echo -e "${RED}Backend directory still not found. Skipping Python setup.${NC}" fi echo "" echo "==========================================" echo "Step 6: Setting up Node.js environment..." echo "==========================================" if [ -d "frontend" ]; then cd frontend echo "Installing Node.js dependencies..." npm install echo "Building production frontend..." npm run build cd .. else echo -e "${YELLOW}Frontend directory not found. Skipping frontend setup.${NC}" fi echo "" echo "==========================================" echo "Step 7: Creating systemd service..." echo "==========================================" sudo tee /etc/systemd/system/church-songlyric-backend.service > /dev/null < /dev/null <