How to install Snap packages

Locked
Message
Author
newguy
Posts: 27
Joined: Tue Dec 12, 2017 8:16 pm

How to install Snap packages

#1 Post by newguy »

A problem I have been trying to solve recently is how to get Snap packages working on MX Linux while still using the distribution's default SysV init software. Today I made a little progress.

The problem: Snap packages, or more specifically the snapd daemon which manages Snap packages, relies on systemd. Not only must systemd be installed, but it needs to be running as PID 1. The snapd software uses systemd's systemctl program to perform a few tasks like mounting and unmounting package archives (packages are squashfs files). When systemctl is called when systemd is not running as PID 1, it will fail. Neither systemd nor Snap developers have worked around these issues.


Potential workaround: The snapd software makes calls to the systemctl program (https://github.com/snapcore/snapd/blob/ ... systemd.go), but it does not have a specific path in mind. This means as long as systemctl is somewhere in our path, snapd can execute it. It also means we can insert another executable called "systemctl" into an early part of our path and it will intercept snapd's calls. For example, on MX Linux 17, the official systemctl path is /bin/systemctl. We can create a script or program to pretend to be systemctl by making a file called /usr/bin/systemctl.

I have created a small shell script which accepts parameters from snapd and tries to perform the same task systemctl would. This allows us to at least successfully install Snap packages.


The solution: Right now my solution is crude, but with just a day of playing with Snaps, I've managed to get two of the three packages I've tested working with this method.

Here is how you can try it at home:

1. Install snapd by running "sudo apt install snapd"

2. Create a new, fake systemctl program -

sudo nano /usr/bin/systemctl


3. Paste in this script:

Code: Select all

#!/bin/bash

# First parameter should be start or stop
# Second parameter will be the name of a unit file

if [ $# -lt 2 ]
then 
  echo "usage: $0 start unit-file"
  exit 0
fi

if [ $1 == "start" ]
then
  what=$(grep What /etc/systemd/system/"$2" | cut -f 2 -d '=')
  where=$(grep Where /etc/systemd/system/"$2" | cut -f 2 -d '=')
  mkdir -p "$where"
  mount $what $where
  exit 0
fi

if [ $1 == "stop" ]
then
  where=$(grep Where /etc/systemd/system/"$2" | cut -f 2 -d '=')
  umount $where
  exit 0
fi
4. Save the file and run "sudo chmod 755 /usr/bin/systemctl" to make sure the script can execute.

Edit - forgot a step!

4.5 Run the snapd daemon with "cd /usr/lib/snapd && sudo ./snapd"

5. Install a Snap package. A simple one is the Hello World program. "sudo snap install hello-world"

6. Run the program. This is the tricky part as different Snaps seem to handle being installed this way and some do not handle it gracefully. (Simple Note and Hello-World worked for me. The VLC Snap did not.) Newly installed programs can be found under the /snap directory. For example, I can run "/snap/simplenote/33/usr/share/simplenote/simplenote" to run the Simple Note program.


The future: Ideally, things could be a little more automated. Maybe the MX team could add a package for the above script. Maybe some code could be added to add Snap executables to the user's path, etc. But right now the good news is MX users can install Snaps without swapping out init systems or doing other risky actions. Some of those Snaps will even run!

User avatar
Jerry3904
Administrator
Posts: 21881
Joined: Wed Jul 19, 2006 6:13 am

Re: How to install Snap packages

#2 Post by Jerry3904 »

Sorry, missed this the first time around. Will be modifying for the Wiki--thanks!
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
Jerry3904
Administrator
Posts: 21881
Joined: Wed Jul 19, 2006 6:13 am

Re: How to install Snap packages

#3 Post by Jerry3904 »

Pasted it in, did minor formatting for now:

https://mxlinux.org/wiki/applications/s ... ages-mx-17

Thanks again!
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

newguy
Posts: 27
Joined: Tue Dec 12, 2017 8:16 pm

Re: How to install Snap packages

#4 Post by newguy »

My pleasure. I hope, in the future, this process gets improved/automated so more Snap packages work and the snapd daemon gets run automatically. Unfortunately there is very little documentation on how snapd works so we may need to parse the source code to sort out the remaining steps.

danielson

Re: How to install Snap packages

#5 Post by danielson »

Nurdee nurdee here...
How to save this script is the question.
Do not see "save" anywhere and i do not know how to type that upside down vX to exit (which i presume will ask if i want to save, maybe).
----------

#!/bin/bash

# First parameter should be start or stop
# Second parameter will be the name of a unit file

if [ $# -lt 2 ]
then
echo "usage: $0 start unit-file"
exit 0
fi

if [ $1 == "start" ]
then
what=$(grep What /etc/systemd/system/"$2" | cut -f 2 -d '=')
where=$(grep Where /etc/systemd/system/"$2" | cut -f 2 -d '=')
mkdir -p "$where"
mount $what $where
exit 0
fi

if [ $1 == "stop" ]
then
where=$(grep Where /etc/systemd/system/"$2" | cut -f 2 -d '=')
umount $where
exit 0
fi

----------







(was a synch with LinuxMint).

User avatar
Jerry3904
Administrator
Posts: 21881
Joined: Wed Jul 19, 2006 6:13 am

Re: How to install Snap packages

#6 Post by Jerry3904 »

<LinuxMint runs on systemd, which is the whole point>

You mean this (Users Manual 6.5):
--copy the script
--go to the directory where you want to save it (I created a new folder /home/Scripts/ for these things)
--right-click and empty space > Create Document > Empty File
--name it however you want and save
--open it back up and paste in what you copied
--save again, and check right-click > Permissions that it can run

You realize I hope that the script can't be run as it is since it needs things like "What" and "Where" filled in.
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
Adrian
Developer
Posts: 8248
Joined: Wed Jul 12, 2006 1:42 am

Re: How to install Snap packages

#7 Post by Adrian »

You realize I hope that the script can't be run as it is since it needs things like "What" and "Where" filled in.
It looks like it pulls them with those grep commands.

One small comment, I think you need a & at the end of this command to background the snapd process:

Code: Select all

cd /usr/lib/snapd && sudo ./snapd&

DaleB1970
Posts: 12
Joined: Sun Oct 30, 2022 11:52 am

Re: How to install Snap packages

#8 Post by DaleB1970 »

Is there any progress in this, for those that aren't fluent in coding? I have installed the flatpak of JAMI. JAMI sees the Logitech BRIO 4k webcam, but nothing shows in the preview, like it did with the snap version on Ubuntu 22.04.

User avatar
Utopia
Administrator
Posts: 3245
Joined: Sun Apr 29, 2007 11:53 am

Re: How to install Snap packages

#9 Post by Utopia »

Please, start your own thread. This one is 5 years old. Topic locked.
Henry

Locked

Return to “General”