Add a Gotea Pages prototype: a pages branch is checked out with got, built with the vendored bb, swapped atomically into a pages root, and served only on a separate host from an allowlist. A post-receive hook installer wires the flow through Gitea delegate hooks. The CGI pages mode isolates the host and contains paths with realpath. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
63 lines
1.7 KiB
Bash
Executable File
63 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Install the pages post-receive hook in a bare repository.
|
|
#
|
|
# Usage: install-hook.sh <bare-repo> <pages-root> <allow-file> [bb] [branch]
|
|
set -eu
|
|
|
|
die() {
|
|
echo "gotea-pages: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
repo=${1:-}
|
|
root=${2:-}
|
|
allow=${3:-}
|
|
bb=${4:-}
|
|
branch=${5:-pages}
|
|
[ -n "$repo" ] && [ -n "$root" ] && [ -n "$allow" ] ||
|
|
die "usage: install-hook.sh <bare-repo> <pages-root> <allow-file> [bb] [branch]"
|
|
|
|
repo=$(CDPATH= cd -- "$repo" && pwd) || die "repository not found: $repo"
|
|
[ -f "$repo/HEAD" ] && [ -d "$repo/objects" ] ||
|
|
die "not a bare repository: $repo"
|
|
|
|
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
[ -n "$bb" ] || bb="$here/../../third_party/bb/bb"
|
|
bb=$(CDPATH= cd -- "$(dirname -- "$bb")" && pwd)/$(basename -- "$bb")
|
|
[ -x "$bb" ] || die "bb binary not executable: $bb (run make bb)"
|
|
|
|
case "$root" in
|
|
*\'*) die "paths containing a single quote are not supported" ;;
|
|
esac
|
|
case "$allow" in
|
|
*\'*) die "paths containing a single quote are not supported" ;;
|
|
esac
|
|
case "$repo" in
|
|
*\'*) die "paths containing a single quote are not supported" ;;
|
|
esac
|
|
|
|
base=$(basename "$repo")
|
|
base=${base%.git}
|
|
owner=$(basename "$(dirname "$repo")")
|
|
name="$owner/$base"
|
|
|
|
mkdir -p "$repo/hooks/post-receive.d"
|
|
cp "$here/post-receive.sh" "$repo/hooks/post-receive.d/gotea-pages"
|
|
chmod 0755 "$repo/hooks/post-receive.d/gotea-pages"
|
|
cat > "$repo/hooks/gotea-pages.env" <<EOF
|
|
GOTEA_PAGES_ROOT='$root'
|
|
GOTEA_PAGES_PUBLISH='$here/publish.sh'
|
|
GOTEA_BB='$bb'
|
|
GOTEA_PAGES_BRANCH='$branch'
|
|
EOF
|
|
chmod 0644 "$repo/hooks/gotea-pages.env"
|
|
|
|
mkdir -p "$(dirname "$allow")"
|
|
if ! grep -qxF "$name" "$allow" 2>/dev/null; then
|
|
echo "$name" >> "$allow"
|
|
fi
|
|
|
|
echo "installed pages hook for $name"
|
|
echo "serve with:"
|
|
echo " GOTEA_PAGES_HOST=<pages-host> GOTEA_PAGES_ROOT='$root' GOTEA_PAGES_ALLOW='$allow'"
|