annna-stop - annna - Annna the nice friendly bot.
HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
---
annna-stop (1414B)
---
1 #!/bin/sh
2 #
3 # Dare you to execute this script! You are cruel!
4 #
5
6 [ -z "${ANNNA_BASE}" ] && printf "Please set \$ANNNA_BASE.\n" >&2 && exit 1
7 [ ! -d "${ANNNA_BASE}" ] && printf "%s not a directory.\n" "${ANNNA_BASE}" >&2 && exit 1
8
9 [ ! -e "${ANNNA_BASE}/binbase" ] && printf "No /binbase exists.\n" >&2 && exit 1
10 export ANNNA_BINBASE="$(cat "${ANNNA_BASE}/binbase")"
11 [ ! -d "${ANNNA_BINBASE}" ] && printf "%s not a directory.\n" "${ANNNA_BINBASE}" >&2 && exit 1
12
13 [ ! -e "${ANNNA_BASE}/ircbase" ] && printf "No /ircbase exists.\n" >&2 && exit 1
14 export ANNNA_IRCBASE="$(cat "${ANNNA_BASE}/ircbase")"
15 [ ! -d "${ANNNA_IRCBASE}" ] && printf "%s not a directory.\n" "${ANNNA_IRCBASE}" >&2 && exit 1
16
17 export PATH="$PATH:${ANNNA_BINBASE}"
18
19 cd "${ANNNA_BASE}"
20 if [ $# -gt 1 ];
21 then
22 if [ "$1" = "-h" ];
23 then
24 printf "usage: %s [server ...]\n" "$(basename "$0")" >&2
25 exit 1
26 fi
27 servers="$@"
28 else
29 servers="$(find . -maxdepth 1 -type d | cut -c 3-)"
30 fi
31 for server in ${servers};
32 do
33 [ -z "${server}" ] && continue
34 pidfile="${server}.pid"
35 [ ! -f "${pidfile}" ] && continue
36 serverpid="$(cat "${pidfile}")"
37 [ -z "${serverpid}" ] && continue
38 if kill -0 "${serverpid}";
39 then
40 pkill -P "${serverpid}"
41 kill -KILL "${serverpid}"
42 fi
43 rm "${pidfile}"
44 rm -rf "${ANNNA_IRCBASE}/${server}"
45 done
46
47 # Nothing is left running, so annna running can be removed.
48 [ -z "$(find . -maxdepth 1 -type f -name "*.pid")" ] && annna-die
49