commit e4ed45d222fa8d7ebb223066bdce796b10f67172
parent 1135106521ae3f47492a772f037d3d5f0653003f
Author: Kyle Milz <krwmilz@gmail.com>
Date: Wed, 17 Nov 2021 22:07:44 +0000
gitdaemon chroot 69
- add license
- add check for running as root
- add prompt for install location
- replace writing diff file with pipe
Diffstat:
1 file changed, 36 insertions(+), 9 deletions(-)
diff --git a/gitdaemon_chroot.sh b/gitdaemon_chroot.sh
@@ -1,20 +1,45 @@
#!/bin/sh
+#
+# Copyright (c) Kyle Milz <krwmilz@gmail.com>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
set -eu
#
-# Script must be run as root.
-# Tested on OpenBSD.
+# Tested on OpenBSD 6.9.
#
-# Change this to your chroot location.
-CHROOT=/var/git
-echo "Installing into '${CHROOT}' ..."
+if test $(id -u) -ne 0; then
+ echo "This script must be run as root."
+ exit 1
+fi
+
+#
+# By default we will serve files from the same location that gotweb expects
+# repositories.
+#
+local default=/var/www/got
+read CHROOT?"chroot install directory [$default]: "
+: ${CHROOT:=$default}
+# daemon seems like an appropriate group.
mkdir -p ${CHROOT}
chgrp daemon ${CHROOT}
# git-daemon requires /dev/null, create it
+rm -f ${CHROOT}/dev/null
mkdir -p ${CHROOT}/dev
mknod -m 666 ${CHROOT}/dev/null c 3 2
@@ -42,7 +67,11 @@ git_bin=/usr/local/bin/git
mkdir -p ${CHROOT}/$(dirname $git_bin)
cp $git_bin ${CHROOT}/$git_bin
-cat - << EOF > chroot_gitdaemon_68.diff
+#
+# Kinda tricky.. we want to substitute the CHROOT picked above into this diff,
+# but not expand the other rc variables at this time.
+#
+cat - << EOF | patch -d /etc/rc.d
--- /etc/rc.d/gitdaemon.orig Sat Jan 18 17:47:47 2020
+++ /etc/rc.d/gitdaemon Sat Jan 18 17:33:42 2020
@@ -7,6 +7,10 @@
@@ -53,8 +82,6 @@ cat - << EOF > chroot_gitdaemon_68.diff
+ chroot -u \${daemon_user} ${CHROOT} \${daemon} \${daemon_flags}
+}
+
- pexp="/usr/local/libexec/git/git-daemon --detach${daemon_flags:+ ${daemon_flags}}"
+ pexp="/usr/local/libexec/git/git-daemon --detach\${daemon_flags:+ \${daemon_flags}}"
rc_reload=NO
EOF
-
-patch -d /etc/rc.d < chroot_gitdaemon_68.diff