#!/bin/bash # === Require root if installing on local system === run_locally="" read -rp "Are you running this script on the actual server that will host NGINX? [y/N]: " answer if [[ "$answer" =~ ^[Yy]$ ]]; then run_locally=true if [ "$EUID" -ne 0 ]; then echo "❌ This script must be run as root when deploying directly on the target system." echo "ℹ️ Try again with: sudo $0" exit 1 fi else run_locally=false echo "ℹ️ Generating config for remote deployment – it will be saved to the current directory." fi # === Prompt or take args === SERVER_NAME="${1:-}" SSL_CERT_PATH="${2:-}" SSL_KEY_PATH="${3:-}" NODE_PORT="${4:-12391}" # Prompt if not passed if [ -z "$SERVER_NAME" ]; then read -rp "Enter server_name (e.g. ext-node.qortal.link): " SERVER_NAME fi if [ -z "$SSL_CERT_PATH" ]; then read -rp "Enter full path to SSL certificate: " SSL_CERT_PATH fi if [ -z "$SSL_KEY_PATH" ]; then read -rp "Enter full path to SSL certificate key: " SSL_KEY_PATH fi if [ -z "$NODE_PORT" ]; then read -rp "Enter Qortal node port [default: 12391]: " NODE_PORT NODE_PORT="${NODE_PORT:-12391}" fi # === Output destination === if [[ "$run_locally" == true ]]; then NGINX_CONF_DIR="/etc/nginx/sites-available" NGINX_ENABLED_DIR="/etc/nginx/sites-enabled" CONF_PATH="${NGINX_CONF_DIR}/${SERVER_NAME}" else SCRIPT_DIR="$(pwd)" CONF_PATH="${SCRIPT_DIR}/${SERVER_NAME}.nginx.conf" fi # === Template === cat > "$CONF_PATH" <