#!/bin/bash # Install the eco documentation site as *user* systemd units on this host: # # eco-docs.service serves the current build (python -m http.server) # eco-docs-build.service one rebuild (fetch, sphinx-build, atomic swap) # eco-docs-build.timer runs that rebuild periodically # # Same approach as eco-status-server-install-user-service: no root needed, # runs as the invoking account (whose git credentials fetch the repository). # Both units just call `eco-docs`, so the interactive command and the # service run exactly the same thing. set -euo pipefail SELF_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" LAUNCHER="${ECO_DOCS_LAUNCHER:-$SELF_DIR/eco-docs}" UNIT_DIR="$HOME/.config/systemd/user" ENV_FILE="${ECO_DOCS_ENV:-$HOME/.config/eco-docs.env}" INTERVAL="15min" usage() { cat <&2; usage; exit 2 ;; esac done [ -x "$LAUNCHER" ] || { echo "launcher not executable: $LAUNCHER" >&2; exit 1; } mkdir -p "$UNIT_DIR" "$(dirname "$ENV_FILE")" if [ ! -e "$ENV_FILE" ]; then { echo "# Environment for the eco docs site (systemd EnvironmentFile" echo "# syntax: KEY=value, no export, no shell expansion). Edit to taste." "$LAUNCHER" config } > "$ENV_FILE" echo "wrote template $ENV_FILE - check it before starting the services" else echo "keeping existing $ENV_FILE" fi for unit in eco-docs.service eco-docs-build.service eco-docs-build.timer; do if [ -e "$UNIT_DIR/$unit" ] && [ "$FORCE" -eq 0 ]; then echo "$UNIT_DIR/$unit already exists; re-run with --force to overwrite" >&2 exit 1 fi done cat > "$UNIT_DIR/eco-docs.service" < "$UNIT_DIR/eco-docs-build.service" < "$UNIT_DIR/eco-docs-build.timer" <