Delay shutting down the PC (#759)

* ## 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
This commit is contained in:
Stefan
2019-10-16 09:29:13 +02:00
committed by Pascal Vizeli
parent ec2d209335
commit ab639b7427
3 changed files with 16 additions and 5 deletions

View File

@@ -1,4 +1,9 @@
# Changelog
## 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.
## 1.0
- Update samba 4.8.8

View File

@@ -1,6 +1,6 @@
{
"name": "RPC Shutdown",
"version": "1.0",
"version": "2.0",
"slug": "rpc_shutdown",
"description": "Simple way for remote windows shutdowns",
"url": "https://home-assistant.io/addons/rpc_shutdown/",
@@ -14,7 +14,9 @@
{
"alias": "test-pc",
"address": "192.168.0.1",
"credentials": "user%password"
"credentials": "user%password",
"delay": 0,
"message": "Home Assistant is shutting down this PC. This cannot be canceled. Please save your work!"
}
]
},
@@ -23,7 +25,9 @@
{
"alias": "match(^[\\w-]*$)",
"address": "str",
"credentials": "match(^[^%]*(?:%[^%]*)?$)"
"credentials": "match(^[^%]*(?:%[^%]*)?$)",
"delay": "int(0,600)?",
"message": "str?"
}
]
},

View File

@@ -16,6 +16,8 @@ while read -r input; 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)
# Not the correct alias
if [ "$ALIAS" != "$input" ]; then
@@ -23,8 +25,8 @@ while read -r input; do
fi
echo "[Info] Shutdown $input -> $ADDRESS"
if ! msg="$(net rpc shutdown -I "$ADDRESS" -U "$CREDENTIALS")"; then
if ! msg="$(net rpc shutdown -I "$ADDRESS" -U "$CREDENTIALS" -t "$DELAY" -C "$MESSAGE")"; then
echo "[Error] Shutdown fails -> $msg"
fi
done
done
done