#!/bin/bash set -euo pipefail # QR Server Installation Script # Run as root or with sudo BINARY_NAME="server18004" INSTALL_DIR="/usr/local/bin" CONFIG_DIR="/etc/server18004" SERVICE_USER="qrserver" SERVICE_FILE="/etc/systemd/system/server18004.service" echo "=== server18004 Installer ===" # 1. Build release binary echo "[1/5] Building release binary..." if command -v cargo &>/dev/null; then cargo build --release echo " ✓ Built target/release/${BINARY_NAME}" elif [ -f "target/release/${BINARY_NAME}" ]; then echo " ✓ Found existing binary in target/release/${BINARY_NAME}, skipping build" else echo " ✗ Error: 'cargo' not found and no existing binary in target/release/" echo " Please run 'cargo build --release' as your normal user first," echo " then run this script with sudo." exit 1 fi # 2. Create service user echo "[2/5] Creating service user..." if ! id -u "${SERVICE_USER}" &>/dev/null; then useradd --system --no-create-home --shell /usr/sbin/nologin "${SERVICE_USER}" echo " ✓ Created user ${SERVICE_USER}" else echo " ✓ User ${SERVICE_USER} already exists" fi # 3. Install binary echo "[3/5] Installing binary..." cp "target/release/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}" chmod 755 "${INSTALL_DIR}/${BINARY_NAME}" echo " ✓ Installed to ${INSTALL_DIR}/${BINARY_NAME}" # 4. Install config files echo "[4/5] Installing configuration..." mkdir -p "${CONFIG_DIR}" if [ ! -f "${CONFIG_DIR}/server.conf" ]; then cp config/server.conf.example "${CONFIG_DIR}/server.conf" echo " ✓ Installed server.conf" else echo " ⚠ server.conf already exists, skipping (see config/server.conf.example)" fi if [ ! -f "${CONFIG_DIR}/domains.conf" ]; then cp config/domains.conf.example "${CONFIG_DIR}/domains.conf" echo " ✓ Installed domains.conf" else echo " ⚠ domains.conf already exists, skipping (see config/domains.conf.example)" fi chown -R "${SERVICE_USER}:${SERVICE_USER}" "${CONFIG_DIR}" echo " ✓ Set ownership to ${SERVICE_USER}" # 5. Install systemd service echo "[5/5] Installing systemd service..." cp config/server18004.service "${SERVICE_FILE}" systemctl daemon-reload echo " ✓ Service installed" echo "" echo "=== Installation Complete ===" echo "" echo "Next steps:" echo " 1. Edit config: sudo nano ${CONFIG_DIR}/server.conf" echo " 2. Edit domains: sudo nano ${CONFIG_DIR}/domains.conf" echo " 3. Start service: sudo systemctl start server18004" echo " 4. Enable on boot: sudo systemctl enable server18004" echo " 5. Check status: sudo systemctl status server18004" echo " 6. View logs: sudo journalctl -u server18004 -f"