view hg-web/run.sh @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
parents c5129452493e
children
line wrap: on
line source

#!/usr/bin/env bash
set -Eeuo pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bundle_root="$(dirname "$script_dir")"
repository="${HG_REPOSITORY_PATH:-$bundle_root/repository}"
hg_binary="$bundle_root/third_party/mercurial/runtime/bin/hg"
server="$bundle_root/hg_web_server"
hg_pid=""
server_pid=""

if [[ ! -x "$hg_binary" ]]; then
  echo "Bundled Mercurial is unavailable: $hg_binary" >&2
  exit 1
fi
if [[ ! -x "$server" ]]; then
  echo "hg-web server is unavailable: $server" >&2
  exit 1
fi
if [[ ! -d "$repository/.hg" ]]; then
  echo "Mercurial repository snapshot is unavailable: $repository" >&2
  exit 1
fi

cleanup() {
  trap - EXIT INT TERM
  for pid in "$server_pid" "$hg_pid"; do
    if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
      kill "$pid" 2>/dev/null || true
    fi
  done
  for pid in "$server_pid" "$hg_pid"; do
    if [[ -n "$pid" ]]; then
      wait "$pid" 2>/dev/null || true
    fi
  done
}
trap cleanup EXIT
trap 'exit 130' INT TERM

hg_arguments=(
  --repository "$repository"
  serve
  --address 127.0.0.1
  --port 4444
  --accesslog -
  --errorlog -
)
if [[ "${HG_ALLOW_PUSH:-false}" == "true" ]]; then
  echo "WARNING: Mercurial pushes are enabled; protect /repo in Nginx."
  hg_arguments=(
    --config "web.allow-push=*"
    --config "web.deny-push="
    --config "web.push_ssl=false"
    "${hg_arguments[@]}"
  )
else
  hg_arguments=(
    --config "web.allow-push="
    --config "web.deny-push=*"
    "${hg_arguments[@]}"
  )
fi

export HGRCPATH=
"$hg_binary" "${hg_arguments[@]}" &
hg_pid=$!

(
  cd "$bundle_root"
  exec "$server"
) &
server_pid=$!

echo "hg-web: http://127.0.0.1:6970"
echo "hg serve repository: $repository"

set +e
wait -n "$hg_pid" "$server_pid"
status=$?
set -e
exit "$status"