comparison hg-web/run.sh @ 249:c5129452493e

[deploy] Bundle Mercurial with hg-web Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 04:16:45 -0700
parents
children
comparison
equal deleted inserted replaced
248:b8b6e726964a 249:c5129452493e
1 #!/usr/bin/env bash
2 set -Eeuo pipefail
3
4 script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5 bundle_root="$(dirname "$script_dir")"
6 repository="${HG_REPOSITORY_PATH:-$bundle_root/repository}"
7 hg_binary="$bundle_root/third_party/mercurial/runtime/bin/hg"
8 server="$bundle_root/hg_web_server"
9 hg_pid=""
10 server_pid=""
11
12 if [[ ! -x "$hg_binary" ]]; then
13 echo "Bundled Mercurial is unavailable: $hg_binary" >&2
14 exit 1
15 fi
16 if [[ ! -x "$server" ]]; then
17 echo "hg-web server is unavailable: $server" >&2
18 exit 1
19 fi
20 if [[ ! -d "$repository/.hg" ]]; then
21 echo "Mercurial repository snapshot is unavailable: $repository" >&2
22 exit 1
23 fi
24
25 cleanup() {
26 trap - EXIT INT TERM
27 for pid in "$server_pid" "$hg_pid"; do
28 if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
29 kill "$pid" 2>/dev/null || true
30 fi
31 done
32 for pid in "$server_pid" "$hg_pid"; do
33 if [[ -n "$pid" ]]; then
34 wait "$pid" 2>/dev/null || true
35 fi
36 done
37 }
38 trap cleanup EXIT
39 trap 'exit 130' INT TERM
40
41 hg_arguments=(
42 --repository "$repository"
43 serve
44 --address 127.0.0.1
45 --port 4444
46 --accesslog -
47 --errorlog -
48 )
49 if [[ "${HG_ALLOW_PUSH:-false}" == "true" ]]; then
50 echo "WARNING: Mercurial pushes are enabled; protect /repo in Nginx."
51 hg_arguments=(
52 --config "web.allow-push=*"
53 --config "web.deny-push="
54 --config "web.push_ssl=false"
55 "${hg_arguments[@]}"
56 )
57 else
58 hg_arguments=(
59 --config "web.allow-push="
60 --config "web.deny-push=*"
61 "${hg_arguments[@]}"
62 )
63 fi
64
65 export HGRCPATH=
66 "$hg_binary" "${hg_arguments[@]}" &
67 hg_pid=$!
68
69 (
70 cd "$bundle_root"
71 exec "$server"
72 ) &
73 server_pid=$!
74
75 echo "hg-web: http://127.0.0.1:6970"
76 echo "hg serve repository: $repository"
77
78 set +e
79 wait -n "$hg_pid" "$server_pid"
80 status=$?
81 set -e
82 exit "$status"