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:
parent
12345f9816
commit
ef11f94e76
@ -1216,7 +1216,7 @@ function SystemUpgradeTab() {
|
|||||||
reinstall manually:
|
reinstall manually:
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Paragraph code copyable style={{ fontSize: 12, marginBottom: 0 }}>
|
<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>
|
</Paragraph>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|||||||
@ -1049,8 +1049,7 @@ install_upgrade_watcher() {
|
|||||||
else
|
else
|
||||||
warn "Failed to install systemd units (sudo may have failed)"
|
warn "Failed to install systemd units (sudo may have failed)"
|
||||||
warn "Install manually later:"
|
warn "Install manually later:"
|
||||||
echo -e " ${CYAN}sudo cp scripts/systemd/changemaker-upgrade.* /etc/systemd/system/${NC}"
|
echo -e " ${CYAN}cd ~/changemaker.lite && sudo ./scripts/systemd/install.sh${NC}"
|
||||||
echo -e " ${CYAN}sudo systemctl daemon-reload && sudo systemctl enable --now changemaker-upgrade.path${NC}"
|
|
||||||
UPGRADE_WATCHER="manual"
|
UPGRADE_WATCHER="manual"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ for item in "$DOCS_DIR"/*/; do
|
|||||||
[ ! -d "$item" ] && continue
|
[ ! -d "$item" ] && continue
|
||||||
dirname="$(basename "$item")"
|
dirname="$(basename "$item")"
|
||||||
case "$dirname" in
|
case "$dirname" in
|
||||||
hooks|assets|javascripts|overrides|stylesheets|blog) ;;
|
hooks|assets|javascripts|overrides|stylesheets|blog|comments|partials) ;;
|
||||||
*) LOST_DIRS+=("$dirname") ;;
|
*) LOST_DIRS+=("$dirname") ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -84,7 +84,7 @@ mkdir -p "$TEMP_DIR"
|
|||||||
|
|
||||||
# Backup custom directories if they exist
|
# Backup custom directories if they exist
|
||||||
echo "📦 Preserving custom directories..."
|
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
|
if [ -d "$DOCS_DIR/$dir" ]; then
|
||||||
echo " - Preserving $dir/"
|
echo " - Preserving $dir/"
|
||||||
cp -r "$DOCS_DIR/$dir" "$TEMP_DIR/"
|
cp -r "$DOCS_DIR/$dir" "$TEMP_DIR/"
|
||||||
@ -195,7 +195,7 @@ EOF
|
|||||||
|
|
||||||
# Restore custom directories
|
# Restore custom directories
|
||||||
echo "♻️ Restoring 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
|
if [ -d "$TEMP_DIR/$dir" ]; then
|
||||||
echo " - Restoring $dir/"
|
echo " - Restoring $dir/"
|
||||||
cp -r "$TEMP_DIR/$dir" "$DOCS_DIR/"
|
cp -r "$TEMP_DIR/$dir" "$DOCS_DIR/"
|
||||||
@ -205,7 +205,10 @@ for dir in hooks assets javascripts overrides stylesheets blog; do
|
|||||||
fi
|
fi
|
||||||
done
|
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..."
|
echo "🏠 Creating simplified home template..."
|
||||||
cat > "$DOCS_DIR/overrides/home.html" << 'EOF'
|
cat > "$DOCS_DIR/overrides/home.html" << 'EOF'
|
||||||
{% extends "main.html" %}
|
{% extends "main.html" %}
|
||||||
@ -261,7 +264,12 @@ cat > "$DOCS_DIR/overrides/home.html" << 'EOF'
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
EOF
|
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..."
|
echo "🎨 Creating simplified home styles..."
|
||||||
cat > "$DOCS_DIR/stylesheets/home.css" << 'EOF'
|
cat > "$DOCS_DIR/stylesheets/home.css" << 'EOF'
|
||||||
/* Simple home page styles */
|
/* Simple home page styles */
|
||||||
@ -393,10 +401,20 @@ cat > "$DOCS_DIR/stylesheets/home.css" << 'EOF'
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Update mkdocs.yml - remove nav section
|
# Update mkdocs.yml - remove nav section
|
||||||
echo "📋 Updating mkdocs.yml (removing nav)..."
|
echo "📋 Updating mkdocs.yml (removing nav)..."
|
||||||
# Use sed to remove nav section (everything from "nav:" to the next top-level key)
|
# Use Python to safely remove the nav block without eating adjacent sections
|
||||||
sed -i '/^nav:/,/^[a-zA-Z]/{ /^nav:/d; /^[a-zA-Z]/!d; }' "$MKDOCS_DIR/mkdocs.yml"
|
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
|
# Also ensure the logo path is correct
|
||||||
if [ -f "$DOCS_DIR/assets/logo.png" ]; then
|
if [ -f "$DOCS_DIR/assets/logo.png" ]; then
|
||||||
@ -427,3 +445,5 @@ echo " - javascripts/"
|
|||||||
echo " - overrides/"
|
echo " - overrides/"
|
||||||
echo " - stylesheets/"
|
echo " - stylesheets/"
|
||||||
echo " - blog/"
|
echo " - blog/"
|
||||||
|
echo " - comments/"
|
||||||
|
echo " - partials/"
|
||||||
|
|||||||
35
scripts/systemd/install.sh
Executable file
35
scripts/systemd/install.sh
Executable 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
|
||||||
Loading…
x
Reference in New Issue
Block a user