Last active
September 24, 2018 18:39
-
-
Save dale3h/8cf94b896f30a30b86d17b49554ff66d to your computer and use it in GitHub Desktop.
Revisions
-
dale3h revised this gist
Sep 18, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,8 @@ readonly BACKUP_DIR=/backup/speck usage() { echo "usage: $(basename "$0") addon_name" 2>&1 exit 1 } addon_install() { -
dale3h revised this gist
Sep 18, 2018 . 1 changed file with 88 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,37 +1,111 @@ #!/bin/bash readonly BACKUP_DIR=/backup/speck usage() { echo "usage: $(basename $0) addon_name" 2>&1 exit 1 } addon_install() { local addon="${1}" hassio addons install --name "${addon}" } addon_uninstall() { local addon="${1}" hassio addons uninstall --name "${addon}" } addon_reload() { hassio addons reload } addon_config_backup() { local addon="${1}" local backup_file local result local config local ex_code # Ensure backup directory exists if [[ ! -d "${BACKUP_DIR}" ]]; then mkdir -p "${BACKUP_DIR}" fi # Create backup file name backup_file="${BACKUP_DIR}/${addon}.json" # Get addon config from Hass.io result=$(hassio addons info --name "${addon}") ex_code="$?" # Check for exit code if [[ "${ex_code}" -ne 0 ]]; then echo "fail (${result})" return "${ex_code}" fi # Pull config from results config=$(jq --raw-output ".data.options // empty" <<< "${result}") # Test for empty config if [[ -z "${config}" ]]; then echo "fail (Empty config)" return 1 fi # Save config to file echo "${config}" > "${backup_file}" echo "ok" } addon_config_restore() { local addon="${1}" local backup_file="${BACKUP_DIR}/${addon}.json" local config local options local ex_code # Check if backup file exists if [[ ! -f "${backup_file}" ]]; then echo "fail (Missing backup file)" return 1 fi # Read backup file config=$(jq --compact-output "." "${backup_file}") options="{\"options\":${config}}" # Restore config curl -sS -X "POST" -H "X-HASSIO-KEY: ${HASSIO_TOKEN}" --data-binary "${options}" "http://hassio/addons/${addon}/options" ex_code="$?" echo return "${ex_code}" } main() { local addon="${1}" if [[ -z "${addon}" ]]; then usage fi echo -n "Backup config: " addon_config_backup "${addon}" echo -n "Uninstall ${addon}: " addon_uninstall "${addon}" || echo echo -n "Reload addons: " addon_reload || exit 1 echo -n "Install ${addon}: " addon_install "${addon}" || exit 1 echo -n "Restore config: " addon_config_restore "${addon}" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then -
dale3h created this gist
Sep 7, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/bin/bash function usage() { echo "usage: $(basename $0) addon_name" 2>&1 exit 1 } function addon_install() { hassio addons install --name "$1" } function addon_uninstall() { hassio addons uninstall --name "$1" } function addon_reload() { hassio addons reload } function main() { readonly ADDON_NAME="$1" if [[ -z "$ADDON_NAME" ]]; then usage fi echo -n "Uninstalling $ADDON_NAME: " addon_uninstall "$ADDON_NAME" || echo echo -n "Reloading addons: " addon_reload || exit 1 echo -n "Installing $ADDON_NAME: " addon_install "$ADDON_NAME" || exit 1 } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main "${@}" fi