Hooks not working

Hi people! I am trying to pack a new Snap with bellow yaml:

apps:
  forwarder:
    command: ./forwarder/lora_pkt_fwd/lora_pkt_fwd
    daemon: simple
    restart-condition: always
    plugs: [home,network,network-bind,spi]

hooks:
  configure:
    plugs: [home,network,network-bind]

parts:
  driver:
    source: https://github.com/Lora-net/lora_gateway.git
    plugin: make
    build-packages:
      - build-essential
    override-build: |
      make all
      cp -rf $SNAPCRAFT_PART_INSTALL/../build $SNAPCRAFT_PRIME/driver
  
  forwarder:
    source: https://github.com/Lora-net/packet_forwarder.git
    plugin: make
    after: [driver]
    build-packages:
      - build-essential
    override-build: |
      export LGW_PATH="$SNAPCRAFT_PART_INSTALL/../../driver/build/libloragw"
      make all
      cp -rf $SNAPCRAFT_PART_INSTALL/../build $SNAPCRAFT_PRIME/forwarder

My problem: the hook “configure” not works. I put it in “snap/hooks/configure” (and yaml in root), with a+x permissions and bellow content:

#!/bin/sh -e

id="$(snapctl get id)"
echo "Starting configuration..."
echo $id >> $SNAP_DATA/id
cd $SNAP/forwarder/lora_pkt_fwd
pwd
./update_gwid.sh local_conf.json
echo "Done!"

So, after install it, I call:

sudo snap set bigboxx-lora id="aaaa"

But not work. Nothing is printed and file “/snap/[snap name]/current/id” is not created.

Please, I am trying for two days. Anybody can help me? I am packing Snap in MacOS and installing in Ubuntu Server 18.04 (over VirtualBox).

One thing to note is that $SNAP_DATA should resolve to /var/snap/[snap name]/current which is different to /snap/[snap name]/current. It’s worth double checking whether your id file is in the /var/snap path…

You are right! I am looking to wrong place. I me sorry for dummy error! I think that echo commands will appear in stderr when I made “set”. Now I am putting all output in log and its works fine:

#!/bin/sh -e
NOW=$(date +"%d-%m-%Y %T")
LOG=$SNAP_DATA/configure.log
echo "-- $NOW --" >> $LOG
echo "Starting configuration..." >> $LOG
cd $SNAP/forwarder/lora_pkt_fwd
pwd >> $LOG
./update_gwid.sh local_conf.json >> $LOG
echo "Done! \n" >> $LOG
1 Like