aboutsummaryrefslogblamecommitdiffstats
path: root/skein-infra
blob: 45c9f8b43ff0e01b54cf7393a282729867d05621 (plain) (tree)
1
2
3
4
5
6
7
8
9



         

                                             
 
         
                                                        


              
             


                                   



                                
                          


               

                   
                          


         


                                               
 
                                              



                                                     
                                                      

                                                   
                                                                         
 
                                                             



            

                                      
 
                                                          



                                
                      



                            
                  
    
#!/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_mount() {
	printf ' %s %s\n' "$1" "$2"
}

bind_mount() {
	mkdir "$2"
	mount --rbind "$1" "$2"
	mount --make-rslave "$2"
	log_mount "+" "$2"
}

bind_umount() {
	umount "$1"
	rmdir "$1"
	log_mount "-" "$1"
}

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"/home/*; 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

		available_repos="$SKEIN_CGIT_ROOT"/home/$user/repos.avail

		bind_mount "$git_repo_dir" "$available_repos"
	done
}

teardown() {
	rm "$SKEIN_CGIT_ROOT"/dev/null
	rmdir "$SKEIN_CGIT_ROOT"/dev

	for i in "$SKEIN_CGIT_ROOT"/home/*/repos.avail; do
		bind_umount "$i"
	done
}

test $# -eq 1 || usage

case $1 in
	setup) setup;;
	teardown) teardown;;
	*) usage;;
esac