From 6b2a60ee925d62ee53be9c2b064cca12d01dbdd6 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 2 Feb 2025 22:05:59 +0100 Subject: Initial --- register_app.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 register_app.sh (limited to 'register_app.sh') diff --git a/register_app.sh b/register_app.sh new file mode 100755 index 0000000..9cec53b --- /dev/null +++ b/register_app.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +source functions.sh + +application_name=tom-hue-stuff + +read_vars + +if [[ -z $var_ip || -z $var_bridgeid ]]; then + echo >&2 "Variables ip and bridgeid required in my_bridge.txt" + exit 1 +fi + +echo "Registering a new user on the Hue Bridge (using API V1)." +echo "Application name: $application_name" + +read -r -p "Device name (e.g. iphone peter): " device_name + +if [[ -z $device_name ]]; then + echo >&2 "Device name required" + exit 1 +fi +if [[ -n "$(echo "$device_name" | tr -d 'a-zA-Z90-9 _-')" ]]; then + echo >&2 "Invalid characters in device name" + exit 1 +fi + +echo "Now press the button on the Bridge, and press enter here." +echo "Please press enter within 30 seconds of pressing the button." + +read + +reqdata=$(jq -c --arg app "$application_name" --arg dev "$device_name" '{"devicetype": ($app + "#" + $dev)}' <<<0) +# reqdata=$(jq -c --arg app "$application_name" --arg dev "$device_name" '{}' <<<0) +response=$(curl -s --cacert signify_root_cert.pem --resolve "$var_bridgeid:443:$var_ip" -d "$reqdata" https://"$var_bridgeid"/api) + +if [[ $(jq '.[0] | has("success")' <<<"$response") = true ]]; then + username=$(jq '.[0].success.username' <<<"$response") + echo "username=$username" +else + echo "Registration failed:" + echo "$response" + exit 1 +fi -- cgit v1.2.3-70-g09d2