diff --git a/roles/services/handlers/main.yaml b/roles/services/handlers/main.yaml index 30f7392..ba797c1 100644 --- a/roles/services/handlers/main.yaml +++ b/roles/services/handlers/main.yaml @@ -13,6 +13,12 @@ state: restarted daemon_reload: true +- name: restart irc-doorduino + systemd: + name: irc-doorduino + state: restarted + daemon_reload: true + - name: restart discord-bot systemd: name: discord-bot diff --git a/roles/services/tasks/ircbot.yaml b/roles/services/tasks/ircbot.yaml index 3a75eb4..ce9eeb0 100644 --- a/roles/services/tasks/ircbot.yaml +++ b/roles/services/tasks/ircbot.yaml @@ -58,3 +58,28 @@ state: started enabled: yes daemon_reload: true + +- name: Install doorduino notification + template: + src: irc-doorduino.sh + dest: /var/lib/irc-helpers/doorduino.sh + owner: root + group: root + mode: 0755 + notify: restart irc-doorduino + +- name: Install doorduino notification service + template: + src: irc-doorduino.service + dest: /etc/systemd/system/irc-doorduino.service + owner: root + group: root + mode: 0644 + notify: restart irc-doorduino + +- name: Start irc-doorduino + systemd: + name: irc-doorduino + state: started + enabled: yes + daemon_reload: true diff --git a/roles/services/templates/irc-doorduino.service b/roles/services/templates/irc-doorduino.service new file mode 100644 index 0000000..f5f6d5a --- /dev/null +++ b/roles/services/templates/irc-doorduino.service @@ -0,0 +1,16 @@ +# Managed by Ansible + +[Unit] +Description=Bitlair IRC doorduino notification +After=network.target +Requires=irc-bot.service + +[Service] +Type=simple +ExecStart=/bin/bash /var/lib/irc-helpers/doorduino.sh +Restart=on-failure +RestartSec=10s +DynamicUser=true + +[Install] +WantedBy=multi-user.target diff --git a/roles/services/templates/irc-doorduino.sh b/roles/services/templates/irc-doorduino.sh new file mode 100644 index 0000000..29e0eea --- /dev/null +++ b/roles/services/templates/irc-doorduino.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Managed by Ansible + +set -eu +set -o pipefail + +initial=1 + +mqtt-simple -h {{ mqtt_internal_host }} -t "bitlair/doorduino/+" | + while read line; do + topic=$(echo "$line" | cut -d' ' -f1 | sed "s/bitlair\/doorduino\///") + value=$(echo "$line" | cut -s -d' ' -f2-) + + if [ $initial == 0 ] && [ $value != 0 ]; then + if [ $topic == "doorbell" ]; then + irc-say "DEURBEL! Open de deur beneden!" + elif [ $topic != "dooropen" ]; then + irc-say "Doorduino: $topic $value" + fi + fi + initial=0 + done +