diff --git a/Makefile.in b/Makefile.in index 0151ebf..7fd277f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -32,6 +32,7 @@ PLIST = org.$(NAME).server.plist HAIKU_SRV = @HAIKUSRV@ DEFAULT = @DEFAULT@ SYSCONF = @SYSCONF@ +SYSTEMD = @SYSTEMD@ CC ?= @CC@ HOSTCC ?= @HOSTCC@ @@ -101,13 +102,15 @@ install-root: $(INSTALL) -m 644 $(MAP).sample $(DESTDIR)$(ROOT)/gophermap install-inetd-update: install-root - update-inetd --add $$(sed -e "s/@BINARY_PATH@/$(DESTDIR)$(SBINDIR)$(BINARY)/g" -e "s/@BINARY_NAME@/$(BINARY)/g" -e "s/@OPTIONS@/$(INETOPT)/g" init/inetlin.in) + update-inetd --add "$$(sed -e "s:@BINARY_PATH@:$(DESTDIR)$(SBINDIR)/$(BINARY):g" -e "s/@OPTIONS@/$(INETOPT)/g" init/inetlin.in)" + update-inetd --enable gopher install-inetd-manual: install-root - sed -e "s:@BINARY_PATH@:$(DESTDIR)$(SBINDIR)/$(BINARY):g" -e "s/@BINARY_NAME@/$(BINARY)/g" -e "s/@OPTIONS@/$(INETOPT)/g" init/inetlin.in >> $(DESTDIR)$(INETD) + sed -e "s:@BINARY_PATH@:$(DESTDIR)$(SBINDIR)/$(BINARY):g" -e "s/@OPTIONS@/$(INETOPT)/g" init/inetlin.in >> $(DESTDIR)$(INETD) install-xinetd: install-root $(INSTALL) -d -m 755 $(DESTDIR)/etc/xinetd.d + sed -i -e "s:@BINARY@:$(DESTDIR)$(SBINDIR)/$(BINARY):g" init/$(NAME).xinetd $(INSTALL) -m 644 -T init/$(NAME).xinetd $(DESTDIR)$(XINETD) install-osx: install-root @@ -122,12 +125,12 @@ install-haiku: install-root install-systemd: install-root $(INSTALL) -d -m 755 $(DESTDIR)$(SYSCONF) $(INSTALL) -m 644 -T init/$(NAME).env $(DESTDIR)$(SYSCONF)/$(NAME) - $(INSTALL) -m 644 -T init/$(NAME).socket $(DESTDIR)$(SYSCONF)/$(NAME) - $(INSTALL) -m 644 -T init/$(NAME)\@.service $(DESTDIR)$(SYSCONF)/$(NAME) $(INSTALL) -d -m 755 $(DESTDIR)$(DEFAULT) $(INSTALL) -m 644 -T init/$(NAME).env $(DESTDIR)$(DEFAULT)/$(NAME) - $(INSTALL) -m 644 -T init/$(NAME).socket $(DESTDIR)$(DEFAULT)/$(NAME) - $(INSTALL) -m 644 init/$(NAME)\@.service $(DESTDIR)$(DEFAULT)/$(NAME) + $(INSTALL) -d -m 755 $(DESTDIR)$(SYSTEMD) + $(INSTALL) -m 644 -t $(DESTDIR)$(SYSTEMD) init/$(NAME).socket + sed -i -e "s:@BINARY@:$(DESTDIR)$(SBINDIR)/$(BINARY):g" init/$(NAME)\@.service + $(INSTALL) -m 644 -t $(DESTDIR)$(SYSTEMD) init/$(NAME)\@.service uninstall: @UNINSTALL_INETD_UPDATE@ @UNINSTALL_INETD_MANUAL@ @UNINSTALL_XINETD@ @UNINSTALL_OSX@ @UNINSTALL_SYSTEMD@ rm -f $(DESTDIR)$(SBINDIR)/$(BINARY) @@ -150,8 +153,6 @@ uninstall-haiku: uninstall-systemd: rm -f $(DESTDIR)$(SYSCONF)/$(NAME)/$(NAME).env - rm -f $(DESTDIR)$(SYSCONF)/$(NAME)/$(NAME).socket - rm -f $(DESTDIR)$(SYSCONF)/$(NAME)/$(NAME)\@.service rm -f $(DESTDIR)$(DEFAULT)/$(NAME)/$(NAME).env - rm -f $(DESTDIR)$(DEFAULT)/$(NAME)/$(NAME).socket - rm -f $(DESTDIR)$(DEFAULT)/$(NAME)/$(NAME)\@.service + rm -f $(DESTDIR)$(SYSTEMD)/$(NAME).socket + rm -f $(DESTDIR)$(SYSTEMD)/$(NAME)\@.service diff --git a/configure b/configure index ec9611e..728cbfd 100755 --- a/configure +++ b/configure @@ -10,10 +10,11 @@ usage() { printf " --mandir=PREFIX/share/man Prefix for manpages\\n" printf " --man8dir=MANDIR/man8 Prefix for section 8 manpages\\n" printf " --gopherroot=/var/gopher Path to gopher root\\n" - printf " --sysconfig=/etc/sysconfig Path to sysconfig directory\\n\\n" - printf " --default=/etc/default Path to 'default' configuration directory\\n\\n" + printf " --sysconfig=/etc/sysconfig Path to sysconfig directory\\n" + printf " --default=/etc/default Path to 'default' configuration directory\\n" printf " --launchd=/Library/LaunchDaemons Path to launchd for MacOS\\n" - printf " --haikusrv=/boot/common/settings/network/services Path to services directory in Haiku\\n\\n" + printf " --haikusrv=/boot/common/settings/network/services Path to services directory in Haiku\\n" + printf " --systemd=/lib/systemd/system Path to systemd directory when using systemd listener\\n" printf " --os=autodetected Your target OS, one of linux, mac, haiku, netbsd, openbsd or freebsd\\n" printf " --listener=somelistener Program to recieve and pass network requests; one or more of systemd, inetd, xinetd, comma-seperated, or autodetect, mac or haiku (parameter required, mac/haiku required on respective OSes)\\n" printf " --hostname=autodetected Desired hostname for gophernicus to identify as\\n" @@ -37,7 +38,8 @@ while [ "$#" -gt 0 ] ; do os) OS="${value}"; shift ;; launchd) LAUNCHD="${value}"; shift ;; haikusrv) HAIKUSRV="${value}"; shift ;; - listener) LISTENER="${value}"; shift ;; + systemd) SYSTEMD="${value}"; shift ;; + listener) LISTENERS="${value}"; shift ;; hostname) HOSTNAME="${value}"; shift ;; help) usage; exit 0 ;; *) usage; exit 2 ;; @@ -56,6 +58,7 @@ done : ${DEFAULTCONF:=/etc/default} : ${LAUNCHD:=/Library/LaunchDaemons} : ${HAIKUSRV:=/boot/common/settings/network/services} +: ${SYSTEMD:=/lib/systemd/system} : ${CC:=cc} : ${HOSTCC:=${CC}} : ${CFLAGS:=-O2} @@ -118,7 +121,13 @@ else fi printf "\\n" -listeners="$(echo ${LISTENER} | tr ',' ' ')" +listeners="$(echo ${LISTENERS} | tr ',' ' ')" +if [ -z "${listeners}" ]; then + printf "checking for listener... " + printf "not given\\n" + exit 1 +fi + for listener in ${listeners}; do # Check for listener validity and autodetect if required # Checks that take place: @@ -142,33 +151,30 @@ for listener in ${listeners}; do # OS-specific listeners case "${OS}" in mac) - LISTENER=mac + listener=mac printf "mac\\n" break ;; haiku) - LISTENER=haiku + listener=haiku printf "haiku\\n" break ;; esac if [ -d "/lib/systemd/system" ] ; then - LISTENER=systemd + listener=systemd printf "systemd\\n" - break fi printf "checking for inetd... " - if command -v update-inetd; then - LISTENER=inetd + if command -v update-inetd && [ "${listener}" = "autodetect" ]; then + listener=inetd printf "inetd\\n" - break fi printf "checking for xinetd... " - if XINETD="$(command -v xinetd)"; then - LISTENER=xinetd + if XINETD="$(command -v xinetd)" && [ "${listener}" = "autodetect" ]; then + listener=xinetd printf "xinetd\\n" - break fi # Ensure we detected something @@ -299,6 +305,7 @@ sed -i -e "s:@ROOT@:${GOPHERROOT}:" Makefile sed -i -e "s:@HAIKUSRV@:${HAIKUSRV}:" Makefile sed -i -e "s:@LAUNCHD@:${LAUNCHD}:" Makefile +sed -i -e "s:@SYSTEMD@:${SYSTEMD}:" Makefile sed -i -e "s:@INSTALL_ROOT@:${INSTALL_ROOT}:" Makefile sed -i -e "s:@INSTALL_OSX@:${INSTALL_OSX}:" Makefile @@ -328,5 +335,12 @@ for f in gophernicus.env haiku_snippet org.gophernicus.server.plist \ printf "done\\n" done +# And generate gophernicus@.service +printf "creating init/gophernicus@.service... " +sed -e "s:@DEFAULT@:${DEFAULTCONF}:" \ + -e "s:@SYSCONFIG@:${SYSCONFIG}:" \ + 'init/gophernicus@.service.in' > 'init/gophernicus@.service' +printf "done\\n" + # Cleanup rm -f conftest conftest.c diff --git a/init/.gitignore b/init/.gitignore index 4fc3d36..e8842f7 100644 --- a/init/.gitignore +++ b/init/.gitignore @@ -3,3 +3,4 @@ org.gophernicus.server.plist gophernicus.xinetd inetlin gophernicus.env +gophernicus@.service diff --git a/init/gophernicus.xinetd.in b/init/gophernicus.xinetd.in index 0c5553c..4f2c921 100644 --- a/init/gophernicus.xinetd.in +++ b/init/gophernicus.xinetd.in @@ -5,7 +5,7 @@ service gopher socket_type = stream wait = no user = nobody - server = /usr/sbin/gophernicus + server = @BINARY@ server_args = -r/var/gopher -h@HOSTNAME@ disable = no } diff --git a/init/gophernicus@.service b/init/gophernicus@.service deleted file mode 100644 index dacb19b..0000000 --- a/init/gophernicus@.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Gophernicus gopher server - -[Service] -EnvironmentFile=-/etc/default/gophernicus -EnvironmentFile=-/etc/sysconfig/gophernicus -ExecStart=/usr/sbin/gophernicus -h %H $OPTIONS -SuccessExitStatus=1 -StandardInput=socket -User=nobody diff --git a/init/gophernicus@.service.in b/init/gophernicus@.service.in new file mode 100644 index 0000000..54279ea --- /dev/null +++ b/init/gophernicus@.service.in @@ -0,0 +1,10 @@ +[Unit] +Description=Gophernicus gopher server + +[Service] +EnvironmentFile=-@DEFAULT@/gophernicus +EnvironmentFile=-@SYSCONFIG@/gophernicus +ExecStart=@BINARY@ $OPTIONS +SuccessExitStatus=1 +StandardInput=socket +User=nobody diff --git a/init/inetlin.in b/init/inetlin.in index aa02d82..178e739 100644 --- a/init/inetlin.in +++ b/init/inetlin.in @@ -1 +1 @@ -gopher stream tcp nowait @BINARY_PATH@ @BINARY_NAME@ @OPTIONS@ +gopher stream tcp nowait nobody @BINARY_PATH@ @OPTIONS@