forked from home-assistant/addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delay shutting down the PC (home-assistant#792)
* ## 2.0 - New option to delay shutting down the Windows PC - New option to send a message to the PC that is about to be shut down. If somebody is using the PC, you can warn them to save their work. * delay parameter is int. check for empty is not needed when we have a default * Add a default value for Delay. * update 2.1 * Fixed syntax error
- Loading branch information
1 parent
714bcfb
commit 89d43e8
Showing
3 changed files
with
26 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bashio | ||
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" | ||
# parse JSON value | ||
input=$(bashio::jq "${input}" '.') | ||
bashio::log.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) | ||
DELAY=$(jq --raw-output ".computers[$i].delay" $CONFIG_PATH) | ||
MESSAGE=$(jq --raw-output ".computers[$i].message" $CONFIG_PATH) | ||
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 [ "$ALIAS" != "$input" ]; then | ||
if ! bashio::var.equals "$ALIAS" "$input"; then | ||
continue | ||
fi | ||
|
||
echo "[Info] Shutdown $input -> $ADDRESS" | ||
|
||
# Check if delay is not empty | ||
if bashio::var.is_empty "${DELAY}"; then | ||
DELAY="0" | ||
fi | ||
|
||
bashio::log.info "Shutdown $input -> $ADDRESS" | ||
if ! msg="$(net rpc shutdown -I "$ADDRESS" -U "$CREDENTIALS" -t "$DELAY" -C "$MESSAGE")"; then | ||
echo "[Error] Shutdown fails -> $msg" | ||
bashio::log.error "Shutdown fails -> $msg" | ||
fi | ||
done | ||
done |