diff --git a/abusehelper/files/botnet.init b/abusehelper/files/botnet.init index 01f2466..c22a0c5 100644 --- a/abusehelper/files/botnet.init +++ b/abusehelper/files/botnet.init @@ -35,30 +35,41 @@ if [ -z "${BOTNETS}" ]; then exit 1 fi +botnet_action() { + action="$1" + botnet="$2" + + echo -n "${botnet}: " + + if [ -d ${botnet} ]; then + startup="." + elif [ -f ${botnet} ]; then + startup="$(basename ${botnet})" + botnet="$(dirname ${botnet})" + else + echo "No such file or directory." + return 1 + fi + + su -s /bin/sh - ${BOTUSER} \ + -c "umask 007 ; cd ${botnet} && botnet ${action} ${startup}" +} + start_botnets() { for botnet in ${BOTNETS}; do - echo -n "${botnet}: " - test -d ${botnet} || { echo "No such directory."; continue; } - su -s /bin/sh - ${BOTUSER} \ - -c "umask 007 ; cd ${botnet} && botnet start ." + botnet_action start ${botnet} done } stop_botnets() { for botnet in ${BOTNETS}; do - echo -n "${botnet}: " - test -d ${botnet} || { echo "No such directory."; continue; } - su -s /bin/sh - ${BOTUSER} \ - -c "umask 007 ; cd ${botnet} && botnet stop ." + botnet_action stop ${botnet} done } restart_botnets() { for botnet in ${BOTNETS}; do - echo -n "${botnet}: " - test -d ${botnet} || { echo "No such directory."; continue; } - su -s /bin/sh - ${BOTUSER} \ - -c "umask 007 ; cd ${botnet} && botnet restart ." + botnet_action restart ${botnet} done }