From: Plom Heller Date: Thu, 24 Sep 2026 22:33:17 +0000 (+0200) Subject: Minor refactoring. X-Git-Url: https://plomlompom.com/repos/booking/%7B%7Bprefix%7D%7D/ledger2?a=commitdiff_plain;p=confplom Minor refactoring. --- diff --git a/CLAUDE.md b/CLAUDE.md index 10d999d..c53937f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -204,8 +204,9 @@ caller) rather than functions reaching for same-named globals. - Validation: `check_tools`, `check_boot_device_layout`, `check_partition_mountable` (takes the partition as explicit `$1`; callers now always pass `PATH_PARTITION_LUKSVG`/`PATH_PARTITION_EFI`), - `check_new_luksvg`, `check_openable_luksvg`, `usage` (arg-count check with - auto-built usage message). The boot-label legality check in + `check_new_luksvg`, `check_openable_luksvg`, + `check_path_is_git_checkout ` (has a `.git`), `usage` (arg-count + check with auto-built usage message). The boot-label legality check in `install_debian.sh` is an inline `case`, not a helper, since it's the only caller left. - LUKS lifecycle: `open_luksvg`/`close_luksvg` operate on the global @@ -232,6 +233,9 @@ caller) rather than functions reaching for same-named globals. succeeds — wraps every `passwd` call so mismatched passwords re-prompt instead of aborting via errexit. `create_lv` wraps `lvcreate -L -n ` with narration. +- `point_repo_origin ` sets that checkout's `origin` + to `` (`remote set-url`, or `remote add` if it has none); used by + `setup_git_server.sh` and `adopt_repo.sh`. - `efi_copy_kernel_vmlinuz []` copies `FNAME_VMLINUZ`/`FNAME_INITRD` into an EFI boot directory; empty prefix means the running system's own `/`. `install_debian.sh` passes diff --git a/scripts/adopt_repo.sh b/scripts/adopt_repo.sh index 5b71e59..985669f 100755 --- a/scripts/adopt_repo.sh +++ b/scripts/adopt_repo.sh @@ -3,10 +3,11 @@ include OPTS_SSH_NEW_HOST include PATH_GIT_BASE include USERNAME +include check_path_is_git_checkout include check_tools include error include msg -include try_quiet +include point_repo_origin include usage # inputs to confirm @@ -16,8 +17,7 @@ SERVER=$2 LOGIN="${USERNAME}@${SERVER}" # early sanity check, with further-down constant declarations relying on this … -[ -d "${PATH_SRC_REPO}/.git" ]\ - || error "${PATH_SRC_REPO}: not a git checkout" +check_path_is_git_checkout "${PATH_SRC_REPO}" # constants derived from changeables NAME_REPO=$(basename "$(cd "${PATH_SRC_REPO}" && pwd)") @@ -46,19 +46,14 @@ GIT_SSH_COMMAND="ssh ${OPTS_SSH_NEW_HOST}" \ git -C "${PATH_SRC_REPO}" push --quiet "${URL_REMOTE_REPO}" \ 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*' -msg "Pointing this checkout's origin at %s …" "${SERVER}" -if try_quiet git -C "${PATH_SRC_REPO}" remote get-url origin; then - PUSHURL=$(git -C "${PATH_SRC_REPO}" config --get remote.origin.pushurl)\ - || PUSHURL="" - git -C "${PATH_SRC_REPO}" remote set-url origin "${URL_REMOTE_REPO}" - if [ -n "${PUSHURL}" ] && [ "${PUSHURL}" != "${URL_REMOTE_REPO}" ]; then - msg 'Note: origin also has a separate pushurl (%s)' "${PUSHURL}" - msg 'left untouched; a bare git push will still use it. To also' - msg 'repoint pushes here:' - msg ' git remote set-url --push origin %s' "${URL_REMOTE_REPO}" - fi -else - git -C "${PATH_SRC_REPO}" remote add origin "${URL_REMOTE_REPO}" +point_repo_origin "${PATH_SRC_REPO}" "${URL_REMOTE_REPO}" +PUSHURL=$(git -C "${PATH_SRC_REPO}" config --get remote.origin.pushurl)\ + || PUSHURL="" +if [ -n "${PUSHURL}" ] && [ "${PUSHURL}" != "${URL_REMOTE_REPO}" ]; then + msg 'Note: origin also has a separate pushurl (%s)' "${PUSHURL}" + msg 'left untouched; a bare git push will still use it. To also' + msg 'repoint pushes here:' + msg ' git remote set-url --push origin %s' "${URL_REMOTE_REPO}" fi msg '%s is now authoritative for %s.' "${SERVER}" "${NAME_REPO}" diff --git a/scripts/lib/check_path_is_git_checkout.sh b/scripts/lib/check_path_is_git_checkout.sh new file mode 100644 index 0000000..f723333 --- /dev/null +++ b/scripts/lib/check_path_is_git_checkout.sh @@ -0,0 +1,7 @@ +include error + +check_path_is_git_checkout() { + local PATH_CHECKOUT=$1 + [ -d "${PATH_CHECKOUT}/.git" ]\ + || error "${PATH_CHECKOUT}: not a git checkout" +} diff --git a/scripts/lib/point_repo_origin.sh b/scripts/lib/point_repo_origin.sh new file mode 100644 index 0000000..d1ab0c1 --- /dev/null +++ b/scripts/lib/point_repo_origin.sh @@ -0,0 +1,13 @@ +include msg +include try_quiet + +point_repo_origin() { + local PATH_CHECKOUT=$1 + local URL_ORIGIN=$2 + msg "Pointing %s's origin at %s …" "${PATH_CHECKOUT}" "${URL_ORIGIN}" + if try_quiet git -C "${PATH_CHECKOUT}" remote get-url origin; then + git -C "${PATH_CHECKOUT}" remote set-url origin "${URL_ORIGIN}" + else + git -C "${PATH_CHECKOUT}" remote add origin "${URL_ORIGIN}" + fi +} diff --git a/scripts/setup_git_server.sh b/scripts/setup_git_server.sh index 4890b3e..9f94ea5 100755 --- a/scripts/setup_git_server.sh +++ b/scripts/setup_git_server.sh @@ -4,10 +4,10 @@ include DIRNAME_REPO include PATH_GIT_BASE include PATH_REPO include USERNAME -include error +include check_path_is_git_checkout include msg +include point_repo_origin include render_template -include try_quiet # constants derived from changeables FNAME_GIT_DAEMON_UNIT=git-daemon.service @@ -15,9 +15,8 @@ PATH_GIT_DAEMON_UNIT="/etc/systemd/system/${FNAME_GIT_DAEMON_UNIT}" PATH_SELF_HOSTED="${PATH_GIT_BASE}/${DIRNAME_REPO}.git" URL_SELF_HOSTED_LOCAL="git://localhost/${DIRNAME_REPO}.git" -# early sanity check, so we fail before changing anything -[ -d "${PATH_REPO}/.git" ]\ - || error "${PATH_REPO}: not a git checkout, so cannot host it" +# sanity checks +check_path_is_git_checkout "${PATH_REPO}" msg 'Ensuring installation of git …' apt-get -y update @@ -47,12 +46,7 @@ else chown -R "${USERNAME}:${USERNAME}" "${PATH_SELF_HOSTED}" fi -msg "Pointing %s's origin at %s …" "${PATH_REPO}" "${URL_SELF_HOSTED_LOCAL}" -if try_quiet git -C "${PATH_REPO}" remote get-url origin; then - git -C "${PATH_REPO}" remote set-url origin "${URL_SELF_HOSTED_LOCAL}" -else - git -C "${PATH_REPO}" remote add origin "${URL_SELF_HOSTED_LOCAL}" -fi +point_repo_origin "${PATH_REPO}" "${URL_SELF_HOSTED_LOCAL}" msg 'Ready. To make the checkout you commit in push here, run there:' msg ' git remote set-url origin ssh://%s@%s' \