#!/usr/bin/env bash set -e source $SNAP/helper/functions SERVER_SSL=$(snapctl get server.ssl) SERVER_PORT=$(snapctl get server.port) if [ $(echo "${SERVER_PORT}" | grep -E "^\-?[0-9]+$") = "" ]; then echo "!! server.port must be numeric, got ${SERVER_PORT}" >&2 exit 1 fi if [ ${SERVER_SSL} != true -a ${SERVER_SSL} != false ]; then echo "!! server.ssl must be boolean value" >&2 exit 1 fi NETWORK_KEY=$(snapctl get network.key) if [ ! -f "${SNAP_DATA}/settings.json" ]; then echo "{}" > ${SNAP_DATA}/settings.json fi jq --arg networkKey "${NETWORK_KEY}" '.zwave.networkKey = $networkKey' $SNAP_DATA/settings.json > $SNAP_DATA/tmp.json cat ${SNAP_DATA}/tmp.json > ${SNAP_DATA}/settings.json rm ${SNAP_DATA}/tmp.json test_default_config RUNNING=$(snapctl services | grep "${SNAP_NAME}" | grep inactive | wc -l) if [ ${RUNNING} -eq 0 ]; then echo "Restarting ${SNAP_NAME}" snapctl restart "${SNAP_NAME}" fi