Add doall.sh configuration helper
This commit is contained in:
27
deploy/README.md
Normal file
27
deploy/README.md
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Convenience tool
|
||||||
|
|
||||||
|
This tool reads a CSV and sets all TimeSpecs found. How to use:
|
||||||
|
1) edit config.csv and edit the last column in the CSV (a TimeSpec in UTC)
|
||||||
|
2) run ./doall.sh -q get > old.csv
|
||||||
|
3) diff -u old.csv config.csv
|
||||||
|
4) run ./doall.sh set
|
||||||
|
and check the output
|
||||||
|
5) run ./doall.sh -f set
|
||||||
|
6) Check in the new config.csv
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```
|
||||||
|
# Generated on Sun Mar 31 13:03:21 CEST 2019
|
||||||
|
# Device,IPv4,Chan,Name,TimeSpec(UTC)
|
||||||
|
esp8266_808501,192.168.9.7,0,Heli Basking Light,06:45:00-18:30:00
|
||||||
|
esp8266_808501,192.168.9.7,1,Heli UV Light,07:00:00-18:15:00
|
||||||
|
esp8266_052EE8,192.168.9.12,0,Heli Red/White LED,06:30:00-18:45:00
|
||||||
|
esp8266_052FB1,192.168.9.13,0,Heli Blue LED,22:00:00-04:00:00
|
||||||
|
esp8266_807AAD,192.168.9.8,0,Sticky Basking Light,06:45:00-18:30:00
|
||||||
|
esp8266_807AAD,192.168.9.8,1,Sticky UV Light,07:00:00-18:15:00
|
||||||
|
esp8266_202936,192.168.9.10,0,Sticky Red/White LED,06:30:00-18:45:00
|
||||||
|
esp8266_053F26,192.168.9.11,0,Sticky Blue LED,22:00:00-04:00:00
|
||||||
|
esp8266_807AAD,192.168.9.8,2,Sticky Fogging,17:02:00-17:22:00
|
||||||
|
esp8266_807AAD,192.168.9.8,3,Sticky Raining,17:15:00-17:15:15
|
||||||
|
```
|
12
deploy/config.csv
Normal file
12
deploy/config.csv
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Generated on Sun Mar 31 13:03:21 CEST 2019
|
||||||
|
# Device,IPv4,Chan,Name,TimeSpec(UTC)
|
||||||
|
esp8266_808501,192.168.9.7,0,Heli Basking Light,06:45:00-18:30:00
|
||||||
|
esp8266_808501,192.168.9.7,1,Heli UV Light,07:00:00-18:15:00
|
||||||
|
esp8266_052EE8,192.168.9.12,0,Heli Red/White LED,06:30:00-18:45:00
|
||||||
|
esp8266_052FB1,192.168.9.13,0,Heli Blue LED,22:00:00-04:00:00
|
||||||
|
esp8266_807AAD,192.168.9.8,0,Sticky Basking Light,06:45:00-18:30:00
|
||||||
|
esp8266_807AAD,192.168.9.8,1,Sticky UV Light,07:00:00-18:15:00
|
||||||
|
esp8266_202936,192.168.9.10,0,Sticky Red/White LED,06:30:00-18:45:00
|
||||||
|
esp8266_053F26,192.168.9.11,0,Sticky Blue LED,22:00:00-04:00:00
|
||||||
|
esp8266_807AAD,192.168.9.8,2,Sticky Fogging,17:02:00-17:22:00
|
||||||
|
esp8266_807AAD,192.168.9.8,3,Sticky Raining,17:15:00-17:15:15
|
|
104
deploy/doall.sh
Executable file
104
deploy/doall.sh
Executable file
@ -0,0 +1,104 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
[ -n "$1" ] && {
|
||||||
|
echo $1
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
echo "Usage:"
|
||||||
|
echo "$0 [-csv <file>] [-f] [-q] get|set"
|
||||||
|
echo "Using Input CSV file given by -csv argument, either get all channel info, or set all channel info."
|
||||||
|
echo "If not given, the file config.csv in the working directory is chosen"
|
||||||
|
echo "Setting -f (force) will call the RPCs, without it, only print what would be sent"
|
||||||
|
echo "Setting -q (quiet) will only output the CSV and errors"
|
||||||
|
echo ""
|
||||||
|
exit -1
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
[ $QUIET -eq 1 ] && return
|
||||||
|
echo "# $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
doget() {
|
||||||
|
echo "# Generated on $(date)"
|
||||||
|
echo "# Device,IPv4,Chan,Name,TimeSpec(UTC)"
|
||||||
|
while IFS=, read -r dev ip chan name timespec
|
||||||
|
do
|
||||||
|
[ "${dev:0:1}" == "#" ] && continue
|
||||||
|
cmd="mos --port ws://$ip/rpc call TimeSpec.Get '{\"idx\": $chan }'"
|
||||||
|
log "$cmd"
|
||||||
|
SPEC=$(eval $cmd | awk '/spec/ { print $2 }' | sed -e 's,",,g')
|
||||||
|
echo "$dev,$ip,$chan,$name,$SPEC"
|
||||||
|
done < $CONFIG
|
||||||
|
}
|
||||||
|
|
||||||
|
doset() {
|
||||||
|
# Device,IPv4,Chan,Name,TimeSpec(UTC)
|
||||||
|
while IFS=, read -r dev ip chan name timespec
|
||||||
|
do
|
||||||
|
[ "${dev:0:1}" == "#" ] && continue
|
||||||
|
|
||||||
|
cmd="mos --port ws://$ip/rpc call TimeSpec.Clear '{\"idx\": $chan }'"
|
||||||
|
log "$cmd"
|
||||||
|
[ $FORCE -ne 0 ] && {
|
||||||
|
eval $cmd
|
||||||
|
}
|
||||||
|
cmd="mos --port ws://$ip/rpc call TimeSpec.Add '{\"idx\": $chan, \"spec\": \"$timespec\" }'"
|
||||||
|
log "$cmd"
|
||||||
|
[ $FORCE -ne 0 ] && {
|
||||||
|
eval $cmd
|
||||||
|
}
|
||||||
|
done < $CONFIG
|
||||||
|
}
|
||||||
|
|
||||||
|
VERB="get"
|
||||||
|
CONFIG="config.csv"
|
||||||
|
FORCE=0
|
||||||
|
QUIET=0
|
||||||
|
|
||||||
|
while [ $# -ne 0 ]; do
|
||||||
|
case $1 in
|
||||||
|
-f)
|
||||||
|
FORCE=1
|
||||||
|
;;
|
||||||
|
-q)
|
||||||
|
QUIET=1
|
||||||
|
;;
|
||||||
|
-csv)
|
||||||
|
shift
|
||||||
|
CONFIG=$1
|
||||||
|
;;
|
||||||
|
get)
|
||||||
|
VERB="get"
|
||||||
|
;;
|
||||||
|
set)
|
||||||
|
VERB="set"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage "Unknown commandline flag '$1'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
[ ! -r $CONFIG ] && {
|
||||||
|
echo "Cannot open file '$CONFIG'"
|
||||||
|
exit -2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case $VERB in
|
||||||
|
get)
|
||||||
|
doget
|
||||||
|
;;
|
||||||
|
set)
|
||||||
|
doset
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown verb: $VERB"
|
||||||
|
exit -3;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
Reference in New Issue
Block a user