summaryrefslogtreecommitdiffstats
path: root/ircbot.bash
diff options
context:
space:
mode:
Diffstat (limited to 'ircbot.bash')
-rwxr-xr-xircbot.bash23
1 files changed, 21 insertions, 2 deletions
diff --git a/ircbot.bash b/ircbot.bash
index 646c4da..e3fc56a 100755
--- a/ircbot.bash
+++ b/ircbot.bash
@@ -66,6 +66,8 @@ IRCBOT_MODULE=ircbot
_events=(connect disconnect readmsg sendmsg privmsg dm ctcp self_join self_kick self_part self_invite)
+_ircbot_cleanup=()
+
verbose() {
if [ -n "$IRCBOT_VERBOSE" ] && [ "$IRCBOT_VERBOSE" -ne 0 ]; then
printf "[%s] $1\n" "$IRCBOT_MODULE" "${@:2}" >&2
@@ -73,8 +75,17 @@ verbose() {
}
connect() {
- if ! exec {_ircbot_fd}<>"/dev/tcp/$IRCBOT_HOST/$IRCBOT_PORT"; then
- return $?
+ if [[ "$IRCBOT_TLS" -ne 0 ]]; then
+ local fifo
+ fifo="$(mktemp -u --tmpdir "ircbot.XXXXXX.fifo")" || return $?
+ mkfifo "$fifo" || return $?
+ _ircbot_cleanup+=("$fifo")
+ openssl s_client -quiet -connect "$IRCBOT_HOST:$IRCBOT_PORT" <"$fifo" >"$fifo" &
+ exec {_ircbot_fd}<>"$fifo"
+ else
+ if ! exec {_ircbot_fd}<>"/dev/tcp/$IRCBOT_HOST/$IRCBOT_PORT"; then
+ return $?
+ fi
fi
if [[ -n "$IRCBOT_PASS" ]]; then
@@ -410,6 +421,14 @@ _main() { # args: $1 - config file
verbose 'reconnecting in %d seconds...' "${IRCBOT_SLEEP_RECONNECT:-10}"
sleep "${IRCBOT_SLEEP_RECONNECT:-10}"
done
+ _cleanup
+}
+
+_cleanup() {
+ local f
+ for f in "${_ircbot_cleanup[@]}"; do
+ rm -f "$f"
+ done
}
_main "$@"