From 0c1718e51c551ca415ae4a8125076a58bd197ca2 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 16 Aug 2017 09:57:39 +0200 Subject: [PATCH] Update ssh hassio cli (#172) * Update config.json * add check support * extend api ouput * Update hassio --- ssh/config.json | 2 +- ssh/hassio | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ssh/config.json b/ssh/config.json index 6a63e1f..f50f402 100644 --- a/ssh/config.json +++ b/ssh/config.json @@ -1,6 +1,6 @@ { "name": "SSH server", - "version": "2.6", + "version": "2.7", "slug": "ssh", "description": "Allows connections over SSH", "url": "https://home-assistant.io/addons/ssh/", diff --git a/ssh/hassio b/ssh/hassio index 7137b39..f1c1955 100644 --- a/ssh/hassio +++ b/ssh/hassio @@ -10,6 +10,7 @@ HomeAssistant: $ hassio homeassistant logs $ hassio homeassistant restart $ hassio homeassistant update + $ hassio homeassistant check Host: $ hassio host hardware @@ -35,20 +36,38 @@ function call_api() { if ! api_ret="$(curl -s -X $command "http://hassio/$1/$2")"; then echo "API error: $api_ret" - exit 1 + return 1 fi if [ "$2" == "logs" ]; then echo "$api_ret" - else - echo "$api_ret" | jq . + return 0 fi + + result="$(echo "$api_ret" | jq --raw-output ".result")" + + # On error + if [ "$result" == "error" ]; then + message="$(echo "$api_ret" | jq --raw-output ".message // empty")" + echo "Error on $1/$2:" "$message" + return 0 + fi + + # On success + data="$(echo "$api_ret" | jq 'if .data == {} then empty else .data end')" + if [ ! -z "$data" ]; then + echo "$data" | jq . + else + echo "Success $1/$2" + fi + + return 0 } ###### # homeassistant functions if [ "$1" == "homeassistant" ]; then - hass_cmd=('logs' 'restart' 'update') + hass_cmd=('logs' 'restart' 'update' 'check') if [[ ! ${hass_cmd[*]} =~ $2 ]]; then echo "No homeassistant command '$2' found!" exit 1