mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 21:24:20 +01:00
* rpc_shutdown: Prettier YAML files * rpc_shutdown: Move run.sh to data folder * rpc_shutdown: Documentation tweaks * rpc_shutdown: Update add-on URL & Description
33 lines
1.1 KiB
Bash
Executable File
33 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bashio
|
|
set -e
|
|
|
|
# Read from STDIN aliases to send shutdown
|
|
while read -r input; do
|
|
# parse JSON value
|
|
input=$(bashio::jq "${input}" '.')
|
|
bashio::log.info "Read alias: $input"
|
|
|
|
# Find aliases -> computer
|
|
for computer in $(bashio::config 'computers|keys'); do
|
|
ALIAS=$(bashio::config "computers[${computer}].alias")
|
|
ADDRESS=$(bashio::config "computers[${computer}].address")
|
|
CREDENTIALS=$(bashio::config "computers[${computer}].credentials")
|
|
DELAY=$(bashio::config "computers[${computer}].delay")
|
|
MESSAGE=$(bashio::config "computers[${computer}].message")
|
|
|
|
# Not the correct alias
|
|
if ! bashio::var.equals "$ALIAS" "$input"; then
|
|
continue
|
|
fi
|
|
|
|
# Check if delay is not empty
|
|
if bashio::var.equals "$DELAY" "null"; then
|
|
DELAY="0"
|
|
fi
|
|
|
|
bashio::log.info "Shutdown $input -> $ADDRESS"
|
|
if ! msg="$(net rpc shutdown -I "$ADDRESS" -U "$CREDENTIALS" -t "$DELAY" -C "$MESSAGE")"; then
|
|
bashio::log.error "Shutdown fails -> $msg"
|
|
fi
|
|
done
|
|
done |