Running executable that located out side of the snap

I am creating a snap to control smart devices.

I am trying to add support for multiple devices like Raspberry Pi and NanoPi but they are using fork of the same library WiringPi to control the device pins so both library’s cannot be installed on the same snap.

I have decided to go on different rout and control the devices pins through the library that installed on the device outside of the snap.

While trying to run the commands in the terminal or the executable that located on the device I get an error that it does not exist No such file or directory (with the command ls in my software inside the snap I verified that the executable exist and I can see it inside the snap).

The command that I use in the terminal is gpio.

Is there a way to make the executable on the device accessible within the snap and run on the device out side of the snap?
gpio can be found in /usr/local/bin/gpio or /usr/bin/gpio depending on the device.

I saw Snap layouts but I am not sure how to use it in this case.

When adding

layout:
  /usr/local/bin/gpio:
    bind: $SNAP_DATA/usr/local/bin/gpio

to the snap the error is changing to Permission denied although I change the gpio executable to 777 permissions and run the snap with sudo.

snapcraft.yaml

name: cybear-jinni
base: core20
version: '0.1.3'  # Just for humans, typically '1.2+git' or '1.3.2'
summary: Smart home snap for CyBear Jinni smart devices.
description: |
  A CyBear Jinni snap for smart devices.

  Using this snap you can make your device smart and control lamp or blind (if the device is supported currently only NanoPi Duo2), you will be able to control it using physical buttons and even from your phones using CyBear Jinni app.

  Our goal here at CyBear Jinni is to raise the quality of life for everyone.
  We are doing this by making Smart-Home accessible for the common person.

  This is open source project so feel free to take a look at the code and join us advancing the world forward.

grade: devel  # devel/stable
confinement: devmode  # devmode/classic/strict

#architectures:
#  - build-on: armhf
#    run-on: armhf
#
#  - build-on: arm64
#    run-on: arm64
#
#  - build-on: amd64
#    run-on: amd64

parts:
  wiring-np:
    plugin: dump
    source: .
    build-attributes: [keep-execstack]
    override-build: |

      #git clone https://github.com/CyBear-Jinni/WiringNP
      ## git clone https://github.com/friendlyarm/WiringNP  // Does not work on the armbian os,  https://forum.armbian.com/topic/13889-nanopiduo2-wiringnp-unable-to-determine-board-revision/
      #cd WiringNP/
      #chmod 755 build
      #./build
      #cd ..

      #git clone https://github.com/WiringPi/WiringPi.git
      #cd WiringPi/
      #chmod 755 build
      #./build
      #cd ..

    build-packages:
      - git
      - make

  smart-home:
    after: [wiring-np]
    plugin: dump
    source: .
    override-build: |
      scripts/bashScripts/nativeExecutableMaker.sh  # Downloading dart-sdk for the correct architecture.

      rm -r SmartDeviceDart

      #cd scripts/bashScripts/
      #./compileAllCFiles.sh # Have to be executed when working directory is this file location
      #cd ../..

      snapcraftctl build

    build-packages:
      - wget
      - unzip
      - gcc
      - g++
    stage-packages:
      - libatlas-base-dev
      - libevent-dev


layout:
  /usr/local/bin/gpio:
    bind: $SNAP_DATA/usr/local/bin/gpio


apps:
  cybear-jinni:
    command: CyBear-Jinni_Smart-Device $SNAP
    #daemon: simple
    plugs: [network, network-bind, gpio, hardware-observe]

Due to Snap’s security confinement, system commands are not invokable from within the snap. Try adding the gpio command via stage-packages snapcraft.yaml property and use https://snapcraft.io/docs/gpio-interface instead?

1 Like

use two parts i.e. wiringpi-rpi, wiringpi-nano and install them into different locations inside the snap ($SNAP/lib/wiringpi-rpi, $SNAP/lib/wiringpi-nano) …

then use a command-chain wrapper to detect which device you are on (using the hardware-observe interface and read from /proc/cpuinfo) to adjust LD_LIBRARY_PATH to contain the specific dir for the device …

2 Likes

@Lin-Buo-Ren as snap interface gpio does not show any slots in my devices

pi@raspberrypi:~ $ snap interface gpio
name:    gpio
summary: allows access to specifc GPIO pin
plugs:
  - cybear-jinni

I will try to use @ogra suggestion.

Thanks for the answer guys.

1 Like