#!/bin/bash

#
# okerr client script
#

#
# DO NOT EDIT THIS FILE
# 
# edit local settings file
#
#
# settings files. you can write settings there
# (but can edit this file for simplicity)
#

settings="/etc/default/okerrclient /etc/sysconfig/okerrclient"

#
# default values 
# (overriden by settings in settings files)
#
# copy this block to your local settings file (one of listed above)
#

# LOCAL SETTINGS:

textid='setyours'
myname=`hostname`
keypath='servers:$myname|conf:anyserver'
keyuser='client'
keypass='yourpass'
safebins="dpkg dig uname"
readfiles=""
customscript="/usr/local/bin/okerr-local" # optional, no problem if it's missing
ocbin='/usr/local/bin/okerrclient'
verbose="" # "" or "-v" for verbosity
secret="nosecret"

# END OF LOCAL SETTINGS


for sfile in $settings
do
    if [ -r $sfile ]
    then
        . $sfile
    fi
done

if [ ! -x "$ocbin" ]
then
    echo "not found okerr-client script"
    exit 1 
fi


#
# build safebin args for RUN processor
#

tpconf_args="--tpconf"

for bin in $safebins
do
   tpconf_args="$tpconf_args RUN:safebin=$bin"
done

for rf in $readfiles
do
    tpconf_args="$tpconf_args FILE:read=$rf"
done

#
# code
#

ocargs="$verbose -i $textid $tpconf_args"



# add optional args
if [ ! -z "$keyuser" ]
then
    ocargs="$ocargs --keyuser $keyuser"
fi

if [ ! -z "$keypass" ]
then
    ocargs="$ocargs --keypass $keypass"
fi

if [ ! -z "$secret" ]
then
    ocargs="$ocargs -S $secret"
fi

if [ ! -z "$local_args" ]
then
    ocargs="$ocargs $local_args"
fi


$ocbin $ocargs -s "NAME $myname" "MKSEQ $keypath"


#
# execute custom checks
#

if [ -x $customscript ]
then
    . $customscript
fi


