gitdaemon_chroot.sh (1645B)
1 #!/bin/sh 2 # 3 # public domain. 4 # 5 6 set -eu 7 8 # 9 # Tested on OpenBSD 7.1. 10 # 11 12 if test $(id -u) -ne 0; then 13 echo "This script must be run as root." 14 exit 1 15 fi 16 17 local default=/var/git 18 read CHROOT?"chroot install directory [$default]: " 19 : ${CHROOT:=$default} 20 21 # daemon seems like an appropriate group. 22 mkdir -p ${CHROOT} 23 chgrp daemon ${CHROOT} 24 25 # git-daemon requires /dev/null, create it 26 rm -f ${CHROOT}/dev/null 27 mkdir -p ${CHROOT}/dev 28 mknod -m 666 ${CHROOT}/dev/null c 3 2 29 30 # Check if nodev is a mount option 31 if grep var /etc/fstab | grep nodev; then 32 echo "error: /var mount has 'nodev' option; this must be removed" 33 echo " Do not forget to remount the filesystem afterwards." 34 exit 1 35 fi 36 37 # 38 # Copy dynamic library dependencies into CHROOT 39 # Knock off the first 2 lines of `ldd' output, field 7 contains the library 40 # path. 41 # 42 ldd /usr/local/libexec/git/git-daemon | tail -n +3 | awk '{ print $7 }' | 43 while read -r lib_path 44 do 45 mkdir -p ${CHROOT}/$(dirname $lib_path) 46 cp $lib_path ${CHROOT}/$lib_path 47 done 48 49 # Copy git binary for `upload-pack'. 50 git_bin=/usr/local/bin/git 51 mkdir -p ${CHROOT}/$(dirname $git_bin) 52 cp $git_bin ${CHROOT}/$git_bin 53 54 # 55 # Kinda tricky.. we want to substitute the CHROOT picked above into this diff, 56 # but not expand the other rc variables at this time. 57 # 58 cat - << EOF | patch -d /etc/rc.d 59 --- /etc/rc.d/gitdaemon.orig Sat Jan 18 17:47:47 2020 60 +++ /etc/rc.d/gitdaemon Sat Jan 18 17:33:42 2020 61 @@ -7,6 +7,10 @@ 62 63 . /etc/rc.d/rc.subr 64 65 +rc_start() { 66 + chroot -u \${daemon_user} ${CHROOT} \${daemon} \${daemon_flags} 67 +} 68 + 69 pexp="/usr/local/libexec/git/git-daemon --detach\${daemon_flags:+ \${daemon_flags}}" 70 rc_reload=NO 71 EOF