From 61503a5c94cbe3142e00152d59da8df126cf3b1e Mon Sep 17 00:00:00 2001
From: Ruben Rodriguez <ruben@trisquel.info>
Date: Fri, 17 Jan 2020 15:49:40 -0500
Subject: [PATCH] software-properties: fixed livepatch removal bug

---
 .../disable-livepatch.patch                   | 87 +++++++++++++++++++
 helpers/make-software-properties              |  5 +-
 2 files changed, 90 insertions(+), 2 deletions(-)
 create mode 100644 helpers/DATA/software-properties/disable-livepatch.patch

diff --git a/helpers/DATA/software-properties/disable-livepatch.patch b/helpers/DATA/software-properties/disable-livepatch.patch
new file mode 100644
index 00000000..9612792f
--- /dev/null
+++ b/helpers/DATA/software-properties/disable-livepatch.patch
@@ -0,0 +1,87 @@
+--- a/softwareproperties/LivepatchService.py	2020-01-06 15:10:21.950486591 -0500
++++ b/softwareproperties/LivepatchService.py 2020-01-06 15:07:49.294703393 -0500
+@@ -29,8 +29,6 @@
+     import dateutil.parser
+     import requests_unixsocket
+ 
+-    gi.require_version('Snapd', '1')
+-    from gi.repository import Snapd
+ except(ImportError, ValueError):
+     pass
+ 
+@@ -41,9 +39,6 @@
+     retry
+ )
+ 
+-from softwareproperties.LivepatchSnap import LivepatchSnap
+-
+-
+ def datetime_parser(json_dict):
+     for (key, value) in json_dict.items():
+         try:
+@@ -89,7 +84,6 @@
+ 
+         self._timeout_id = 0
+ 
+-        self._snap = LivepatchSnap()
+         self._session = requests_unixsocket.Session()
+ 
+         # Init Properties
+@@ -129,8 +123,6 @@
+             # string rapresents the error message that needs to be shown if the
+             # callable returns false.
+             rules = [
+-                (lambda: self._snap.get_status() != Snapd.SnapStatus.UNKNOWN,
+-                    _('Canonical Livepatch snap is not available.')),
+                 (has_gnome_online_accounts,
+                     _('Gnome Online Accounts is required to enable Livepatch.')),
+                 (is_current_distro_lts,
+@@ -177,16 +169,7 @@
+         Returns:
+             (False, '') if successful, (True, error_message) otherwise.
+         """
+-        if self._enabled == enabled:
+-            return False, ''
+-
+-        if not enabled:
+-            return self._disable_service()
+-        elif self._snap.get_status() == Snapd.SnapStatus.ACTIVE:
+-            return self._enable_service(token)
+-        else:
+-            success, msg = self._snap.enable_or_install()
+-            return self._enable_service(token) if success else (True, msg)
++        return self._disable_service()
+ 
+     def get_status(self):
+         """Synchronously retrieve the status of Canonical Livepatch.
+@@ -194,13 +177,7 @@
+         Returns:
+             str: The status. A valid string for success, None otherwise.
+         """
+-        try:
+-            params = {'verbosity': 3, 'format': 'json'}
+-            r = self._session.get(self.STATUS_ENDPOINT, params=params)
+-            return r.json(object_hook=datetime_parser)
+-        except Exception as e:
+-            logging.debug('Failed to get Livepatch status: {}'.format(str(e)))
+-            return None
++        return None
+ 
+     # Private methods
+     def _enable_service(self, token):
+--- a/softwareproperties/gtk/SoftwarePropertiesGtk.py	2020-01-06 15:10:21.970486562 -0500
++++ b/softwareproperties/gtk/SoftwarePropertiesGtk.py	2020-01-06 15:08:00.466687527 -0500
+@@ -1038,12 +1037,7 @@
+                                     self.datadir)
+             d.run()
+ 
+-        self.quit_when_livepatch_responds = False
+-        if self.livepatch_page.waiting_livepatch_response:
+-            self.quit_when_livepatch_responds = True
+-            self.hide()
+-        else:
+-            self.quit()
++        self.quit()
+ 
+     def on_button_add_cdrom_clicked(self, widget):
+         """ when a cdrom is requested for adding """
diff --git a/helpers/make-software-properties b/helpers/make-software-properties
index 2b0e654f..e8e2613f 100644
--- a/helpers/make-software-properties
+++ b/helpers/make-software-properties
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-#    Copyright (C) 2011-2016  Rubén Rodríguez <ruben@trisquel.info>
+#    Copyright (C) 2011-2020  Ruben Rodriguez <ruben@trisquel.info>
 #    Copyright (C) 2011  Carlos Pais <freemind@lavabit.com>
 #    Copyright (C) 2019 Mason Hock <mason@masonhock.com>
 #
@@ -19,7 +19,7 @@
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 #
 
-VERSION=2
+VERSION=3
 
 . ./config
 
@@ -69,6 +69,7 @@ rm -rf tests
 sed '/gir1.2-snapd-1/d' -i debian/control
 sed '/self.init_livepatch/d' -i softwareproperties/gtk/SoftwarePropertiesGtk.py
 patch -p0 < $DATA/remove_livepatch_from_gtk_ui.patch
+patch -p1 < $DATA/disable-livepatch.patch
 sed 's/status = self.get_status()/status = Snapd.SnapStatus.UNKNOWN/' -i softwareproperties/LivepatchSnap.py
 
 rm data/software-properties-drivers.desktop.in
-- 
GitLab