From: Plom Heller Date: Mon, 7 Sep 2026 14:10:38 +0000 (+0200) Subject: Use server as git repo mirror. X-Git-Url: https://plomlompom.com/repos/booking/processes?a=commitdiff_plain;h=17e77763bdf0afce497075f98c2cda0a8f96d206;p=confplom Use server as git repo mirror. --- diff --git a/setup_scripts/_lib.sh b/setup_scripts/_lib.sh index 5d9e37f..8fa181a 100644 --- a/setup_scripts/_lib.sh +++ b/setup_scripts/_lib.sh @@ -22,6 +22,7 @@ USERNAME=plom PATH_MY_SSH="${HOME}/${DIRNAME_SSH}" PATH_PROFILE="${HOME}/${FNAME_PROFILE}" PATH_REPO=$(cd .. && pwd) +NAME_REPO_DIR=$(basename "${PATH_REPO}") # path constructors path_luks_mapper() { diff --git a/setup_scripts/install_server.sh b/setup_scripts/install_server.sh index 65464d0..d21593f 100755 --- a/setup_scripts/install_server.sh +++ b/setup_scripts/install_server.sh @@ -5,7 +5,6 @@ FNAME_REPO_TAR=repo.tar # constants derived from changeables -NAME_REPO_DIR=$(basename "${PATH_REPO}") PATH_REPO_PARENT=$(dirname "${PATH_REPO}") PATH_SETUP_SCRIPT="./${NAME_REPO_DIR}/setup_scripts/start_root_server.sh" diff --git a/setup_scripts/setup_git_mirror.sh b/setup_scripts/setup_git_mirror.sh new file mode 100755 index 0000000..25f6143 --- /dev/null +++ b/setup_scripts/setup_git_mirror.sh @@ -0,0 +1,47 @@ +#!/bin/sh +. "$(dirname "$0")/_lib.sh" + +# constants we might want to change at some point +PATH_GIT_BASE=/srv/git + +# constants derived from changeables +PATH_GIT_DAEMON_UNIT=/etc/systemd/system/git-daemon.service +PATH_GIT_MIRROR="${PATH_GIT_BASE}/${NAME_REPO_DIR}.git" + +[ -e "${PATH_GIT_MIRROR}" ]\ + && error "${PATH_GIT_MIRROR} already exists" + +msg 'Installing git …' +apt-get -y update +apt-get -y install git + +msg 'Bare-cloning repo to %s for anonymous serving …' "${PATH_GIT_MIRROR}" +mkdir -p "${PATH_GIT_BASE}" +git clone --quiet --bare "${PATH_REPO}" "${PATH_GIT_MIRROR}" +touch "${PATH_GIT_MIRROR}/git-daemon-export-ok" + +msg 'Own repo to %s so they can update it via ssh …' "${USERNAME}" +chown -R "${USERNAME}:${USERNAME}" "${PATH_GIT_MIRROR}" + +msg 'Writing and enabling git-daemon systemd unit …' +cat <| "${PATH_GIT_DAEMON_UNIT}" +[Unit] +Description=Anonymous read-only git daemon +After=network.target + +[Service] +User=${USERNAME} +ExecStart=/usr/bin/git daemon --reuseaddr \ + --base-path=${PATH_GIT_BASE} ${PATH_GIT_BASE} +Restart=on-failure + +[Install] +WantedBy=multi-user.target +EOF +systemctl daemon-reload +systemctl enable --now git-daemon + +msg 'Anonymous clone URL: git:///%s.git' "${NAME_REPO_DIR}" +msg 'Push updates later with: git push ssh://%s@%s' \ + "${USERNAME}" "${PATH_GIT_MIRROR}" +msg 'Firewall note: git daemon listens on port 9418/tcp.'