summaryrefslogtreecommitdiff
path: root/register_app.sh
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-02-02 22:05:59 +0100
committerTom Smeding <tom@tomsmeding.com>2025-02-02 22:05:59 +0100
commit6b2a60ee925d62ee53be9c2b064cca12d01dbdd6 (patch)
tree21cfe8297bf179ae5511f9240349d3e22a7c7e45 /register_app.sh
InitialHEADmaster
Diffstat (limited to 'register_app.sh')
-rwxr-xr-xregister_app.sh45
1 files changed, 45 insertions, 0 deletions
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