From 2d22a6e769ff31386fa11b7c1e605fa61bd59a10 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Wed, 26 Oct 2022 19:11:16 +0200 Subject: [PATCH] services: Add flipdot --- roles/services/defaults/main.yaml | 2 ++ roles/services/handlers/main.yaml | 6 +++++ roles/services/tasks/flipdot.yaml | 28 ++++++++++++++++++++++ roles/services/tasks/main.yaml | 3 +++ roles/services/templates/flipdot-reboot.sh | 4 ++++ roles/services/templates/flipdot-time.sh | 25 +++++++++++++++++++ roles/services/templates/flipdot.service | 16 +++++++++++++ 7 files changed, 84 insertions(+) create mode 100644 roles/services/defaults/main.yaml create mode 100644 roles/services/tasks/flipdot.yaml create mode 100644 roles/services/templates/flipdot-reboot.sh create mode 100644 roles/services/templates/flipdot-time.sh create mode 100644 roles/services/templates/flipdot.service diff --git a/roles/services/defaults/main.yaml b/roles/services/defaults/main.yaml new file mode 100644 index 0000000..6143a15 --- /dev/null +++ b/roles/services/defaults/main.yaml @@ -0,0 +1,2 @@ +flipdot_host: 100.64.0.90 +flipdot_powebar_num: 3 diff --git a/roles/services/handlers/main.yaml b/roles/services/handlers/main.yaml index be55cc7..f96a29d 100644 --- a/roles/services/handlers/main.yaml +++ b/roles/services/handlers/main.yaml @@ -7,6 +7,12 @@ state: restarted daemon_reload: true +- name: restart flipdot + systemd: + name: flipdot + state: restarted + daemon_reload: true + - name: restart siahsd systemd: name: siahsd diff --git a/roles/services/tasks/flipdot.yaml b/roles/services/tasks/flipdot.yaml new file mode 100644 index 0000000..48d3674 --- /dev/null +++ b/roles/services/tasks/flipdot.yaml @@ -0,0 +1,28 @@ +--- +- name: Install flipdot scripts + template: + src: "{{ item }}" + dest: "/usr/local/bin/{{ item }}" + owner: root + group: root + mode: 0755 + notify: restart flipdot + with_items: + - flipdot-reboot.sh + - flipdot-time.sh + +- name: Install flipdot service + template: + src: flipdot.service + dest: /etc/systemd/system/flipdot.service + owner: root + group: root + mode: 0644 + notify: restart flipdot + +- name: Start flipdot + systemd: + name: flipdot + state: started + enabled: yes + daemon_reload: true diff --git a/roles/services/tasks/main.yaml b/roles/services/tasks/main.yaml index 621d051..dac2dcf 100644 --- a/roles/services/tasks/main.yaml +++ b/roles/services/tasks/main.yaml @@ -1,4 +1,7 @@ --- +- tags: services_flipdot + import_tasks: flipdot.yaml + - tags: services_siahsd import_tasks: siahsd.yaml diff --git a/roles/services/templates/flipdot-reboot.sh b/roles/services/templates/flipdot-reboot.sh new file mode 100644 index 0000000..8897c08 --- /dev/null +++ b/roles/services/templates/flipdot-reboot.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +powerbar-switch {{ flipdot_powebar_num }} off +powerbar-switch {{ flipdot_powebar_num }} on diff --git a/roles/services/templates/flipdot-time.sh b/roles/services/templates/flipdot-time.sh new file mode 100644 index 0000000..30943c8 --- /dev/null +++ b/roles/services/templates/flipdot-time.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Managed by Ansible + +set -eu + +HOST={{ flipdot_host }} + +while true; do + time=`date +%H:%M` + tmp=/tmp/flipdot.gray + + convert -size 336x16 xc:black -density 800x240 -font Liberation-Mono -pointsize 6 -fill white -gravity Center -annotate +0+1 `date +%H:%M` -draw "line 0,15,$(((`date +1%S`-100)*56/10)),15" -depth 8 $tmp + (echo -ne "\x00\x00\x15\x00" ; dd if=$tmp bs=5376 count=1 2>/dev/null) | nc -q1 -w1 $HOST 7890 + sleep 1 + convert -size 336x16 xc:black -density 800x240 -font Liberation-Mono -pointsize 6 -fill white -gravity Center -annotate +0+1 "`date "+%H %M"`" -draw "line 0,15,$(((`date +1%S`-100)*56/10)),15" -depth 8 $tmp + (echo -ne "\x00\x00\x15\x00" ; dd if=$tmp bs=5376 count=1 2>/dev/null) | nc -q1 -w1 $HOST 7890 + sleep 1 + + if [ $time != `date +%H:%M` ] + then + convert -size 336x16 xc:white -density 800x240 -font Liberation-Mono -pointsize 6 -fill black -gravity Center -annotate +0+1 `date +%H:%M` -depth 8 $tmp; (echo -ne "\x00\x00\x15\x00" ; dd if=$tmp bs=5376 count=1 2>/dev/null) | nc -q1 -w1 $HOST 7890 + sleep 2 + fi +done diff --git a/roles/services/templates/flipdot.service b/roles/services/templates/flipdot.service new file mode 100644 index 0000000..0146c0d --- /dev/null +++ b/roles/services/templates/flipdot.service @@ -0,0 +1,16 @@ +# Managed by Ansible + +[Unit] +Description=Big flipdot display +After=network.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/flipdot-time.sh +ExecStopPost=/usr/local/bin/flipdot-reboot.sh +Restart=on-failure +RestartSec=30s +DynamicUser=true + +[Install] +WantedBy=multi-user.target