Welcome!
Important information
-- Spectre and Meltdown vulnerabilities
-- Change in MX sources

News
-- MX Linux on social media: here
-- Mepis support still here

Current releases
-- MX-17.1 Final release info here
-- antiX-17 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

How to install Snap packages

Post Reply
Message
Author
newguy
Forum Novice
Forum  Novice
Posts: 18
Joined: Tue Dec 12, 2017 8:16 pm

How to install Snap packages

#1 Post by newguy » Fri Feb 09, 2018 7:35 pm

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
Forum Veteran
Forum Veteran
Posts: 22420
Joined: Wed Jul 19, 2006 6:13 am

Re: How to install Snap packages

#2 Post by Jerry3904 » Sat Feb 24, 2018 10:08 pm

Sorry, missed this the first time around. Will be modifying for the Wiki--thanks!
Production: 4.15.0-1-amd64, MX-17.1, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 8 GB, Kingston SSD 120 GB and WesternDigital 1TB
Testing: AAO 722: 4.15.0-1-386. MX-17.1, AMD C-60 APU, 4 GB

User avatar
Jerry3904
Forum Veteran
Forum Veteran
Posts: 22420
Joined: Wed Jul 19, 2006 6:13 am

Re: How to install Snap packages

#3 Post by Jerry3904 » Mon Feb 26, 2018 5:35 pm

Pasted it in, did minor formatting for now:

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

Thanks again!
Production: 4.15.0-1-amd64, MX-17.1, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 8 GB, Kingston SSD 120 GB and WesternDigital 1TB
Testing: AAO 722: 4.15.0-1-386. MX-17.1, AMD C-60 APU, 4 GB

newguy
Forum Novice
Forum  Novice
Posts: 18
Joined: Tue Dec 12, 2017 8:16 pm

Re: How to install Snap packages

#4 Post by newguy » Mon Feb 26, 2018 5:50 pm

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.

User avatar
danielson
Forum Regular
Forum Regular
Posts: 167
Joined: Wed Dec 14, 2016 3:36 pm

Re: How to install Snap packages

#5 Post by danielson » Fri Mar 09, 2018 10:44 am

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).
Distro: MX-17_x64 Horizon
Laptop: HP EliteBook 8460p
CPU: Dual core Intel i5-2520M.
Office: LibreOffice.
Browser: Firefox (Quantum), Vivaldi (Snapshot).

User avatar
Jerry3904
Forum Veteran
Forum Veteran
Posts: 22420
Joined: Wed Jul 19, 2006 6:13 am

Re: How to install Snap packages

#6 Post by Jerry3904 » Fri Mar 09, 2018 11:07 am

<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: 4.15.0-1-amd64, MX-17.1, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 8 GB, Kingston SSD 120 GB and WesternDigital 1TB
Testing: AAO 722: 4.15.0-1-386. MX-17.1, AMD C-60 APU, 4 GB

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 8877
Joined: Wed Jul 12, 2006 1:42 am

Re: How to install Snap packages

#7 Post by Adrian » Sun Jul 22, 2018 10:21 am

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&

Post Reply

Return to “General”