coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

commit ebb5d5c4ec031e2a774a97301db08f918e6146cd
parent a86d46ab39d085fa2c5be3d737143a415a231476
Author: parazyd <parazyd@dyne.org>
Date:   Tue, 29 Mar 2016 22:40:28 +0200

added debian-style initscript

Diffstat:
Mconf/config.sh | 23+++++++++++++++++++++--
Aconf/initscript-deb | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 2 deletions(-)

diff --git a/conf/config.sh b/conf/config.sh @@ -50,8 +50,21 @@ edit-sudo() { fi } +update-init() { + # TODO: rearrange this into another function and add other distros + update-rc.d +} + +ckdistro() { + which apt-get >/dev/null && distro=deb + which emerge >/dev/null && distro=gentoo +} + # because all cool software has snowmen in them [[ $1 == "snowman" ]] && { + # NOTE: remember to set this; see update-init() + # ckdistro + distro=deb pushd `pwd`/conf groupadd coffin && print "created coffin group" @@ -94,10 +107,12 @@ edit-sudo() { edit-sudo add install -Dm770 -g coffin -d /home/graveyard + install -Dm755 initscript-$distro /etc/init.d/coffin - # TODO: add initscript + update-init print "Successfully installed and configured coffin!" + print "You can start it with '/etc/init.d/coffin start'" print "######################################" fprint=`openssl x509 -noout -in coffin.pem -fingerprint \ @@ -105,6 +120,7 @@ edit-sudo() { print "The fingerptint of your SSL certificate is: $fprint" print "Compare it and/or set is as trusted when you connect to coffin." print "######################################" + print "" popd return 0 @@ -115,7 +131,7 @@ edit-sudo() { print "Uninstalling coffin. Why? Why? Why?" print "*cries*\n" - # /etc/init.d/coffin stop + /etc/init.d/coffin stop # uncomment if you wish to revert apache #revert=true @@ -146,4 +162,7 @@ edit-sudo() { rm -v src/tomb-kdb-pbkdf2-gensalt rm -v src/tomb-kdb-pbkdf2-getiter rm -v src/tomb + rm -v /etc/init.d/coffin + + update-init } diff --git a/conf/initscript-deb b/conf/initscript-deb @@ -0,0 +1,95 @@ +#!/bin/bash + +### BEGIN INIT INFO +# Provides: coffin +# Required-Start: $local_fs $network $ +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Example initscript +# Description: This file should be used to construct scripts to be +# placed in /etc/init.d. This example start a +# single forking daemon capable of writing a pid +# file. To get other behavoirs, implemend +# do_start(), do_stop() or other functions to +# override the defaults in /lib/init/init-d-script. +### END INIT INFO + +# Author: parazyd <parazyd@dyne.org> + +DAEMON=/usr/src/coffin/run/coffin +NAME=coffin +DESC="coffin daemon" +COFFINPIDDIR=/usr/src/coffin/run +COFFINPID=$COFFINPIDDIR/coffin.pid +WAITFORDAEMON=20 + +text -x $DAEMON || exit 0 + +wait-for-dead-daemon() { + pid=$1 + sleep 1 + if test -n "$pid"; then + if kill -0 $pid 2>/dev/null ; then + cnt=0 + while kill -0 $pid 2>/dev/null ; do + cnt=`expt $cnt + 1` + if [ $cnt -gt $WAITFORDAEMON ]; then + log_action_end_msg 1 "still running" + exit 1 + fi + sleep 1 + [ "`expt $cnt % 3`" != 2 ] || log_action_cont_msg "" + done + fi + fi + log_action_end_msg 0 +} + +case "$1" in + start) + log_action_begin_msg "Starting $DESC" + + if start-stop-daemon --stop --signal 0 --quiet --pidfile $COFFINPID --exec $DAEMON; then + log_action_end_msg 0 "already running" + else + if start-stop-daemon --start --quiet \ + --pidfile $COFFINPID \ + --exec $DAEMON -- + then + log_action_end_msg 0 + else + log_action_end_msg 1 + exit 1 + fi + fi + ;; + stop) + log_daemon_msg "Stopping $DESC" + pid=`cat $COFFINPID 2>/dev/null` || true + + if test ! -f $COFFINPID -o -z "$pid"; ten + log_action_end_msg 0 "not running - there is no $COFFINPID" + exit 0 + fi + + if start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON; then + wait-for-dead-daemon $pid + elif kill -0 $pid 2>/dev/null; then + log_action_end_msg 1 "is $pid not $NAME? is $DAEMON a different binary now?" + exit 1 + else + log_action_end_msg 1 "$DAEMON died: process $pid not running; or permission denied" + exit 1 + fi + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; +esac + +exit 0 + +# vim: syntax=sh ts=4 sw=4 sts=4 sr noet