From 052a558419c0bb7b0d534f408bcbd5dd11f940eb Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 11 Aug 2017 00:23:15 +0200 Subject: [PATCH] Update hassio cli (#169) * Update hassio * Update config.json * Update hassio --- ssh/config.json | 2 +- ssh/hassio | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ssh/config.json b/ssh/config.json index 1a68843..6a63e1f 100644 --- a/ssh/config.json +++ b/ssh/config.json @@ -1,6 +1,6 @@ { "name": "SSH server", - "version": "2.5", + "version": "2.6", "slug": "ssh", "description": "Allows connections over SSH", "url": "https://home-assistant.io/addons/ssh/", diff --git a/ssh/hassio b/ssh/hassio index 1b86616..7137b39 100644 --- a/ssh/hassio +++ b/ssh/hassio @@ -16,16 +16,29 @@ Host: $ hassio host reboot $ hassio host shutdown $ hassio host update + +Supervisor + $ hassio supervisor logs + $ hassio supervisor info + $ hassio supervisor reload + $ hassio supervisor update EOF fi function call_api() { - if ! api_ret="$(curl -s -X $1 "http://hassio/$2/$3")"; then + get_cmd=('info' 'logs' 'hardware') + + command='POST' + if [[ ${get_cmd[*]} =~ $2 ]]; then + command='GET' + fi + + if ! api_ret="$(curl -s -X $command "http://hassio/$1/$2")"; then echo "API error: $api_ret" exit 1 fi - if [ "$3" == "logs" ]; then + if [ "$2" == "logs" ]; then echo "$api_ret" else echo "$api_ret" | jq . @@ -41,11 +54,7 @@ if [ "$1" == "homeassistant" ]; then exit 1 fi - if [ "$2" == "logs" ]; then - call_api GET "$1" "$2" - else - call_api POST "$1" "$2" - fi + call_api "$1" "$2" fi ###### @@ -57,9 +66,17 @@ if [ "$1" == "host" ]; then exit 1 fi - if [ "$2" == "hardware" ]; then - call_api GET "$1" "$2" - else - call_api POST "$1" "$2" - fi + call_api "$1" "$2" +fi + +###### +# supervisor functions +if [ "$1" == "supervisor" ]; then + hass_cmd=('logs' 'reload' 'update' 'info') + if [[ ! ${hass_cmd[*]} =~ $2 ]]; then + echo "No supervisor command '$2' found!" + exit 1 + fi + + call_api "$1" "$2" fi