diff options
author | Wynn Wolf Arbor | 2020-05-27 21:48:14 +0200 |
---|---|---|
committer | Wynn Wolf Arbor | 2020-05-27 21:48:14 +0200 |
commit | 5d12f42bb6d8f339dbe76689a0fb2afa51f994d9 (patch) | |
tree | 0f9e83ef29af6c0634f91164fee69eb284052fc6 /skein-infra | |
parent | 3bd87dc46ff202ee3d37e9d5e3e0c5ebfe504bba (diff) | |
download | skein-5d12f42bb6d8f339dbe76689a0fb2afa51f994d9.tar.gz |
cgit-chroot: Rename to skein-infra
Be more clear about the purpose of this script and rename it to
"skein-infra" since users might expect a program carrying "chroot" in
its name to enter or otherwise manage a chroot.
Additionally, use a consistent format for the environment variables
controlling the locations of the cgit chroot and git repositories.
Diffstat (limited to 'skein-infra')
-rwxr-xr-x | skein-infra | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/skein-infra b/skein-infra new file mode 100755 index 0000000..44f55a5 --- /dev/null +++ b/skein-infra @@ -0,0 +1,77 @@ +#!/bin/sh + +set -e + +SKEIN_CGIT_ROOT=${SKEIN_CGIT_ROOT:-/srv/cgit} +SKEIN_GIT_ROOT=${SKEIN_GIT_ROOT:-/srv/git} + +usage() { + printf 'usage: skein-infra setup|teardown\n' >&2 + exit 1 +} + +log() { + printf ' %s %s\n' "$1" "$2" +} + +ladd() { + log + "$1" +} + +ldel() { + log - "$1" +} + +remove_prefix() { + printf "%s" "${1#$SKEIN_CGIT_ROOT/*}" +} + +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 "$SKEIN_CGIT_ROOT"/dev + mknod "$SKEIN_CGIT_ROOT"/dev/null c 1 3 + chmod 666 "$SKEIN_CGIT_ROOT"/dev/null + + for i in "$SKEIN_CGIT_ROOT"/instances/*; do + test -d "$i" || continue + user=$(basename "$i") + id -ru "$user" >/dev/null || continue + + git_repo_dir="${SKEIN_GIT_ROOT}/$user" + test -d "$git_repo_dir" || continue + + instance_repo_dir="$SKEIN_CGIT_ROOT"/instances/$user/repos + + bind_mount "$git_repo_dir" "$instance_repo_dir" + chmod 0701 "$instance_repo_dir" + done +} + +teardown() { + rm "$SKEIN_CGIT_ROOT"/dev/null + rmdir "$SKEIN_CGIT_ROOT"/dev + + for i in "$SKEIN_CGIT_ROOT"/instances/*/repos; do + bind_umount "$i" + done +} + +test $# -eq 1 || usage + +case $1 in + setup) setup;; + teardown) teardown;; + *) usage;; +esac |