-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcel Hofmann
committed
Jun 14, 2019
1 parent
dd3bd53
commit 65ce03c
Showing
4 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ARG BUILD_FROM | ||
FROM $BUILD_FROM | ||
|
||
# Add env | ||
ENV LANG C.UTF-8 | ||
|
||
# Setup base | ||
RUN apk add --no-cache samba-common-tools samba-common | ||
|
||
# Copy data | ||
COPY run.sh / | ||
|
||
CMD [ "/run.sh" ] |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "RPC Shutdown with timeout", | ||
"version": "1.1", | ||
"slug": "rpc_shutdown", | ||
"description": "Simple way for remote windows shutdowns", | ||
"url": "https://github.com/m2hofi94/my-hassio-addons/tree/master/rpc", | ||
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"], | ||
"startup": "services", | ||
"boot": "auto", | ||
"stdin": true, | ||
"host_network": true, | ||
"options": { | ||
"computers": [ | ||
{ | ||
"alias": "test-pc", | ||
"address": "192.168.0.1", | ||
"credentials": "user%password", | ||
"timeout": 30 | ||
} | ||
] | ||
}, | ||
"schema": { | ||
"computers": [ | ||
{ | ||
"alias": "match(^[\\w-]*$)", | ||
"address": "str", | ||
"credentials": "str", | ||
"timeout": "int" | ||
} | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# RPC Shutdown with Timeout | ||
|
||
Copied from https://github.com/home-assistant/hassio-addons/tree/master/rpc_shutdown, but added a configurable timeout. For a detailed description look here: https://home-assistant.io/addons/rpc_shutdown/ | ||
|
||
Also removed regex from the credentials field, because it did not allow a password with a `%` in it. If your password contains a percentage sign, simply provide it as is: `user%pass%word`. |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/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) | ||
TIMEOUT=$(jq --raw-output ".computers[$i].timeout" $CONFIG_PATH) | ||
|
||
# Not the correct alias | ||
if [ "$ALIAS" != "$input" ]; then | ||
continue | ||
fi | ||
|
||
echo "[Info] Shutdown $input -> $ADDRESS" | ||
if ! msg="$(net rpc shutdown -I "$ADDRESS" -t "$TIMEOUT" -U "$CREDENTIALS" -C "TIME: $TIMEOUT")"; then | ||
echo "[Error] Shutdown fails -> $msg" | ||
fi | ||
done | ||
done |