Skip to content

Instantly share code, notes, and snippets.

@bonelifer
Created June 21, 2024 18:57
Show Gist options
  • Save bonelifer/1ed4301385038a6342cb1423448e6e67 to your computer and use it in GitHub Desktop.
Save bonelifer/1ed4301385038a6342cb1423448e6e67 to your computer and use it in GitHub Desktop.
Bash script to switch from Firefox Snap package to the Debian APT package from Mozilla.
#!/bin/bash
# Script to switch Firefox from Snap to Debian package from Mozilla repository
#
# Based on the Ansible playbook found here: https://www.hackitu.de/firefox_snap_apt/
# Ensure the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Function to remove Snap package
# This function removes the Firefox Snap package if it exists
remove_snap_package() {
snap remove firefox
}
# Function to get and add Mozilla repository key
# This function downloads the Mozilla repository signing key and adds it to the trusted keys
add_mozilla_repo_key() {
wget -O /etc/apt/trusted.gpg.d/mozilla.asc https://packages.mozilla.org/apt/repo-signing-key.gpg
chown root:root /etc/apt/trusted.gpg.d/mozilla.asc
chmod 0644 /etc/apt/trusted.gpg.d/mozilla.asc
}
# Function to add Mozilla repository
# This function adds the Mozilla repository to the APT sources list and updates the package list
add_mozilla_repository() {
echo "deb [signed-by=/etc/apt/trusted.gpg.d/mozilla.asc] https://packages.mozilla.org/apt mozilla main" | tee /etc/apt/sources.list.d/mozilla.list
apt-get update
}
# Function to pin Mozilla packages
# This function sets the APT pinning priority for packages from the Mozilla repository
pin_mozilla_packages() {
cat <<EOF > /etc/apt/preferences.d/mozilla
Package: *
Pin: origin packages.mozilla.org
Pin-Priority: 1000
EOF
chown root:root /etc/apt/preferences.d/mozilla
chmod 0644 /etc/apt/preferences.d/mozilla
}
# Function to install Firefox from Debian package
# This function installs Firefox from the Debian package provided by the Mozilla repository
install_firefox() {
apt-get install -y firefox
}
# Execute functions in the proper order
remove_snap_package
add_mozilla_repo_key
add_mozilla_repository
pin_mozilla_packages
install_firefox
# Print completion message
echo "Firefox has been switched from Snap to Debian package from Mozilla repository."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment