about summary refs log tree commit diff
path: root/colmena/cobalt
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2023-02-05 13:10:48 +0900
committersefidel <contact@sefidel.net>2023-02-05 13:10:48 +0900
commit8b58776e9c2ad8ee5f7fd553a4650ca921e69579 (patch)
treeddcb466f5cfed96a0f8c35d2bab738ef558442c9 /colmena/cobalt
parent1c471fc1847e0da278f0aa4957867f75f40cb1a9 (diff)
downloadnixrc-8b58776e9c2ad8ee5f7fd553a4650ca921e69579.tar.gz
nixrc-8b58776e9c2ad8ee5f7fd553a4650ca921e69579.zip
feat(colmena/services): add 'rename' & enable symbolic-ref
+ move raw scripts to separate directory
Diffstat (limited to 'colmena/cobalt')
-rw-r--r--colmena/cobalt/services/gitolite-noncore/fix-refs9
-rw-r--r--colmena/cobalt/services/gitolite-noncore/rename60
-rw-r--r--colmena/cobalt/services/gitolite.nix11
3 files changed, 79 insertions, 1 deletions
diff --git a/colmena/cobalt/services/gitolite-noncore/fix-refs b/colmena/cobalt/services/gitolite-noncore/fix-refs
new file mode 100644
index 0000000..8ffec9e
--- /dev/null
+++ b/colmena/cobalt/services/gitolite-noncore/fix-refs
@@ -0,0 +1,9 @@
+[[ $4 == W ]] || exit 0
+
+cd $GL_REPO_BASE/$2.git
+
+head=`git symbolic-ref HEAD`
+[[ -f $head ]] || {
+  set -- refs/heads/*
+  git symbolic-ref HEAD $1
+}
diff --git a/colmena/cobalt/services/gitolite-noncore/rename b/colmena/cobalt/services/gitolite-noncore/rename
new file mode 100644
index 0000000..091de82
--- /dev/null
+++ b/colmena/cobalt/services/gitolite-noncore/rename
@@ -0,0 +1,60 @@
+
+# Usage:    ssh git@host rename [-c] <repo1> <repo2>
+#
+# Renames repo1 to repo2. You must be the creator of repo1, and have
+# create ("C") permissions for repo2, which of course must not exist.
+# Alternatively you must be an account admin, that is, you must have
+# write access to the gitolite-admin repository. If you have "C"
+# permissions for repo2 then you can use the -c option to take over
+# as creator of the repository.
+
+die() { echo "$@" >&2; exit 1; }
+usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }
+[ -z "$1" ] && usage
+[ "$1" = "-h" ] && usage
+[ -z "$GL_USER" ] && die GL_USER not set
+
+# ----------------------------------------------------------------------
+
+if [ "$1" = "-c" ]
+then	shift
+	takeover=true
+else	takeover=false
+fi
+
+from="$1"; shift
+to="$1"; shift
+[ -z "$to" ] && usage
+
+topath=$GL_REPO_BASE/$to.git
+
+checkto() {
+	gitolite access -q "$to" $GL_USER ^C any ||
+		die "'$to' already exists or you are not allowed to create it"
+}
+
+if gitolite access -q gitolite-admin $GL_USER
+then
+	# the user is an admin so we can avoid most permission checks
+	if $takeover
+	then checkto
+	elif [ -e $topath ]
+	then die "'$to' already exists"
+	fi
+else
+	# the user isn't an admin, so do all the checks
+	checkto
+	gitolite creator "$from" $GL_USER ||
+		die "'$from' does not exist or you are not allowed to delete it"
+fi
+
+# ----------------------------------------------------------------------
+
+mv $GL_REPO_BASE/$from.git $topath
+[ $? -ne 0 ] && exit 1
+
+$takeover && echo $GL_USER > $topath/gl-creator
+
+echo "$from renamed to $to" >&2
+
+exit
diff --git a/colmena/cobalt/services/gitolite.nix b/colmena/cobalt/services/gitolite.nix
index af4c88a..94c7ac9 100644
--- a/colmena/cobalt/services/gitolite.nix
+++ b/colmena/cobalt/services/gitolite.nix
@@ -30,6 +30,8 @@ in
       # $RC{LOCAL_CODE} = '$ENV{HOME}/local';
       $RC{LOCAL_CODE} = '/var/lib/gitolite/local';
       push(@{$RC{ENABLE}}, 'D');
+      push(@{$RC{ENABLE}}, 'symbolic-ref');
+      push(@{$RC{ENABLE}}, 'rename');
       push(@{$RC{POST_GIT}}, 'fix-refs');
       # push(@{$RC{ENABLE}}, 'set-default-roles');
       # push(@{$RC{ENABLE}}, 'create');
@@ -42,8 +44,15 @@ in
     "/var/lib/gitolite"
   ];
 
+  system.activationScripts.gitolite-create-local = ''
+    mkdir -p /var/lib/gitolite/local/triggers
+    mkdir -p /var/lib/gitolite/local/commands
+    chown -R git:git /var/lib/gitolite/local
+  '';
+
   systemd.tmpfiles.rules = [
-    "C /var/lib/gitolite/local/triggers/fix-refs 755 git git - ${fixRefsTrigger}"
+    "C /var/lib/gitolite/local/triggers/fix-refs 755 - - - ${./gitolite-noncore/fix-refs}"
+    "C /var/lib/gitolite/local/commands/rename 755 - - - ${./gitolite-noncore/rename}"
   ];