#!/usr/bin/env bash # Q002-prep.sh — hermes baseline: nginx config syntax error # # Prepares sc-web-server for Q002 "Syntax Error in Aisle Four". # Introduces a deliberate nginx config syntax error that breaks the service. # # What this does: # - Installs nginx if not present # - Writes a broken /etc/nginx/sites-enabled/axiomworks.conf # (missing semicolon on the server_name line) # - Stops nginx so the player finds it down # - Adds error log evidence # # Idempotent: safe to run multiple times. set -euo pipefail export LIBVIRT_DEFAULT_URI="${LIBVIRT_DEFAULT_URI:-qemu:///system}" DOMAIN="${1:-sc-web-server}" DRY_RUN=false [[ "${2:-}" == "--dry-run" ]] && DRY_RUN=true get_vm_ip() { local domain="$1" local addr="" addr="$(virsh domifaddr "$domain" --source agent 2>/dev/null | awk '/ipv4/ {print $4}' | cut -d/ -f1 | grep -v '^127\.' | head -n1 || true)" if [ -n "$addr" ]; then printf '%s\n' "$addr" return 0 fi local mac="" mac="$(virsh dumpxml "$domain" 2>/dev/null | sed -n "s/.* /etc/nginx/sites-enabled/axiomworks.conf <<'NGINX_CONF' server { listen 80; server_name axiomworks.internal # <-- MISSING SEMICOLON: this is the bug root /var/www/axiomworks; index index.html; location / { try_files \$uri \$uri/ =404; } } NGINX_CONF" # Disable the default site to make this the only relevant config run_in_vm "rm -f /etc/nginx/sites-enabled/default" # Stop nginx (it fails to start with bad config) run_in_vm "systemctl stop nginx || true" # Populate nginx error log with the kind of evidence a player would find run_in_vm "mkdir -p /var/log/nginx && echo '[emerg] unexpected \";\" in /etc/nginx/sites-enabled/axiomworks.conf:3' >> /var/log/nginx/error.log" # Create the web root (nginx would serve from here if config were valid) run_in_vm "mkdir -p /var/www/axiomworks && echo '

Axiom Works

' > /var/www/axiomworks/index.html" echo "Q002-prep: Done. nginx is stopped with broken config on $DOMAIN."