diff options
-rw-r--r-- | config.bash | 3 | ||||
-rwxr-xr-x | ircbot.bash | 23 |
2 files changed, 24 insertions, 2 deletions
diff --git a/config.bash b/config.bash index 645c367..5c9f62a 100644 --- a/config.bash +++ b/config.bash @@ -10,6 +10,9 @@ IRCBOT_HOST=irc.example.net # IRC server port IRCBOT_PORT=6667 +# set to 1 to use TLS +IRCBOT_TLS=1 + # bot nick IRCBOT_NICK=sedbot 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 "$@" |