fix(install): clean stale generated files from site dirs before rebuild

Install script now removes index.html, QR codes, and download bundles
from existing site directories before rebuild-all regenerates them.
Preserves config.json, .onionshare-session, server.pid, and logs.
Also auto-rebuilds on serve if index.html is missing.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.6 committed 2026-03-16 21:46:14 -04:00
1 parent 03b1c51e27
commit 46360ca6ea
2 files changed
+23

No files matched your search

+17
View File
@@ -182,6 +182,23 @@ if [ -d "$HOME/imports" ] && ls "$HOME/imports"/*.json &>/dev/null; then
fi
fi
# Clean generated files from existing site directories so rebuild-all
# regenerates them from the current template. Preserves:
# config.json — site content and settings
# .onionshare-session — Tor domain identity key
# server.pid — running process marker
# onionshare.log — current log (may be in use)
# Everything else is regenerated by build_assets().
if [ -d "$HOME/host" ]; then
for site_dir in "$HOME"/host/*/; do
[ -f "${site_dir}config.json" ] || continue
msg "Cleaning generated files in ${site_dir}..."
rm -f "${site_dir}index.html" 2>/dev/null || true
rm -f "${site_dir}qrcode-content.png" "${site_dir}qrcode-tear-offs.png" 2>/dev/null || true
rm -rf "${site_dir}download" 2>/dev/null || true
done
fi
# --- Helper: build pip flags for this distro ---
pip_flags() {
local flags="--user --upgrade"
+6
View File
@@ -731,6 +731,12 @@ def serve(config_path: str) -> str | None:
if not dir_path.is_dir():
print(f"Directory {dir_path} not found", file=sys.stderr)
sys.exit(1)
# Auto-rebuild if index.html is missing (e.g. after install cleanup)
if not (dir_path / "index.html").exists():
print(f"Rebuilding {folder_name} from current template...")
build_assets(config_path)
logfile = dir_path / "onionshare.log"
# Set environment variables for OnionShare to use the detected Tor ports