#!/bin/sh # # Copyright (c) 2003-2010 Jeremy Kister # Author: Jeremy Kister # Date: 2010-Aug-05 23:10 (EDT) # Function: client to naimd # # take a look at http://jeremy.kister.net./ PATH=/usr/bin:/usr/ucb:/bin:$PATH if [ ! -d /var/naim/queue ] ; then echo "no naim/queue found - start naimd first"; exit 1 fi diroid="`ls -ld /var/naim/queue/ 2>/dev/null | awk '{ print $3 }'`"; if [ "$diroid" != `whoami` ] ; then echo "oops, we're not running as $diroid"; exit 1 fi recipients=$1 idno=$2 if [ -z "$recipients" -o -z "$idno" ] ; then echo "syntax error: $0 " exit 1 else # limit most errors - "1+1", "3.2" as an arg would succeed result=`echo "$idno + 0" | bc 2>/dev/null` if [ "$result" != "$idno" ] ; then echo "ID must be an integer: [$idno]" exit 1 fi fi scrubbed="`echo $recipients | tr '[A-Z]' '[a-z]' | sed 's/\ //g'`" if [ ! -d "/var/naim/queue/tmp/" ] ; then mkdir -p /var/naim/queue/tmp/ fi while read line ; do echo "$line" >> /var/naim/queue/tmp/$idno.$$ done hup=0 for recipient in `echo $scrubbed | sed 's/,/ /g'` ; do if [ ! -d "/var/naim/queue/$recipient/tmp/" ] ; then mkdir -p /var/naim/queue/$recipient/tmp/ if [ $? -ne 0 ] ; then echo "could not make dir: /var/naim/queue/$recipient/tmp" exit 1; fi fi if [ -f /var/naim/queue/$recipient/$idno.$$ ] ; then echo "pageid $idno already in queue for $recipient - ignoring" # username,user2,username hup=1 # just in case else cp /var/naim/queue/tmp/$idno.$$ /var/naim/queue/$recipient/tmp/$idno.$$ if [ $? -eq 0 ] ; then mv /var/naim/queue/$recipient/tmp/$idno.$$ /var/naim/queue/$recipient/$idno.$$ if [ $? -eq 0 ] ; then hup=1 else echo "could not mv /var/naim/queue/$recipient/tmp/$idno.$$ /var/naim/queue/$recipient/$idno.$$" fi else echo "could not write to /var/naim/queue/$recipient/tmp/$idno.$$" fi fi done rm /var/naim/queue/tmp/$idno.$$ if [ "$hup" = 1 ] ; then pid="`head -1 /var/run/naimd/child.pid`" if [ $pid -gt 1 ] ; then kill -USR1 $pid if [ $? -ne 0 ] ; then echo "could not HUP pid $pid" exit 1 fi else echo "/var/run/naimd/child.pid contains invalid looking pid: [$pid]" exit 1 fi fi