Install Firefox PPA version over Snap version

Posted by ads' corner on Saturday, 2023-01-07
Posted in [Linux][Operating-Systems]

It was time to update my laptop, and I already knew that the update will bring Snap, and installs the Snap Firefox version. Along with many known problems. Previously the laptop was on 20.04 LTS, but this version is about to loose support.

I ran through the upgrade, and then added an Ansible Playbook to handle the Firefox installation, remove the Snap version and install the PPA version. Most of my laptop configuration is handled using Ansible Playbooks.

The task is split into two tasks:

  1. Uninstall the Snap version
  2. Install the PPA version

And a couple smaller side quests.

Uninstall the Snap version

For this I first need to figure out if the Snap Firefox version is installed. The way to do this is run snap list firefox and deal with the error if it’s not installed:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  - name: Figure out if Firefox Snap version is installed
    local_action:
      module: command
      cmd: "snap list firefox"
    register: snap_firefox_installed
    failed_when: "snap_firefox_installed.rc > 0 and 'no matching snaps installed' not in snap_firefox_installed.stderr"
    changed_when: false

  - block:
    - name: Uninstall Firefox snap
      local_action:
        module: command
        cmd: "snap remove --purge firefox"

    when: "'mozilla' in snap_firefox_installed.stdout"

Ubuntu also likes to install transition packages which then pull in the Snap version. They need to go as well:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  - name: Detect source of traditional Firefox packages
    shell:
      cmd: "dpkg --list | grep firefox"
    register: firefox_package
    changed_when: false

  - block:
    - name: Uninstall transitional packake
      apt:
        name:
          - firefox
          - firefox-locale-de
          - firefox-locale-en
        state: absent

    when: "'1snap' in firefox_package.stdout or 'Transitional package' in firefox_package.stdout"

After this step, there should be no more Snap version installed. Time to do the actual install.

Install the Firefix PPA version

Mozilla provides a PPA repository with Firefox packages: ppa:mozillateam/ppa. This is used to add the repository, and then override the default firefox package.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  - name: Mozilla repository
    apt_repository:
      repo: 'ppa:mozillateam/ppa'
      state: present
      filename: mozilla
    register: repo_mozilla

  - name: Upload /etc/apt/preferences.d/mozilla-firefox
    template:
      src: "templates/apt_preferences_d_mozilla-firefox"
      dest: "/etc/apt/preferences.d/mozilla-firefox"
      owner: "root"
      group: "root"
      mode: "0644"

  - name: Upload /etc/apt/apt.conf.d/51unattended-upgrades-firefox
    template:
      src: "templates/apt_apt_conf_d_51_unattended-upgrades-firefox"
      dest: "/etc/apt/apt.conf.d/51unattended-upgrades-firefox"
      owner: "root"
      group: "root"
      mode: "0644"

  - name: Firefox package
    apt:
      name:
        - firefox
      state: present

The content of /etc/apt/preferences.d/mozilla-firefox:

1
2
3
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001

The content of /etc/apt/apt.conf.d/51unattended-upgrades-firefox:

1
Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";

This pins the PPA version, and allows automatic upgrades.

Summary

Last but not least show which version is installed:

1
2
3
4
5
6
7
8
9
  - name: Extract Firefox packages
    shell:
      cmd: "dpkg --list | grep firefox"
    register: firefox_package_show
    changed_when: false

  - name: Show Firefox packages
    debug:
      msg: "{{ firefox_package_show.stdout }}"

This Playbook needs to run after every OS upgrade. Ubuntu tries to reinstall the Snap version.


Categories: [Linux] [Operating-Systems]