-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·60 lines (50 loc) · 1.94 KB
/
Copy pathgenerate.sh
File metadata and controls
executable file
·60 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/bash
set -Eeuo pipefail
# Generates the static HTML archive from dump/ using phpbb-archive's own
# generator (generator/generate.py), creating and reusing a local .venv
# for its dependencies rather than installing them system-wide.
#
# Usage:
# generate.sh
# Set up .venv if needed, then generate output/ from dump/.
#
# generate.sh --dump DIR --output DIR
# Forwarded to `python -m generator.generate`; overrides the
# default dump/ and output/ locations.
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$script_dir"
venv_dir="$script_dir/.venv"
requirements_file="$script_dir/generator/requirements.txt"
dump_dir="$script_dir/dump"
if ! command -v python3 >/dev/null 2>&1; then
echo "ERROR: required command not found: python3" >&2
exit 1
fi
if [[ ! -d "$dump_dir" ]]; then
echo "ERROR: dump directory not found:" >&2
echo " $dump_dir" >&2
echo "See README.md for what to collect into dump/." >&2
exit 1
fi
if [[ -x "$venv_dir/bin/python" ]] && ! "$venv_dir/bin/pip" --version >/dev/null 2>&1; then
# A venv's console-script wrappers (pip, etc.) hardcode an absolute
# shebang path back to the venv itself at creation time, so copying or
# moving the containing folder silently breaks them even though the
# python binary/symlink keeps working. Recreate rather than fail.
echo "Existing virtual environment is broken (likely moved/copied from elsewhere) — recreating: $venv_dir"
rm -rf "$venv_dir"
fi
if [[ ! -x "$venv_dir/bin/python" ]]; then
echo "Creating virtual environment: $venv_dir"
python3 -m venv "$venv_dir"
fi
echo "Installing dependencies from generator/requirements.txt"
"$venv_dir/bin/pip" install --quiet --requirement "$requirements_file"
echo "Generating archive..."
"$venv_dir/bin/python" -m generator.generate \
--dump dump/ \
--output output/ \
"$@"
echo
echo "Done. Open in a browser:"
echo " $script_dir/output/index.html"