This work fine if I want to use a hardcoded value. And the same value for every device. However, I want this value to NOT be hardcoded and be based on a dynamic device value - in this case the mac id of eth0, which is stored in /sys/class/net/eth0/address.
So, I was hoping that in the prepare_device hook, I could read this value and then set the appropriate defaults key something like:
This would effectively let me dynamically set the default passphrase for each individual device with nothing hardcoded or having to set that value manually in each gadget file and creating individual images for every device.
No they cannot. However you can just set the config item you want from the install hook, i.e. something like
#!/bin/sh
snapctl set passphrase="$(cat /sys/class/net/eth0/address)"
Would that work for your use case?
Also, just as an FYI I would recommend moving this topic to either the #devices or the #snapd categories where it will get more views from relevant folks.
I started there - part of the install hook - however I cannot get that to work. I’ll explain my results and perhaps you could offer a solution?
I had added the code to the install hook. And, since I am accessing the /sys/ directory and a network device, I have added the requisite hardware-observe and network-observe plugs. However, during install, I still get an access denied error:
adjust program to not access ‘/sys/devices/pci0000:00/0000:00:13.1/0000:02:00.0/net/eth0/address’
adjust program to not access ‘/sys/devices/pci[0-9]:[0-9]/[0-9]:[0-9]:[0-9].[0-9]/[0-9]:[0-9]:[0-9].[0-9]/net/eth[0-9]*/address’
I have read numerous places that all that is required to access the /sys/class/net/* files is hardware-observe and network-observe (I have even added system-observe) but to no avail.