From eea8bea4b90108cc6bf8b63a35189b4d34b0ced1 Mon Sep 17 00:00:00 2001 From: Alex Lewontin Date: Wed, 14 Feb 2024 09:35:40 -0500 Subject: [PATCH] prepare-device: implement reference prepare-device hook Fixes: #110 Signed-off-by: Tony Espy --- snap/hooks/prepare-device | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 snap/hooks/prepare-device diff --git a/snap/hooks/prepare-device b/snap/hooks/prepare-device new file mode 100755 index 0000000..2ee7f65 --- /dev/null +++ b/snap/hooks/prepare-device @@ -0,0 +1,23 @@ +#!/bin/sh + +# This file is included for reference purposes. If MODEL_APIKEY is not set +# in snapcraft.yaml (as is the default), it is a no-op. For more about how +# to use this script to connect a device to an IoT App Store, see +# - https://ubuntu.com/core/services/guide/serial-vault-overview +# - https://ubuntu.com/core/services/guide/connecting-devices +# - https://snapcraft.io/docs/gadget-snap#heading--prepare + +set -eu + +if [ -z "$MODEL_APIKEY" ] ; then + exit 0 +fi + +exec >> $SNAP_COMMON/prepare-device-hook.log 2>&1 + +# If you are forking and building your own gadget: +# implement your preferred way of generating a serial number for this device here +snapctl set registration.proposed-serial="\"$(date -u)\"" + +snapctl set device-service.url="https://serial-vault-partners.canonical.com/v1/" +snapctl set device-service.headers="{\"api-key\": \"$MODEL_APIKEY\"}"