summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore6
-rw-r--r--Makefile5
-rw-r--r--rc.d/litterbox51
3 files changed, 59 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 272bd1a..eb8afe8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
 *.o
-litterbox
-scoop
+/litterbox
+/scoop
+/unscoop
 tags
-unscoop
diff --git a/Makefile b/Makefile
index 309dd8f..b358a82 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 PREFIX = /usr/local
 MANDIR = ${PREFIX}/share/man
+ETCDIR = ${PREFIX}/etc
 LIBS_PREFIX = /usr/local
 
 CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
@@ -10,6 +11,7 @@ LDLIBS_litterbox = -ltls
 
 BINS = litterbox scoop unscoop
 MANS = ${BINS:=.1}
+RCS  = rc.d/litterbox
 
 -include config.mk
 
@@ -37,6 +39,9 @@ install: ${BINS} ${MANS}
 	install -d ${PREFIX}/bin ${MANDIR}/man1
 	install ${BINS} ${PREFIX}/bin
 	for man in ${MANS}; do gzip -c $$man > ${MANDIR}/man1/$$man.gz; done
+	if [ -n '${RCS}' ]; then install -d ${ETCDIR}/rc.d; fi
+	if [ -n '${RCS}' ]; then install ${RCS} ${ETCDIR}/rc.d; fi
 
 uninstall:
 	rm -f ${BINS:%=${PREFIX}/bin/%} ${MANS:%=${MANDIR}/man1/%.gz}
+	if [ -n '${RCS}' ]; then rm -f ${RCS:%=${ETCDIR}/%}; fi
diff --git a/rc.d/litterbox b/rc.d/litterbox
new file mode 100644
index 0000000..fbcc97d
--- /dev/null
+++ b/rc.d/litterbox
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# PROVIDE: litterbox
+# REQUIRE: LOGIN
+# KEYWORD: shutdown
+
+. /etc/rc.subr
+
+name='litterbox'
+rcvar='litterbox_enable'
+
+load_rc_config "${name}"
+
+: ${litterbox_enable:='NO'}
+
+command='/usr/sbin/daemon'
+pidprefix="/var/run/${name}"
+pidfile="${pidprefix}.pid"
+
+child_command='/usr/local/bin/litterbox'
+
+if [ -n "$2" ]; then
+	profile=$2
+	if [ -n "${litterbox_profiles}" ]; then
+		pidfile="${pidprefix}.${profile}.pid"
+		eval litterbox_enable="\${litterbox_${profile}_enable:-${litterbox_enable}}"
+		eval litterbox_flags="\${litterbox_${profile}_flags:-${litterbox_flags}}"
+		eval litterbox_user="\${litterbox_${profile}_user:-${litterbox_user}}"
+		eval litterbox_env="\${litterbox_${profile}_env:-${litterbox_env}}"
+	else
+		echo "$0: extra argument ignored"
+	fi
+else
+	if [ -n "${litterbox_profiles}" -a -n "$1" ]; then
+		for profile in ${litterbox_profiles}; do
+			echo "===> ${name} profile: ${profile}"
+			/usr/local/etc/rc.d/${name} "$1" "${profile}" || exit "$?"
+		done
+		exit
+	fi
+fi
+
+child_flags=$litterbox_flags
+child_user=$litterbox_user
+unset litterbox_flags litterbox_user
+command_args="\
+	-r -P ${pidfile} -T ${name}${profile:+/${profile}} \
+	${child_user:+-u ${child_user}} \
+	-- ${child_command} ${child_flags}"
+
+run_rc_command "$1"