Skip to content

Instantly share code, notes, and snippets.

@maximilize
Last active September 14, 2018 16:29
Show Gist options
  • Save maximilize/6070958a08246f7a849379a9d530faa9 to your computer and use it in GitHub Desktop.
Save maximilize/6070958a08246f7a849379a9d530faa9 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
if [ "$1" = "install" ]; then
echo "binds+=( '/var/lib/snapd' '/snap' )" >/etc/qubes-bind-dirs.d/50_snapd.conf
cat >/etc/systemd/system/qubes-snappy-fix.service <<EOF
[Unit]
Description=Rebuild the non-persistent snappy systemd mounts
After=qubes-mount-dirs.service
DefaultDependencies=no
Before=snapd.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/opt/qubes-snappy-fix.sh mount
[Install]
WantedBy=multi-user.target
EOF
systemctl -q enable qubes-snappy-fix.service
echo "Before using snap, restart the VM to activate the bind-mounts"
elif [ "$1" = "mount" ]; then
if [ ! -e /usr/bin/snap ]; then
echo "snappy is not installed on this system" >&2
exit 1
fi
cd /var/lib/snapd/snaps/
while read app revision; do
if [ ! -e /etc/systemd/system/snap-$app-$revision.mount ]; then
cat >/etc/systemd/system/snap-$app-$revision.mount <<EOF
[Unit]
Description=Mount unit for ${app}, revision ${revision}
After=qubes-snappy-fix.service
Before=snapd.service
[Mount]
What=/var/lib/snapd/snaps/${app}_${revision}.snap
Where=/snap/${app}/${revision}
Type=squashfs
Options=nodev,ro,x-gdu.hide
[Install]
WantedBy=multi-user.target
EOF
systemctl -q enable snap-$app-$revision.mount
systemctl -q start snap-$app-$revision.mount
fi
done < <(ls *.snap | cut -d'.' -f1 | sed 's/_/ /')
else
echo "Usage: $0 <install|mount>" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment