Shell script not running on button click

Hello , I have developed a Linux application using Flutter. In this app I am running a shell script from a button click. It is working fine when run via Android studio but its not working from snap file installation. your help is much appreciated.

The script is regarding opening Cashdrawer. gnome-terminal --window – bash -c /home/arindam/Documents/cashdraweropen.sh

ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ShellException(gnome-terminal --window – bash -c “/home/arindam/Documents/cashdraweropen.sh Bar Printer”, error: ProcessException: No such file or directory Command: gnome-terminal --window – bash -c /home/arindam/Documents/cashdraweropen.sh Bar Printer, workingDirectory: /home/arindam/StudioProjects/pos_flutter)

Hi!

Wow - a flutter app, that’s really cool.

I think I know what is going on here.

Your snap is strictly confined, which means that it cannot access /usr/bin.

Gnome Terminal happens to live in /usr/bin, which means that your app has absolutely no idea that it exists, hence the error.

You can fix this easily by shipping a copy of gnome-terminal in your $SNAP directory, though be careful, you’ll have to find out which dependenices it calls, and ship a copy of them too.

Here’s a snapcraft.yaml parts example which will ship gnome-terminal. Once you run with this, you might see some error messages mentioning gnome-terminal dependencies which can’t be found, just add a new line to the override-build saying cp /usr/bin/[DEP NAME] $SNAPCRAFT_PART_INSTALL/cargo.

layout:
   /usr/bin:
      $SNAP/cargo

parts:
  whatever:
    plugin: whatever
    source: whatever
    override-build: |
      snapcraftctl build
      mkdir $SNAPCRAFT_PART_INSTALL/cargo
      cp /usr/bin/gnome-terminal $SNAPCRAFT_PART_INSTALL/cargo

When building with the automatic GitHub building, you’ll have to add another step to override-build:

override-build: |
   apt -y install gnome-terminal
   ... everything else we had

I hope this helps!

foss-for-the-win