Skip to content

Instantly share code, notes, and snippets.

@JJRcop
Last active September 25, 2023 14:25
Show Gist options
  • Save JJRcop/46450e4f7aa0770a60cb8d4a61ecd2f6 to your computer and use it in GitHub Desktop.
Save JJRcop/46450e4f7aa0770a60cb8d4a61ecd2f6 to your computer and use it in GitHub Desktop.
PWAsForFirefox systemd.service to use installed Firefox runtime
[Unit]
Description=FirefoxPWA overlayfs to use installed Firefox runtime
AssertPathIsDirectory=%%runtime_path
[Service]
Type=simple
ExecStart=fuse-overlayfs -f -o squash_to_uid=%U,squash_to_gid=%G,lowerdir=%%runtime_path,upperdir=%t/firefoxpwa/overlayfs/upper,workdir=%t/firefoxpwa/overlayfs/work %h/.local/share/firefoxpwa/runtime/
ExecStop=fusermount -u %h/.local/share/firefoxpwa/runtime/
RuntimeDirectory=firefoxpwa/overlayfs firefoxpwa/overlayfs/upper firefoxpwa/overlayfs/work
[Install]
WantedBy=default.target

Prerequisites

  • Your OS uses systemd

  • Firefox is installed

  • fuse-overlayfs is installed

From your package manager

Arch/Manjaro

sudo pacman -S fuse-overlayfs

CentOS

sudo yum -y install fuse-overlayfs

Debian/Ubuntu

sudo apt-get install fuse-overlayfs

Fedora

sudo dnf -y install fuse-overlayfs

openSUSE

sudo zypper install fuse-overlayfs

Installation

  1. Copy "firefoxpwa-runtime-overlayfs.service" to $HOME/.config/systemd/user
  • cURL
curl https://gist.githubusercontent.com/JJRcop/46450e4f7aa0770a60cb8d4a61ecd2f6/raw/6cd70d4153c4b3f0fb66ecfe1c8552fb1e48d1cd/firefoxpwa-runtime-overlayfs.service -o $HOME/.config/systemd/user/firefoxpwa-runtime-overlayfs.service
  • Wget
wget https://gist.githubusercontent.com/JJRcop/46450e4f7aa0770a60cb8d4a61ecd2f6/raw/6cd70d4153c4b3f0fb66ecfe1c8552fb1e48d1cd/firefoxpwa-runtime-overlayfs.service -O $HOME/.config/systemd/user/firefoxpwa-runtime-overlayfs.service
  1. Modify AssertPathIsDirectory= and lowerdir= paths to point to your Firefox runtime
FIREFOX_RUNTIME=/usr/lib/firefox sh -c 'sed -i -e "s|%%runtime_path|${FIREFOX_RUNTIME}|" $HOME/.config/systemd/user/firefoxpwa-runtime-overlayfs.service'
  1. Install the service
systemctl --user enable --now firefoxpwa-runtime-overlayfs.service
  1. Check that the runtime overlay was installed correctly by clicking on the extension in Firefox
  2. Finally, make sure Always patch runtime and profile is enabled in PWAsForFirefox

Non-systemd OS

You can make an equivalent script which runs when you log in (a form that is run as the logged in user is preferred) This section will try to be POSIX-compliant to help the most people

Your script should:

  1. Create upper/ and work/ directories under $XDG_RUNTIME_DIR/firefoxpwa/overlayfs
  • $XDG_RUNTIME_DIR may be substituted for any tmpfs, ramdisk, or equivalent ephemeral directory if /run/user/$(id -u) is not used by your OS
  1. Run fuse-overlayfs -f -o squash_to_uid=$(id -u),squash_to_gid=$(id -g),lowerdir=%%runtime_path,upperdir=$XDG_RUNTIME_DIR/firefoxpwa/overlayfs/upper,workdir=$XDG_RUNTIME_DIR/firefoxpwa/overlayfs/work $HOME/.local/share/firefoxpwa/runtime/, replacing %%runtime_path with the path to your Firefox runtime

When logging out

  1. Run fusermount -u $HOME/.local/share/firefoxpwa/runtime/ to unmount the runtime overlayfs
  2. Destroy the upper/ and work/ directories, or leave them if your OS destroys them for you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment