How to Build Firefox Kiosk on Ubuntu Core 24 Using Ubuntu-Frame and Wayland

This tutorial will walk you through the step of setting up a kiosk on Ubuntu Core 24 using Ubuntu-Frame, Mir-Kiosk and Firefox. I won’t be discussing how to install Ubuntu Core as that is beyond the scope of this project. You can learn how to get up and running with Ubuntu Core here.

Method 1: Install Using a Bash Script (Quick & Easy)

I made a bash script that will do everything on this page in one simple step. You can find it on my GitHub page over here https://github.com/nwdigital/firefox-kiosk. Ctrl + V or right click + copy the contents of install-firefox-frame-kiosk.sh.

Open a new file using VI Editor. Type the command below.

vi install-firefox-frame-kiosk.sh

A new blank file should open in the editor. Press the “i” key on your keyboard once to enter input mode.

While in input mode, right click and click “Paste” from the context menu.

To exit Input mode press the “Esc” key on your keyboard and type in ‘:wq’ and press the Enter key.

Make install-firefox-frame-kiosk.sh executable. Copy and paste the following in terminal and hit enter.

chmod a+x install-firefox-frame-kiosk.sh

Run the script to install everything and start up the Firefox Ubuntu Frame Kiosk. Copy the following code and paste it into terminal and hit enter.

./install-firefox-frame-kiosk.sh

After a while, you should have ubuntu-frame and Firefox snaps installed. Then the script will setup the systemd service and when it’s done, it will launch Firefox in Ubuntu-Frame.

If it doesn’t start up or there is a journalctl or systemctl error message, try restarting the service by typing in the following command and the service should start up after one or two tries.

sudo systemctl restart kiosk.service

You can change the URL being displayed in the kiosk at any time. Just issue the following command with a new URL value and hit enter. It will restart Ubuntu-Frame and load up the new website.

./kiosk -u "https://www.ioblist.com"

BTW, that URL up there ↑ is one of my creations! It the main reason I created these scripts and this tutorial.

Method 2: Install Following the Instructions Below

Once you’re done setting up Ubuntu Core device, log in via Terminal and install Ubuntu Frame using the following command:

snap install ubuntu-frame

Once ubuntu-frame installation is complete, let’s install the Firefox snap.

snap install firefox

Installing Firefox can take a bit of time, but once it’s finished, we need to connect it to the Wayland interface provided by mir-kiosk.

Connect Firefox to the Wayland interface using the following command.

snap connect firefox:wayland ubuntu-frame:wayland

In the next step, we will be creating a systemd service file to manage starting, stopping, and restarting Firefox.

IMPORTANT!

In order for the next to steps to work correctly, you will need to connect to Ubuntu Core with an SFTP client. We have to do this since there is no graphical text editor to use in Ubuntu Core and we need to maintain the magic variables. If we were to paste these in terminal, the values would no longer function.

TIP: Use your private SSH key to connect with FileZilla and your user name. I chose Login Type: Interactive and added my private key in FileZilla Settings > SFTP. All files will first go into your home folder. We will move the service file to the proper location at a later time.

Now we are ready to create the service file. Create a new file in a text editor and name it ‘kiosk.service’. Then, copy the entire contents of the service file code below and paste it into the file you just created. Be sure to REPLACE ‘nwdigital’ in the ExecStart line with the name of your user’s home folder. It should be the same as the Username you used to connect with FileZilla.

[Unit]
Description=Firefox Wayland Kiosk
After=snap.ubuntu-frame.daemon.service snap.ubuntu-frame-osk.daemon.service getty.target
Wants=snap.ubuntu-frame-osk.daemon.service
Requires=snap.ubuntu-frame.daemon.service
Conflicts=display-manager.service
StartLimitIntervalSec=0

[Service]
# https://discourse.ubuntu.com/t/environment-variables-for-wayland-hackers/12750
Type=simple
Restart=always
RestartSec=3
Environment=WAYLAND_DISPLAY=wayland-0
Environment=MOX_CRASHREPORTER_DISABLE=1
Environment=GDK_BACKEND=wayland
Environment=MOZ_ENABLE_WAYLAND=1
Environment=HOME=/root
Environment=XDG_RUNTIME_DIR=/run/user/0
Environment=XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
ExecStartPre=/snap/bin/firefox --CreateProfile "default"
ExecStart=/bin/sh -c 'export KIOSK_URL=$(cat /home/nwdigital/kiosk_url); exec /snap/bin/firefox -P default --kiosk --private-window --disable-pinch $KIOSK_URL'
Nice=15

[Install]
WantedBy=graphical.target

In the file above, we create a system service to manage Firefox, and we added some necessary environment variables to make Firefox work in ubuntu-frame.

If you don’t want to disable pinch to zoom, remove –disable-pinch from the ExecStart line above.

Save the edited version of kiosk.service to your home folder using FileZilla.

If you want, you can create the file ‘kiosk_url’ and upload it to your home folder like you did with the service file. Alternatively, you can have it automatically created when you set the URL using the script below.

Next, we need to create the ‘kiosk’ script file so we can make instant changes to the kiosk URL. This will go in your home folder as well.

Create a new file named ‘kiosk’ using your text editor and paste the contents of the script below into it.

Again, be sure to update the home folder path in the update URL function to match your user’s home folder.

Save the file to your home folder using FileZilla.

#!/bin/bash
############################################################
# Help                                                     #
############################################################
Help()
{
   # Display Help
   echo "Syntax: scriptTemplate [-g|h|v|V]"
   echo "options:"
   echo "-h     Print this Help."
   echo "-u     Sets the url for the kiosk."
}

############################################################
# Process the input options. Add options as needed.        #
############################################################

# Get the options
while getopts ":hu" option; do
    case $option in
        h) # display Help
            Help
            exit;;
        u) # update url
            echo $2 > /home/nwdigital/kiosk_url
            sudo systemctl restart kiosk
            echo "New url is now: " $2
            exit;;
        \?) # Invalid option
            echo "Error: Invalid option"
            exit;;
   esac
done

Let’s now open up a terminal window to your Ubuntu Core device so we can make the above script executable.

Once connected, you should be in your home folder, type the command below to make it executable.

sudo chmod a+x kiosk

Now we need to move the service file to the appropriate location. In terminal type the command below.

sudo mv kiosk.service /etc/systemd/system/

Let’s enable the service, type the command below to enable kiosk.service

sudo systemctl enable kiosk.service

Ok, time to start the service up!

sudo systemctl start kiosk

You should now see Firefox running. If you didn’t create the kiosk_url file, don’t worry. Finish going through any prompts for Firefox first start and when you’re done, enter the command below using the URL of your choice to set the new URL for the kiosk.

./kiosk -u "https://nwdigital.cloud/"

If everything works out, you should now see Firefox loaded up with the website or your choice in Ubuntu-Frame.

Upon rebooting, everything should come back up automatically. Enjoy!

Starting, Stopping, and Restarting the Kiosk

To start, stop or restart the Firefox Kiosk, simply enter one of the following systemctl command in terminal

sudo systemctl start kiosk
sudo systemctl restart kiosk
sudo systemctl stop kiosk

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.