diff --git a/ssh/Dockerfile b/ssh/Dockerfile index d9bcba8..d4b9590 100644 --- a/ssh/Dockerfile +++ b/ssh/Dockerfile @@ -9,7 +9,8 @@ RUN apk add --no-cache tzdata jq openssh vim curl # Copy data COPY run.sh / COPY motd /etc/ +COPY hassio /usr/bin/ -RUN chmod a+x /run.sh +RUN chmod a+x /run.sh /usr/bin/hassio CMD [ "/run.sh" ] diff --git a/ssh/config.json b/ssh/config.json index 73987c3..add2459 100644 --- a/ssh/config.json +++ b/ssh/config.json @@ -1,6 +1,6 @@ { "name": "SSH server", - "version": "0.8", + "version": "1.0", "slug": "ssh", "description": "Connect to your server over SSH", "url": "https://home-assistant.io/addons/ssh/", diff --git a/ssh/hassio b/ssh/hassio new file mode 100644 index 0000000..76b9aa5 --- /dev/null +++ b/ssh/hassio @@ -0,0 +1,49 @@ +#!/bin/bash +set -e + +HASSIO_API="http://172.17.0.2" + +# helppage +if [ "$1" == "help" ] || [ "$#" -lt 2 ]; then + cat << EOF +---- Hass.IO Cli ---- + +HomeAssistant: + $ hassio homeassistant logs + $ hassio homeassistant restart + $ hassio homeassistant update +EOF +fi + +function call_api_post() { + if ! api_ret="$(curl -X POST "$HASSIO_API/$1/$2")"; then + echo "API error: $api_ret" + exit 1 + fi + echo "$api_ret" +} + +function call_api_get() { + if ! api_ret="$(curl "$HASSIO_API/$1/$2")"; then + echo "API error: $api_ret" + exit 1 + fi + echo "$api_ret" +} + +# homeassistant functions +if [ "$1" == "homeassistant" ]; then + hass_cmd=('logs' 'restart' 'update') + if [[ ! ${hass_cmd[*]} =~ $2 ]]; then + echo "No homeassistant command '$2' found!" + exit 1 + fi + + # logs + if [ "$2" == "logs" ]; then + call_api_get "$1" "$2" + exit 0 + fi + + call_api_post "$1" "$2" +fi diff --git a/ssh/motd b/ssh/motd index 124c126..9b36a8a 100644 --- a/ssh/motd +++ b/ssh/motd @@ -7,4 +7,6 @@ |_| |_|\__,_|___/___(_)_____\____/ +Our Cli: +$ hassio help