Cannot create file on install hook


I have a snap app already in place. I decide to add settings to this app and perform set/get to its configuration (like server port for instance).
I have create a configure hook and it works flawlessly. I am able to change the server port in runtime as expected.
However, upon 1st installation, there is no config file and default settings come clear.
I understand that I have to add an install hook where I should create this default config file.
I did that and chmoded a+x.

The config file should be stored at $SNAP_DATA/config.

During snap install, I have got this:

error: cannot perform the following tasks:
Run install hook of “teste” snap if present (run hook “install”: /snap/teste/x1/meta/hooks/install: 7: /snap/teste/x1/meta/hooks/install: cannot create CONFIG_FILE: Read-only file system)

What am I missing?

install hook:

#!/bin/sh -e
set -e
echo “port=9000” > CONFIG_FILE

snapcraft.yaml (only hook part):

plugs: [home]
plugs: [home]

it might help to show your sourecode of the config hook :wink:


Added to 1st post.

(How do I proper highlight a code block?)

first of all, sh -e is pretty much the same as set -e i’d drop one of them (just remove -e in the /bin/sh line) …

echo “port=9000” > CONFIG_FILE

this line would write to a file called CONFIG_FILE, not to $SNAP_DATA/config … i guess you want to use $CONFIG_FILE in that line instead, so it actually uses the variable :wink:


I missed the $… :tired_face: