#!/bin/bash # This is a simple daemon shell script. # # Traps: # signal HUP (1) read config file again # signal QUIT (3) delete temp files # signal TERM (15) delete temp files # variables CONFFILE=/etc/cpkg-daemon/cpkg.conf LLX_COMMONLIB="/usr/share/lliurex/llxcfg-common/llxcfg-common.sh" [ -f "${LLX_COMMONLIB}" ] || exit 1 . ${LLX_COMMONLIB}A [ -x "$CPKG_BACKEND" ] || exit 1 # functions create_pipe(){ # this code must go on the postinstall mkdir -p "$(dirname "$CPKG_PIPE")" if [ ! -p "$CPKG_PIPE" ] ; then rm -f "$CPKG_PIPE" mkfifo -m $LLXCFG_MODE "$CPKG_PIPE" fi chgrp $LLXCFG_GROUP "$CPKG_PIPE" [ ! -p "$CPKG_PIPE" ] && return 1 return 0 } end_daemon(){ rm -f $PID_FILE exit 0 } # main # load conffile [ -f "$CONFFILE" ] && source "$CONFFILE" create_pipe if [ "$1" = "--pidfile" -a "$2" ] ;then touch "$2" &> /dev/null || true [ -f "$2" ] && PID_FILE="$2" fi echo "$$" > "$PID_FILE" # set traps trap '[ -f "$CONFFILE" ] && source "$CONFFILE"' 1 trap 'end_daemon' 0 trap 'end_daemon' 3 trap 'end_daemon' 15 # loop forever # (avoid 'cat ..|while read .. ' due to subshell problems when running in background) while : do read line < "$CPKG_PIPE" if [ "$line" ] ; then $CPKG_BACKEND $line || true fi done