Files
addons/rpc_shutdown/run.sh
Pascal Vizeli e8fa8aa5c8 Update New CLI (#500)
* Update New CLI

* Fix shell

* ssh: Include hassio bash completion (#501)
2019-01-09 13:59:44 +01:00

31 lines
918 B
Bash
Executable File

#!/bin/bash
set -e
CONFIG_PATH=/data/options.json
COMPUTERS=$(jq --raw-output '.computers | length' $CONFIG_PATH)
# Read from STDIN aliases to send shutdown
while read -r input; do
# remove json stuff
input="$(echo "$input" | jq --raw-output '.')"
echo "[Info] Read alias: $input"
# Find aliases -> computer
for (( i=0; i < "$COMPUTERS"; i++ )); do
ALIAS=$(jq --raw-output ".computers[$i].alias" $CONFIG_PATH)
ADDRESS=$(jq --raw-output ".computers[$i].address" $CONFIG_PATH)
CREDENTIALS=$(jq --raw-output ".computers[$i].credentials" $CONFIG_PATH)
# Not the correct alias
if [ "$ALIAS" != "$input" ]; then
continue
fi
echo "[Info] Shutdown $input -> $ADDRESS"
if ! msg="$(net rpc shutdown -I "$ADDRESS" -U "$CREDENTIALS")"; then
echo "[Error] Shutdown fails -> $msg"
fi
done
done