officer-setup: the repository URL is https

https://gitea.officer.dev/officerdev/platform.git, not the ssh form.

The reachability check is now one test for either scheme: `git ls-remote` with
both prompts disabled. That is the real question — not whether the host answers
but whether this account can read the repository — and neither prompt fails
cleanly on its own. Over https git asks for a username nobody is there to type;
over ssh it asks for a password or stops on host-key verification. With
GIT_TERMINAL_PROMPT=0 and BatchMode both off, an unreadable repository is an
immediate non-zero rather than a hang.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-12 21:52:53 +00:00
co-authored by Claude Opus 5
parent a5a8cd4e9c
commit ee21fa16f0
2 changed files with 24 additions and 32 deletions
+12 -15
View File
@@ -211,19 +211,16 @@ if ! skip; then
CLONE_URL="$OFFICER_REPO" CLONE_URL="$OFFICER_REPO"
# Checked before cloning. An ssh URL with no usable key does not fail # Checked before cloning, for either scheme — see repo_reachable.
# cleanly: git prompts for a password nobody is there to type, or stops on if ! repo_reachable "$CLONE_URL"; then
# host-key verification.
if [[ "$CLONE_URL" == ssh://* ]] && ! repo_ssh_ok "$CLONE_URL"; then
echo "" echo ""
warn "${USERNAME} cannot authenticate to $(repo_ssh_host "$CLONE_URL") over ssh" warn "${USERNAME} cannot read ${CLONE_URL}"
echo " Either add that account's public key to the git server, or clone" echo " Either the host is not answering yet, or the repository is not"
echo " over https instead — which works without a key if the repository" echo " readable without credentials."
echo " is readable anonymously."
echo "" echo ""
echo " [1] https — $(repo_https_url "$CLONE_URL")" echo " [1] try it anyway"
echo " [2] ssh anyway — will fail if the key is genuinely missing" echo " [2] use a different URL"
echo " [3] stop here, and add the key first" echo " [3] stop here"
echo "" echo ""
REPO_PICK="" REPO_PICK=""
while [[ -z "$REPO_PICK" ]]; do while [[ -z "$REPO_PICK" ]]; do
@@ -232,12 +229,12 @@ if ! skip; then
fail "No answer." fail "No answer."
fi fi
case "${REPO_CHOICE:-1}" in case "${REPO_CHOICE:-1}" in
1) 1) REPO_PICK=go ;;
CLONE_URL="$(repo_https_url "$CLONE_URL")" 2)
ask_required CLONE_URL "Repository URL" "$CLONE_URL"
REPO_PICK=go REPO_PICK=go
;; ;;
2) REPO_PICK=go ;; 3) fail "Stopped. Nothing below can run without the repository." ;;
3) fail "Stopped. Add ${USERNAME}'s public key to the git server and run this again." ;;
*) warn "Pick 1, 2 or 3." ;; *) warn "Pick 1, 2 or 3." ;;
esac esac
done done
+12 -17
View File
@@ -14,7 +14,7 @@
[[ -n "${OFFICER_SETUP_REPO_LOADED:-}" ]] && return 0 [[ -n "${OFFICER_SETUP_REPO_LOADED:-}" ]] && return 0
OFFICER_SETUP_REPO_LOADED=1 OFFICER_SETUP_REPO_LOADED=1
OFFICER_REPO="${OFFICER_REPO:-ssh://git@gitea.officer.dev:2222/officerdev/platform.git}" OFFICER_REPO="${OFFICER_REPO:-https://gitea.officer.dev/officerdev/platform.git}"
platform_dir() { echo "${OFFICER_ROOT}/platform"; } platform_dir() { echo "${OFFICER_ROOT}/platform"; }
@@ -30,21 +30,16 @@ repo_ssh_port() { sed -nE 's|^ssh://[^@]*@[^:]+:([0-9]+)/.*|\1|p' <<<"$1"; }
# Can this account actually clone it? # Can this account actually clone it?
# #
# Checked before the clone rather than after, because an ssh URL with no usable # `git ls-remote` is the real question — not "does the host answer" but "can this
# key does not fail cleanly — git either prompts for a password nobody is there # account read this repository". Both prompts are disabled, because neither fails
# to type, or hangs on host-key verification. BatchMode turns both into an # cleanly on its own: over https git asks for a username nobody is there to type,
# immediate non-zero. # and over ssh it asks for a password or stops on host-key verification. With
# # both off, an unreachable or unreadable repository is an immediate non-zero
# Gitea answers a successful auth with a message and exit 1, so the test is # instead of a hang.
# whether the SERVER recognised us, not the exit code. repo_reachable() {
repo_ssh_ok() { as_owner "GIT_TERMINAL_PROMPT=0 \
local url="$1" host port out GIT_SSH_COMMAND='ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=8' \
host="$(repo_ssh_host "$url")" timeout 20 git ls-remote '$1' >/dev/null 2>&1" /
port="$(repo_ssh_port "$url")"
[[ -n "$host" ]] || return 1
out="$(as_owner "ssh -T -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=8 ${port:+-p $port} git@${host} 2>&1" || true)"
grep -qiE "authenticated|successfully|welcome|does not provide shell access" <<<"$out"
} }
# The https form of the same repository, for a machine with no key. # The https form of the same repository, for a machine with no key.
@@ -56,7 +51,7 @@ clone_repo() {
local url="$1" dest local url="$1" dest
dest="$(platform_dir)" dest="$(platform_dir)"
install -d -m 0755 -o "$USERNAME" -g "$(user_group)" "$OFFICER_ROOT" install -d -m 0755 -o "$USERNAME" -g "$(user_group)" "$OFFICER_ROOT"
as_owner "git clone '${url}' '${dest}'" / as_owner "GIT_TERMINAL_PROMPT=0 git clone '${url}' '${dest}'" /
} }
pull_repo() { as_owner "git -C '$(platform_dir)' pull --ff-only" /; } pull_repo() { as_owner "git -C '$(platform_dir)' pull --ff-only" /; }