Making snap of a bash script

I’ve been trying to make my first snap. It’s just a bash script. I’ve followed the directions posted here but I keep facing the following error:

Failed to generate snap metadata: Specified command 'xst.sh' was not found.
Verify the command is correct and for a more deterministic outcome, specify the relative path to the command from the prime directory.

My snapcraft.yaml looks like the following:

name: xst
base: core18
version: '1.0'
summary: summary
description: | 
  Brief description

grade: devel
confinement: devmode
architectures: [ all ]

apps:
  xst:
    command: xst.sh

parts:
  xst:
    plugin: nil

Any help would be highly appreciated. Thanks.

First, make sure that xst.sh is set to executable. Second, you’re not copying it into your snap; your part is plugin: nil which means it won’t do anything. You likely want plugin: dump to copy the file(s) verbatim.

1 Like

Thanks a lot! That worked. I had another question. My script when run as a simple bash script like ./xst.sh takes three arguments. How can implement it in my snap so that it can be run like xst first_arg second_arg third_arg?

you don’t need to do anything special. it will take any commandline parameters as normal.

Okay thanks. My script has dependencies on some utilities of ImageMagick suit and some X11 tools. How do I meet these dependencies in my snap? I assume they need to go the parts template, but I have no idea how to implement them.

You need to look into stage-packages.

1 Like

Thanks. That helped a lot. But some commands inside my script are showing up as “not found” when I run the snap, for example

/snap/xst/x1/project/xst.sh: line 40: xprop: command not found

I’m not sure what package I need in order to make these commands available. Any advice?

Here’s how I usually find out which package a binary is in:

alan@mcp:~$ dpkg -S `which xprop`
x11-utils: /usr/bin/xprop
1 Like

I always forget about this and use apt-file instead, but of course that requires actually installing apt-file to begin with so your way is better :slight_smile:

1 Like

i’m also in the apt-file camp since you can search packages with it you do not have installed locally …

so just for reference:

$ sudo apt install apt-file
[...]
$ sudo apt-file update
[...]
$ apt-file search bin/xprop
x11-utils: /usr/bin/xprop
2 Likes

I’m having trouble locating packages for image and convert commands; they should be available since I’ve already included the ImageMagick as a dependency. :confused:

imagemagick uses /etc/alternatives:

$ ls -l $(which convert)
lrwxrwxrwx 1 root root 25 Aug 24  2014 /usr/bin/convert -> /etc/alternatives/convert
$ ls -l /etc/alternatives/convert
lrwxrwxrwx 1 root root 20 Jul 29  2016 /etc/alternatives/convert -> /usr/bin/convert-im6

snapcraft does not process alternatives so you must create a symlink (convert -> convert-im6) yourself or make your script directly call convert-im6