Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare-device: implement reference prepare-device hook #111

Open
wants to merge 1 commit into
base: 20
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions snap/hooks/prepare-device
Original file line number Diff line number Diff line change
@@ -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\"}"