Writing user common data directory into wrapper script

Hi, I am new to building snaps, and I would like to some help this.

I am overriding the build in the yaml file with the following scriptlet.

 fix-fontconfig:
    plugin: nil
    override-build: |
        mkdir $SNAPCRAFT_PART_INSTALL/bin
        echo "[[ -e \$SNAP_USER_COMMON/Config.ini ]] || cp \$SNAP/bin/Config.ini \$SNAP_USER_COMMON/Config.ini" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "[[ -e \$SNAP_USER_COMMON/Config.productspec ]] || cp \$SNAP/bin/Config.productspec \$SNAP_USER_COMMON/Config.productspec" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "mkdir \$SNAP_USER_DATA/.config" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "mkdir \$SNAP_USER_DATA/.config/fontconfig" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "cp \$SNAP/etc/fonts/fonts.conf \$SNAP_USER_DATA/.config/fontconfig/fonts.conf" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "sed -i \"s#<dir>/usr#<dir>\$SNAP/usr#g\" \$SNAP_USER_DATA/.config/fontconfig/fonts.conf" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "cd \$SNAP/bin" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        echo "./PanelApp -p $SNAP_USER_COMMON/Config.productspec" >> $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh
        chmod +x $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh

When the snap is installed and I inspect the start_bms.sh script, I find that the $SNAP_USER_COMMON translated to /root/snap/snapcraft/common, instead of /home/<user_dir>/snap/<snap_name>/common.

What I would like is that $SNAP_USER_COMMON translate to /home/<user_dir>/snap/<snap_name>/common during the execution of the override-build.
How do I do that?

Any help would be appreciated, thanks in advance.

while i’m not sure why you want to live with all these echos instead of simply pre-creating the script, the basic shell quoting rules apply in the override scriptlets … :

ogra@anubis:~$ export FOO=bar
ogra@anubis:~$ echo "Foo is: $FOO"
Foo is: bar
ogra@anubis:~$ echo 'Foo is: $FOO'
Foo is: $FOO
ogra@anubis:~$

Thank you for the reply.
Like I mentioned I am new at this.
How would I then get the script lines into my start_bms.sh script if I don’t echo it into the script?

create a start_bms.sh script like:

#! /bin/sh

[ -e $SNAP_USER_COMMON/Config.ini ] || cp $SNAP/bin/Config.ini $SNAP_USER_COMMON/Config.ini" 
[ -e $SNAP_USER_COMMON/Config.productspec ] || cp $SNAP/bin/Config.productspec $SNAP_USER_COMMON/Config.productspec

# use -p for mkdir to create the whole set of dirs n one go
mkdir -p $SNAP_USER_DATA/.config/fontconfig

cp $SNAP/etc/fonts/fonts.conf $SNAP_USER_DATA/.config/fontconfig/fonts.conf
sed -i "s#<dir>/usr#<dir>$SNAP/usr#g" $SNAP_USER_DATA/.config/fontconfig/fonts.conf

# if PanelApp is in $SNAP/bin/ snap will find it in $PATH, just exec it
exec PanelApp -p $SNAP_USER_COMMON/Config.productspec

in your source tree …
… and copy it in place from your override scriptlet:

  override-build: | 
    mkdir $SNAPCRAFT_PART_INSTALL/bin
    cp $whereever_in_the_tree_your_script_lives/start_bms.sh $SNAPCRAFT_PART_INSTALL/bin/
    chmod +x $SNAPCRAFT_PART_INSTALL/bin/start_bms.sh

Hi
Thank you for the solution, much more simpler than my solution.
Learned something new, thanks for that.