diff --git a/admin/src/pages/SettingsPage.tsx b/admin/src/pages/SettingsPage.tsx index 5be80ab2..0e40eb56 100644 --- a/admin/src/pages/SettingsPage.tsx +++ b/admin/src/pages/SettingsPage.tsx @@ -1216,7 +1216,7 @@ function SystemUpgradeTab() { reinstall manually: - {`cd ~/changemaker.lite && sudo cp scripts/systemd/changemaker-upgrade.* /etc/systemd/system/ && sudo systemctl daemon-reload && sudo systemctl enable --now changemaker-upgrade.path`} + {`cd ~/changemaker.lite && sudo ./scripts/systemd/install.sh`} diff --git a/config.sh b/config.sh index 6269e95b..6d7318a9 100755 --- a/config.sh +++ b/config.sh @@ -1049,8 +1049,7 @@ install_upgrade_watcher() { else warn "Failed to install systemd units (sudo may have failed)" warn "Install manually later:" - echo -e " ${CYAN}sudo cp scripts/systemd/changemaker-upgrade.* /etc/systemd/system/${NC}" - echo -e " ${CYAN}sudo systemctl daemon-reload && sudo systemctl enable --now changemaker-upgrade.path${NC}" + echo -e " ${CYAN}cd ~/changemaker.lite && sudo ./scripts/systemd/install.sh${NC}" UPGRADE_WATCHER="manual" fi diff --git a/reset-site.sh b/reset-site.sh index cbc183b5..a9486348 100755 --- a/reset-site.sh +++ b/reset-site.sh @@ -46,7 +46,7 @@ for item in "$DOCS_DIR"/*/; do [ ! -d "$item" ] && continue dirname="$(basename "$item")" case "$dirname" in - hooks|assets|javascripts|overrides|stylesheets|blog) ;; + hooks|assets|javascripts|overrides|stylesheets|blog|comments|partials) ;; *) LOST_DIRS+=("$dirname") ;; esac done @@ -84,7 +84,7 @@ mkdir -p "$TEMP_DIR" # Backup custom directories if they exist echo "📦 Preserving custom directories..." -for dir in hooks assets javascripts overrides stylesheets blog; do +for dir in hooks assets javascripts overrides stylesheets blog comments partials; do if [ -d "$DOCS_DIR/$dir" ]; then echo " - Preserving $dir/" cp -r "$DOCS_DIR/$dir" "$TEMP_DIR/" @@ -195,7 +195,7 @@ EOF # Restore custom directories echo "♻️ Restoring custom directories..." -for dir in hooks assets javascripts overrides stylesheets blog; do +for dir in hooks assets javascripts overrides stylesheets blog comments partials; do if [ -d "$TEMP_DIR/$dir" ]; then echo " - Restoring $dir/" cp -r "$TEMP_DIR/$dir" "$DOCS_DIR/" @@ -205,7 +205,10 @@ for dir in hooks assets javascripts overrides stylesheets blog; do fi done -# Create simplified home.html +# Create simplified home.html (only if not restored from backup) +if [ -f "$DOCS_DIR/overrides/home.html" ]; then + echo "🏠 Existing home.html preserved (skipping template creation)" +else echo "🏠 Creating simplified home template..." cat > "$DOCS_DIR/overrides/home.html" << 'EOF' {% extends "main.html" %} @@ -261,7 +264,12 @@ cat > "$DOCS_DIR/overrides/home.html" << 'EOF' {% endblock %} EOF -# Create simplified home.css +fi + +# Create simplified home.css (only if not restored from backup) +if [ -f "$DOCS_DIR/stylesheets/home.css" ]; then + echo "🎨 Existing home.css preserved (skipping template creation)" +else echo "🎨 Creating simplified home styles..." cat > "$DOCS_DIR/stylesheets/home.css" << 'EOF' /* Simple home page styles */ @@ -393,10 +401,20 @@ cat > "$DOCS_DIR/stylesheets/home.css" << 'EOF' } EOF +fi + # Update mkdocs.yml - remove nav section echo "📋 Updating mkdocs.yml (removing nav)..." -# Use sed to remove nav section (everything from "nav:" to the next top-level key) -sed -i '/^nav:/,/^[a-zA-Z]/{ /^nav:/d; /^[a-zA-Z]/!d; }' "$MKDOCS_DIR/mkdocs.yml" +# Use Python to safely remove the nav block without eating adjacent sections +python3 -c " +import re, sys +with open(sys.argv[1], 'r') as f: + content = f.read() +# Remove 'nav:' line and all following indented lines (the entire nav block) +content = re.sub(r'^nav:[ \t]*\n(?:[ \t]+.*\n)*', '', content, flags=re.MULTILINE) +with open(sys.argv[1], 'w') as f: + f.write(content) +" "$MKDOCS_DIR/mkdocs.yml" # Also ensure the logo path is correct if [ -f "$DOCS_DIR/assets/logo.png" ]; then @@ -427,3 +445,5 @@ echo " - javascripts/" echo " - overrides/" echo " - stylesheets/" echo " - blog/" +echo " - comments/" +echo " - partials/" diff --git a/scripts/systemd/install.sh b/scripts/systemd/install.sh new file mode 100755 index 00000000..15432bf8 --- /dev/null +++ b/scripts/systemd/install.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# ============================================================================= +# Install Changemaker Lite systemd units +# Substitutes __PROJECT_DIR__ and __USER__ placeholders with actual values. +# Usage: sudo ./scripts/systemd/install.sh +# ============================================================================= +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")" +INSTALL_USER="${SUDO_USER:-$(whoami)}" + +if [[ $EUID -ne 0 ]]; then + echo "ERROR: Must run as root (use sudo)." >&2 + exit 1 +fi + +echo "Installing systemd units..." +echo " Project dir: ${PROJECT_DIR}" +echo " User: ${INSTALL_USER}" + +for unit in "${SCRIPT_DIR}"/changemaker-upgrade.*; do + filename="$(basename "$unit")" + sed \ + -e "s|__PROJECT_DIR__|${PROJECT_DIR}|g" \ + -e "s|__USER__|${INSTALL_USER}|g" \ + "$unit" > "/etc/systemd/system/${filename}" + echo " Installed ${filename}" +done + +systemctl daemon-reload +systemctl enable --now changemaker-upgrade.path + +echo "Done. Status:" +systemctl status changemaker-upgrade.path --no-pager