Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Last active July 14, 2023 06:24
Show Gist options
  • Save jc00ke/4dd8c7afa79bd78412f93bce09a5de84 to your computer and use it in GitHub Desktop.
Save jc00ke/4dd8c7afa79bd78412f93bce09a5de84 to your computer and use it in GitHub Desktop.
Migrate Firefox from snap back to deb on Ubuntu Jammy+
#!/bin/env bash
sudo snap remove firefox
sudo add-apt-repository ppa:mozillateam/ppa
echo '
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
' | sudo tee /etc/apt/preferences.d/mozilla-firefox
echo 'Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";' | sudo tee /etc/apt/apt.conf.d/51unattended-upgrades-firefox
sudo apt install firefox
# consider the ramifications of the following line and uncomment if you want
# mv ~/snap/firefox/common/.mozilla/firefox ~/.mozilla/
@Flimm
Copy link

Flimm commented Aug 30, 2022

This doesn't seem to migrate the user's Firefox settings from ~/snap/firefox/common/.mozilla/firefox/ to ~/.mozilla/firefox/

@jc00ke
Copy link
Author

jc00ke commented Aug 31, 2022

You are correct, because I didn't need to do that 😜

I'll add that as a comment but I don't think that's something I would do automatically.

@wolkenarchitekt
Copy link

wolkenarchitekt commented Sep 2, 2022

Thanks for sharing! Just to clarify, should "distro_codename" be 'jammy'?

@jc00ke
Copy link
Author

jc00ke commented Sep 4, 2022

Thanks for sharing! Just to clarify, should "distro_codename" be 'jammy'?

Yes, in that that's the value but no, in that I believe it gets set by apt so I would not hard-code it.

@Ben-Voris
Copy link

Just updated a WSL2 to Jammy. I had removed snap before but it reappeared, so I did this:

sudo rm -rf /var/cache/snapd/ && sudo apt autoremove --purge snapd gnome-software-plugin-snap && rm -fr ~/snap && sudo apt-mark hold snapd

Then I tried your commands. But this:

sudo add-apt-repository ppa:mozillateam/ppa

Fails with:

Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 364, in
sys.exit(0 if addaptrepo.main() else 1)
File "/usr/bin/add-apt-repository", line 347, in main
shortcut = handler(source, **shortcut_params)
File "/usr/lib/python3/dist-packages/softwareproperties/shortcuts.py", line 40, in shortcut_handler
return handler(shortcut, **kwargs)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 82, in init
if self.lpppa.publish_debug_symbols:
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 120, in lpppa
self._lpppa = self.lpteam.getPPAByName(name=self.ppaname)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 107, in lpteam
self._lpteam = self.lp.people(self.teamname)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 98, in lp
self._lp = login_func("%s.%s" % (self.module, self.class.name),
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 494, in login_anonymously
return cls(
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 230, in init
super(Launchpad, self).init(
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 472, in init
self._wadl = self._browser.get_wadl_application(self._root_uri)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 447, in get_wadl_application
response, content = self._request(url, media_type=wadl_type)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 389, in _request
response, content = self._request_and_retry(
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 359, in _request_and_retry
response, content = self._connection.request(
File "/usr/lib/python3/dist-packages/httplib2/init.py", line 1725, in request
(response, content) = self._request(
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 144, in _request
response, content = super(LaunchpadOAuthAwareHttp, self)._request(
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 184, in _request
return super(RestfulHttp, self)._request(
File "/usr/lib/python3/dist-packages/httplib2/init.py", line 1441, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/lib/python3/dist-packages/httplib2/init.py", line 1363, in _conn_request
conn.connect()
File "/usr/lib/python3/dist-packages/httplib2/init.py", line 1155, in connect
self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.10/ssl.py", line 1071, in _create
self.do_handshake()
File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)


Trying to install firefox gives "firefox : PreDepends: snapd but it is not installable"

Any ideas?

@jc00ke
Copy link
Author

jc00ke commented May 2, 2023

@Ben-Voris I wonder if your apt is still set to install the snap? Maybe try sudo apt autoremove -y && sudo apt update then try to add and install.

@Ben-Voris
Copy link

No change.

: sudo apt autoremove -y && sudo apt update
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
: sudo add-apt-repository ppa:mozillateam/ppa
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 364, in <module>
    sys.exit(0 if addaptrepo.main() else 1)
  File "/usr/bin/add-apt-repository", line 347, in main
    shortcut = handler(source, **shortcut_params)
  File "/usr/lib/python3/dist-packages/softwareproperties/shortcuts.py", line 40, in shortcut_handler
    return handler(shortcut, **kwargs)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 82, in __init__
    if self.lpppa.publish_debug_symbols:
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 120, in lpppa
    self._lpppa = self.lpteam.getPPAByName(name=self.ppaname)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 107, in lpteam
    self._lpteam = self.lp.people(self.teamname)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 98, in lp
    self._lp = login_func("%s.%s" % (self.__module__, self.__class__.__name__),
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 494, in login_anonymously
    return cls(
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 230, in __init__
    super(Launchpad, self).__init__(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 472, in __init__
    self._wadl = self._browser.get_wadl_application(self._root_uri)
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 447, in get_wadl_application
    response, content = self._request(url, media_type=wadl_type)
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 389, in _request
    response, content = self._request_and_retry(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 359, in _request_and_retry
    response, content = self._connection.request(
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1725, in request
    (response, content) = self._request(
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 144, in _request
    response, content = super(LaunchpadOAuthAwareHttp, self)._request(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 184, in _request
    return super(RestfulHttp, self)._request(
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1441, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1363, in _conn_request
    conn.connect()
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1155, in connect
    self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
  File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

@jc00ke
Copy link
Author

jc00ke commented May 9, 2023

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997) what's this about? I'm not a pythonista but I'd look into that, maybe your network settings?

@Ben-Voris
Copy link

I’ve seen a similar error in other contexts. For example, I have a setting in my .gitconfig that disables certificate validation for one of my employer’s internal servers.

Whatever the problem, it doesn’t affect apt when it accesses other servers.

I know next to nothing about certificate validation, so I have no clue what might be broken, but I wonder if, on this version, removing snapd or Firefox might remove/break some certificate thingy.

I don’t know if it’s possible to install two WSL instances running the same distribution. If it is, I could test if the add-apt-repository works before I remove anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment