home · contact · privacy
Minor refactoring. master
authorPlom Heller <plom@plomlompom.com>
Thu, 24 Sep 2026 22:33:17 +0000 (00:33 +0200)
committerPlom Heller <plom@plomlompom.com>
Thu, 24 Sep 2026 22:33:17 +0000 (00:33 +0200)
CLAUDE.md
scripts/adopt_repo.sh
scripts/lib/check_path_is_git_checkout.sh [new file with mode: 0644]
scripts/lib/point_repo_origin.sh [new file with mode: 0644]
scripts/setup_git_server.sh

index 10d999de4970ac7c1c4c9ed1293032c4165d2b3d..c53937f57caeffebba078ccf155fe865365757ee 100644 (file)
--- 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 <path>` (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 <size> -n <lv> <vg>` with narration.
+- `point_repo_origin <path-checkout> <url>` sets that checkout's `origin`
+  to `<url>` (`remote set-url`, or `remote add` if it has none); used by
+  `setup_git_server.sh` and `adopt_repo.sh`.
 - `efi_copy_kernel_vmlinuz <efi-dir> [<root-prefix>]` copies
   `FNAME_VMLINUZ`/`FNAME_INITRD` into an EFI boot directory; empty prefix
   means the running system's own `/`. `install_debian.sh` passes
index 5b71e59ef04cb7a4a00648e7768d36a1ab4dbd0c..985669f1b0e4e1bf9a55b274cd917ede0c60de7b 100755 (executable)
@@ -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 (file)
index 0000000..f723333
--- /dev/null
@@ -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 (file)
index 0000000..d1ab0c1
--- /dev/null
@@ -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
+}
index 4890b3eb857e1b6fb7bb09bd07f334ee8fb8c4f3..9f94ea59d1f4f7350d9c0766ae1c7a5644e58878 100755 (executable)
@@ -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@<this-server>%s' \