From 50b37674ff166df1765545fcc170950f855393d3 Mon Sep 17 00:00:00 2001 From: starcalc Date: Thu, 8 Sep 2022 20:07:10 +0200 Subject: [PATCH] Automatic update all hosts --- .drone.yml | 71 +++++++++++++++++++++++--------------------------- configurefs.sh | 16 ++++++++++++ hosts | 2 ++ uploadfs.sh | 11 ++++++++ 4 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 configurefs.sh create mode 100644 hosts create mode 100644 uploadfs.sh diff --git a/.drone.yml b/.drone.yml index 30c9e46..ad9297a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,54 +1,47 @@ --- + kind: pipeline type: docker name: default steps: - - name: fetch ip + - name: fetch ips image: cburki/mosquitto-clients commands: - - echo "$hostname" - - mosquitto_sub -h raum.ctdo.de -t "homie/$hostname/\$localip" -C 1 | tr -d '\n' - - mosquitto_sub -h raum.ctdo.de -t "homie/$hostname/\$localip" -C 1 | tr -d '\n' >lastknownip - - cat "lastknownip" - environment: - hostname: - from_secret: hostname - - name: configure - image: alpine - commands: - - sed -i "s/WIFISSID/$IOTSSID/" data/homie/config.json - - sed -i "s/WIFIPASS/$iotpwd/" data/homie/config.json - - sed -i "s/HOSTNAME/$hostname/g" data/homie/config.json - - sed -i "s/HOSTNAME/$hostname/g" data/homie/config.json - - lastknownip=$(cat lastknownip) - - sed -i "s/HOSTNAME/$lastknownip/g" platformio.ini - environment: - hostname: - from_secret: hostname - IOTSSID: - from_secret: iotssid - iotpwd: - from_secret: iotpwd + - rm -f lastknownhostips + - cat hosts + - for h in $(cat hosts); do echo $h; echo $h; done + - for h in $(cat hosts); do mosquitto_sub -h raum.ctdo.de -t "homie/$h/\$localip" -C 1; done >lastknownips + - for h in $(cat hosts); do echo -n "$h," >>lastknownhostips; mosquitto_sub -h raum.ctdo.de -t "homie/$h/\$localip" -C 1 >>lastknownhostips; done + - cat lastknownhostips + - cat lastknownips - name: build image: suculent/platformio-docker-build commands: - # - pip install -U platformio - # Build image + # Build images - platformio run --environment d1_mini - # Build file system image - - platformio run --target buildfs --environment d1_mini - - name: upload + - | + chmod u+x ./configurefs.sh + chmod u+x ./uploadfs.sh + ./configurefs.sh + - name: upload image image: curlimages/curl commands: - - lastknownip=$(cat lastknownip) - - echo "$lastknownip" # Upload image with espota-gateway + # All hosts receive the identical image - | - curl --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$lastknownip" --form firmware=@.pio/build/d1_mini/firmware.bin --no-buffer - # TODO: Upload file system image with espota-gateway, if the device is available again (or leave it to espota-gateway to retry often enough) - - | - curl --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$lastknownip" --form spiffs=@.pio/build/d1_mini/spiffs.bin --no-buffer - -### matrix-builds? - for multiple volumeknobs? -### https://0-8-0.docs.drone.io/matrix-builds/ -### + cat lastknownips + for thisip in $(cat lastknownips) + do + echo "Current IP to upload is $thisip" + curl -m 180 --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$thisip" --form firmware=@.pio/build/d1_mini/firmware.bin --no-buffer + done + - name: upload configs + image: curlimages/curl + commands: + - ls -lA . + - /bin/sh ./uploadfs.sh + environment: + IOTSSID: + from_secret: iotssid + iotpwd: + from_secret: iotpwd diff --git a/configurefs.sh b/configurefs.sh new file mode 100644 index 0000000..e1c01de --- /dev/null +++ b/configurefs.sh @@ -0,0 +1,16 @@ +#!/bin/bash +while IFS="," read -r curhost curip +do + echo "Host ${curhost} and IP ${curip}" + cp data/homie/config.json data/homie/config.json.sample + sed -i "s/WIFISSID/$IOTSSID/" data/homie/config.json + sed -i "s/WIFIPASS/$iotpwd/" data/homie/config.json + sed -i "s/HOSTNAME/${curhost}/g" data/homie/config.json + sed -i "s/HOSTNAME/${curhost}/g" data/homie/config.json + # Build image with these parameters + platformio run --target buildfs --environment d1_mini + # Save this image + cp .pio/build/d1_mini/spiffs.bin .pio/build/d1_mini/spiffs_${curhost}.bin + # Revert config.json + cp data/homie/config.json.sample data/homie/config.json +done < <(cat lastknownhostips) \ No newline at end of file diff --git a/hosts b/hosts new file mode 100644 index 0000000..3898d98 --- /dev/null +++ b/hosts @@ -0,0 +1,2 @@ +volumeknob2 +volumeknob3 \ No newline at end of file diff --git a/uploadfs.sh b/uploadfs.sh new file mode 100644 index 0000000..012877e --- /dev/null +++ b/uploadfs.sh @@ -0,0 +1,11 @@ +#!/bin/sh +echo "Running" +while read line +do + echo "Line is ${line}" + curhost=$(echo ${line} | cut -d ',' -f1) + curip=$(echo ${line} | cut -d ',' -f2) + echo "Host ${curhost} and IP ${curip}" + # Upload this image + curl -m 180 --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$curip" --form spiffs=@.pio/build/d1_mini/spiffs_${curhost}.bin --no-buffer +done < <(cat lastknownhostips)