#!/bin/bash # Gitea Mirror LXC Container Installer # This is a self-contained script to install Gitea Mirror in an LXC container # Usage: curl -fsSL https://raw.githubusercontent.com/arunavo4/gitea-mirror/main/scripts/gitea-mirror-lxc-installer.sh | bash set -e # Configuration variables - change these as needed INSTALL_DIR="/opt/gitea-mirror" REPO_URL="https://github.com/arunavo4/gitea-mirror.git" SERVICE_USER="gitea-mirror" PORT=4321 # Color codes for better readability RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Print banner echo -e "${BLUE}" echo "╔════════════════════════════════════════════════════════════╗" echo "║ ║" echo "║ Gitea Mirror LXC Container Installer ║" echo "║ ║" echo "╚════════════════════════════════════════════════════════════╝" echo -e "${NC}" # Ensure script is run as root if [ "$(id -u)" -ne 0 ]; then echo -e "${RED}This script must be run as root${NC}" >&2 exit 1 fi echo -e "${GREEN}Starting Gitea Mirror installation...${NC}" # Check if we're in an LXC container if [ -d /proc/vz ] && [ ! -d /proc/bc ]; then echo -e "${YELLOW}Running in an OpenVZ container. Some features may not work.${NC}" elif [ -f /proc/1/environ ] && grep -q container=lxc /proc/1/environ; then echo -e "${GREEN}Running in an LXC container. Good!${NC}" else echo -e "${YELLOW}Not running in a container. This script is designed for LXC containers.${NC}" read -p "Continue anyway? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}Installation aborted.${NC}" exit 1 fi fi # Install dependencies echo -e "${BLUE}Step 1/7: Installing dependencies...${NC}" apt update apt install -y curl git sqlite3 build-essential openssl # Create service user echo -e "${BLUE}Step 2/7: Creating service user...${NC}" if id "$SERVICE_USER" &>/dev/null; then echo -e "${YELLOW}User $SERVICE_USER already exists${NC}" else useradd -m -s /bin/bash "$SERVICE_USER" echo -e "${GREEN}Created user $SERVICE_USER${NC}" fi # Install Bun echo -e "${BLUE}Step 3/7: Installing Bun runtime...${NC}" if command -v bun >/dev/null 2>&1; then echo -e "${YELLOW}Bun is already installed${NC}" bun --version else echo -e "${GREEN}Installing Bun...${NC}" curl -fsSL https://bun.sh/install | bash export BUN_INSTALL=${BUN_INSTALL:-"/root/.bun"} export PATH="$BUN_INSTALL/bin:$PATH" echo -e "${GREEN}Bun installed successfully${NC}" bun --version fi # Clone repository echo -e "${BLUE}Step 4/7: Downloading Gitea Mirror...${NC}" if [ -d "$INSTALL_DIR" ]; then echo -e "${YELLOW}Directory $INSTALL_DIR already exists${NC}" read -p "Update existing installation? (y/n) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then cd "$INSTALL_DIR" git pull echo -e "${GREEN}Repository updated${NC}" else echo -e "${YELLOW}Using existing installation${NC}" fi else echo -e "${GREEN}Cloning repository...${NC}" git clone "$REPO_URL" "$INSTALL_DIR" echo -e "${GREEN}Repository cloned to $INSTALL_DIR${NC}" fi # Set up application echo -e "${BLUE}Step 5/7: Setting up application...${NC}" cd "$INSTALL_DIR" # Create data directory with proper permissions mkdir -p data chown -R "$SERVICE_USER:$SERVICE_USER" data # Install dependencies and build echo -e "${GREEN}Installing dependencies and building application...${NC}" bun install bun run build # Initialize database if it doesn't exist echo -e "${GREEN}Initializing database...${NC}" if [ ! -f "data/gitea-mirror.db" ]; then bun run manage-db init chown "$SERVICE_USER:$SERVICE_USER" data/gitea-mirror.db fi # Generate a random JWT secret if not provided JWT_SECRET=${JWT_SECRET:-$(openssl rand -hex 32)} # Create systemd service echo -e "${BLUE}Step 6/7: Creating systemd service...${NC}" # Store Bun path in a variable for better maintainability BUN_PATH=$(command -v bun) echo -e "${GREEN}Using Bun from: $BUN_PATH${NC}" cat >/etc/systemd/system/gitea-mirror.service <