Files
addons/ssh/hassio
Pascal Vizeli d24aa7d3e4 Migrate ssh/git_pull to new hassio_api feature of 0.51 (#167)
* Update config.json

* Use new API link

* Update config.json

* Update run.sh

* Update config.json
2017-08-09 09:32:38 +02:00

66 lines
1.2 KiB
Bash

#!/bin/bash
set -e
# helppage
if [ "$1" == "help" ] || [ "$#" -lt 2 ]; then
cat << EOF
---- Hass.IO Cli ----
HomeAssistant:
$ hassio homeassistant logs
$ hassio homeassistant restart
$ hassio homeassistant update
Host:
$ hassio host hardware
$ hassio host reboot
$ hassio host shutdown
$ hassio host update
EOF
fi
function call_api() {
if ! api_ret="$(curl -s -X $1 "http://hassio/$2/$3")"; then
echo "API error: $api_ret"
exit 1
fi
if [ "$3" == "logs" ]; then
echo "$api_ret"
else
echo "$api_ret" | jq .
fi
}
######
# 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
if [ "$2" == "logs" ]; then
call_api GET "$1" "$2"
else
call_api POST "$1" "$2"
fi
fi
######
# host functions
if [ "$1" == "host" ]; then
hass_cmd=('reboot' 'shutdown' 'update' 'hardware')
if [[ ! ${hass_cmd[*]} =~ $2 ]]; then
echo "No host command '$2' found!"
exit 1
fi
if [ "$2" == "hardware" ]; then
call_api GET "$1" "$2"
else
call_api POST "$1" "$2"
fi
fi