Add systemd install script and improve reset-site.sh resilience

- Add scripts/systemd/install.sh to handle placeholder substitution
  (__PROJECT_DIR__, __USER__) and systemd unit installation in one command
- Simplify manual install instructions in SettingsPage and config.sh to
  reference the new install script
- Preserve existing home.html and home.css in reset-site.sh instead of
  overwriting with templates
- Add comments/ and partials/ to preserved directories list
- Fix nav removal in mkdocs.yml using Python regex instead of fragile sed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
admin 2026-03-09 01:03:50 -06:00
parent 12345f9816
commit ef11f94e76
4 changed files with 64 additions and 10 deletions

View File

@ -1216,7 +1216,7 @@ function SystemUpgradeTab() {
reinstall manually:
</Paragraph>
<Paragraph code copyable style={{ fontSize: 12, marginBottom: 0 }}>
{`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`}
</Paragraph>
</Card>

View File

@ -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

View File

@ -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/"

35
scripts/systemd/install.sh Executable file
View File

@ -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