diff --git a/playbooks/mqtt.yml b/playbooks/mqtt.yml index 6c92d03..5b29de0 100644 --- a/playbooks/mqtt.yml +++ b/playbooks/mqtt.yml @@ -16,3 +16,4 @@ - nginx - role: nginx_site nginx_site_name: iot.foo.sh + - shelly_firmware diff --git a/roles/shelly_firmware/files/download-shelly-firmware.sh b/roles/shelly_firmware/files/download-shelly-firmware.sh new file mode 100644 index 0000000..608b156 --- /dev/null +++ b/roles/shelly_firmware/files/download-shelly-firmware.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +umask 022 + +cd /srv/web/iot.foo.sh/shelly + +PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" + +URL="http://archive.shelly-tools.de/" + +for _prod in $(curl -sSf "${URL}/archive.php" | jq -r '.[].type') ; do + _ver="$(curl -sSf "${URL}/archive.php?type=${_prod}" | jq -r \ + 'max_by(.version[1:] | split(".") | map(try tonumber catch 0)) .version')" + _name="$(curl -sSf "${URL}/archive.php?type=${_prod}" | jq -r \ + 'limit(1; .[].file)')" + if [ ! -f "${_prod}.${_ver}.zip" ]; then + echo "New firmware for ${_prod} (version ${_ver})" + curl -sSf -o "${_prod}.${_ver}.zip" "${URL}/version/${_ver}/${_name}" + if [ -h "$_name" ]; then + rm -f "$_name" + fi + ln -s "${_prod}.${_ver}.zip" "$_name" + fi +done diff --git a/roles/shelly_firmware/tasks/main.yml b/roles/shelly_firmware/tasks/main.yml new file mode 100644 index 0000000..2d1dd3a --- /dev/null +++ b/roles/shelly_firmware/tasks/main.yml @@ -0,0 +1,28 @@ +--- +- name: Install dependencies + ansible.builtin.package: + name: jq + state: installed + +- name: Create download directory + ansible.builtin.file: + path: /srv/web/iot.foo.sh/shelly + state: directory + mode: 0755 + owner: root + group: "{{ ansible_wheel }}" + +- name: Install download script + ansible.builtin.copy: + dest: /usr/local/bin/download-shelly-firmware + src: download-shelly-firmware.sh + mode: 0755 + owner: root + group: "{{ ansible_wheel }}" + +- name: Install cron job + ansible.builtin.cron: + name: download-shelly-firmware + job: /usr/local/bin/download-shelly-firmware + hour: "05" + minute: 20