aboutsummaryrefslogtreecommitdiffstats
path: root/cgit-chroot
diff options
context:
space:
mode:
authorWynn Wolf Arbor2020-05-27 15:30:14 +0200
committerWynn Wolf Arbor2020-05-27 15:43:20 +0200
commitebcc62e2a84b3b2b819f55d8910bc0b3ce84a133 (patch)
treebe52a049056da85ab9947d17ffceb860cb1a477f /cgit-chroot
downloadskein-ebcc62e2a84b3b2b819f55d8910bc0b3ce84a133.tar.gz
Initial import0.0.1
Diffstat (limited to 'cgit-chroot')
-rwxr-xr-xcgit-chroot71
1 files changed, 71 insertions, 0 deletions
diff --git a/cgit-chroot b/cgit-chroot
new file mode 100755
index 0000000..1828ee5
--- /dev/null
+++ b/cgit-chroot
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+set -e
+
+CGIT_CHROOT=${CGIT_CHROOT:-/srv/cgit}
+CGIT_GIT_ROOT=${CGIT_GIT_ROOT:-/srv/git}
+
+log() {
+ printf ' %s %s\n' "$1" "$2"
+}
+
+ladd() {
+ log + "$1"
+}
+
+ldel() {
+ log - "$1"
+}
+
+remove_prefix() {
+ printf "%s" "${1#$CGIT_CHROOT/*}"
+}
+
+bind_mount() {
+ mkdir "$2"
+ mount --rbind "$1" "$2"
+ mount --make-rslave "$2"
+ ladd "$(remove_prefix "$2")"
+}
+
+bind_umount() {
+ umount "$i"
+ rmdir "$i"
+ ldel "$(remove_prefix "$i")"
+}
+
+setup() {
+ mkdir "$CGIT_CHROOT"/dev
+ mknod "$CGIT_CHROOT"/dev/null c 1 3
+ chmod 666 "$CGIT_CHROOT"/dev/null
+
+ for i in "$CGIT_CHROOT"/instances/*; do
+ test -d "$i" || continue
+ user=$(basename "$i")
+ id -ru "$user" >/dev/null || continue
+
+ git_repo_dir="${CGIT_GIT_ROOT}/$user"
+ test -d "$git_repo_dir" || continue
+
+ instance_repo_dir="$CGIT_CHROOT"/instances/$user/repos
+
+ bind_mount "$git_repo_dir" "$instance_repo_dir"
+ chmod 0701 "$instance_repo_dir"
+ done
+}
+
+teardown() {
+ rm "$CGIT_CHROOT"/dev/null
+ rmdir "$CGIT_CHROOT"/dev
+
+ for i in "$CGIT_CHROOT"/instances/*/repos; do
+ bind_umount "$i"
+ done
+}
+
+test $# -eq 1 || exit 1
+
+case $1 in
+ setup) setup;;
+ teardown) teardown;;
+esac