I have built my first gadget snap for a custom image, and I want to utilize the prepare-device hook to set up some things that I (think I) cannot achieve through gadget.yaml declarations.
- Set the hostname through nmcli (or hostnamectl)
- copy over a custom miral-kiosk.display config file to use with mir-kiosk (the file has additional layouts)
- Edit the swapfile to enable 1GB swap on the system
The hook code:
#! /bin/sh -e #/usr/bin/hostnamectl set-hostname 'myhost' nmcli g hostname 'myhost' nmcli d set wlan0 autoconnect yes # Enable swap with 1GB cp /etc/default/swapfile . sed -i.bak -e "s/^SIZE=0$/SIZE=1024/"swapfile cp swapfile /etc/default/swapfile rm swapfile swapfile.bak systemctl enable --now swapfile.service cp miral-kiosk.display /var/snap/mir-kiosk/current/
I’ve added this stanza to my gadget’s
hooks: prepare-device: plugs: - hostname-control - network-manager
All examples I can find for
prepare-device deal with serial registration. Nothing from the hook seems to have any effect. Is it possible to do the above in this hook at all? To understand this better, I’d like to know:
- When is the hook called during setup? (have all snaps been installed, interfaces connected …)
- Which privileges does it have (root)?
- Are there better ways to achieve things that would normally require system-user commands on a TTY after the device has been set up?