Snap packages on MX-17

Version: 

Section: 

Applications

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:
----------

#!/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.

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

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

7. 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!

v. 20180226

Language: 

English