From ed321062731abb41bdee0a183ee1d4346b75674d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20Guzm=C3=A1n?= <ark@switnet.org>
Date: Mon, 23 Jan 2023 02:04:09 +0000
Subject: [PATCH] software-properties,distro-info-data: fix PPA integration by
 adding upstream codename info.

---
 helpers/DATA/distro-info-data/trisquel.csv    | 28 ++++++-------
 .../fix_PPA_upstream_codename.patch           | 21 ++++++++++
 .../DATA/software-properties/trisquel_info.py | 11 +++++-
 helpers/make-distro-info-data                 |  6 +--
 helpers/make-software-properties              | 39 ++++---------------
 5 files changed, 54 insertions(+), 51 deletions(-)
 create mode 100644 helpers/DATA/software-properties/fix_PPA_upstream_codename.patch

diff --git a/helpers/DATA/distro-info-data/trisquel.csv b/helpers/DATA/distro-info-data/trisquel.csv
index 867dd3d1..640cebb6 100644
--- a/helpers/DATA/distro-info-data/trisquel.csv
+++ b/helpers/DATA/distro-info-data/trisquel.csv
@@ -1,14 +1,14 @@
-version,codename,series,created,release,eol
-2.0 LTS,Robur,robur,2007-10-18,2008-07-24,2011-05-12
-3.0,Dwyn,dwyn,2008-10-30,2009-09-08,2010-10-23
-3.5,Awen,awen,2009-04-23,2010-03-22,2011-04-30
-4.0 LTS,Taranis,taranis,2009-10-29,2010-09-17,2013-05-09
-4.5,Slaine,slaine,2010-04-29,2011-03-24,2012-04-10
-5.0,Dagda,dagda,2010-10-10,2011-09-17,2012-10-28
-5.5,Brigantia,brigantia,2011-04-28,2012-04-16,2013-05-09
-6.0 LTS,Toutanis,toutanis,2011-10-13,2013-03-11,2017-04-28
-7.0 LTS,Belenos,belenos,2013-10-17,2014-11-03,2019-04-25
-8.0 LTS,Flidas,flidas,2015-10-22,2018-04-18,2021-04-21
-9.0 LTS,Etiona,etiona,2017-10-19,2020-10-16,2023-04-26
-10.0 LTS,Nabia,nabia,2019-10-17,2021-12-16,2025-04-23
-11.0 LTS,Aramo,aramo,2021-10-14,2027-04-21,2027-04-21
+version,codename,series,created,release,eol,upstream
+2.0 LTS,Robur,robur,2007-10-18,2008-07-24,2011-05-12,hardy
+3.0,Dwyn,dwyn,2008-10-30,2009-09-08,2010-10-23,jaunty
+3.5,Awen,awen,2009-04-23,2010-03-22,2011-04-30,karmik
+4.0 LTS,Taranis,taranis,2009-10-29,2010-09-17,2013-05-09,lucid
+4.5,Slaine,slaine,2010-04-29,2011-03-24,2012-04-10,maverick
+5.0,Dagda,dagda,2010-10-10,2011-09-17,2012-10-28,natty
+5.5,Brigantia,brigantia,2011-04-28,2012-04-16,2013-05-09,oneiric
+6.0 LTS,Toutanis,toutanis,2011-10-13,2013-03-11,2017-04-28,precise
+7.0 LTS,Belenos,belenos,2013-10-17,2014-11-03,2019-04-25,trusty
+8.0 LTS,Flidas,flidas,2015-10-22,2018-04-18,2021-04-21,xenial
+9.0 LTS,Etiona,etiona,2017-10-19,2020-10-16,2023-04-26,bionic
+10.0 LTS,Nabia,nabia,2019-10-17,2021-12-16,2025-04-23,focal
+11.0 LTS,Aramo,aramo,2021-10-14,2027-04-21,2027-04-21,jammy
diff --git a/helpers/DATA/software-properties/fix_PPA_upstream_codename.patch b/helpers/DATA/software-properties/fix_PPA_upstream_codename.patch
new file mode 100644
index 00000000..f74374da
--- /dev/null
+++ b/helpers/DATA/software-properties/fix_PPA_upstream_codename.patch
@@ -0,0 +1,21 @@
+diff -Nru software-properties-0.99.22.4+11.0trisquel9/softwareproperties/ppa.py software-properties-0.99.22.4+11.0trisquel9_fix/softwareproperties/ppa.py
+--- software-properties-0.99.22.4+11.0trisquel9/softwareproperties/ppa.py	2023-01-21 14:29:00.314035991 -0600
++++ software-properties-0.99.22.4+11.0trisquel9_fix/softwareproperties/ppa.py	2023-01-21 14:31:47.658510565 -0600
+@@ -32,6 +32,8 @@
+ 
+ from urllib.parse import urlparse
+ 
++from softwareproperties.trisquel_info import trisquel_upstream_rel
++
+ 
+ PPA_URI_FORMAT = 'https://ppa.launchpadcontent.net/{team}/{ppa}/ubuntu/'
+ PRIVATE_PPA_URI_FORMAT = 'https://private-ppa.launchpadcontent.net/{team}/{ppa}/ubuntu/'
+@@ -85,7 +87,7 @@
+ 
+             uri_format = PRIVATE_PPA_URI_FORMAT if self.lpppa.private else PPA_URI_FORMAT
+             uri = uri_format.format(team=self.teamname, ppa=self.ppaname)
+-            line = ('%s %s %s %s' % (self.binary_type, uri, self.dist, ' '.join(comps)))
++            line = ('%s %s %s %s' % (self.binary_type, uri, trisquel_upstream_rel, ' '.join(comps)))
+             self._set_source_entry(line)
+ 
+     @property
diff --git a/helpers/DATA/software-properties/trisquel_info.py b/helpers/DATA/software-properties/trisquel_info.py
index 3695a20c..66f41157 100644
--- a/helpers/DATA/software-properties/trisquel_info.py
+++ b/helpers/DATA/software-properties/trisquel_info.py
@@ -3,7 +3,7 @@
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
+#    the Free Software Foundation; either version 3 of the License, or
 #    (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
@@ -31,7 +31,14 @@ def trisquel_eol():
                                 eol_datetime = datetime.strptime(line['eol'], '%Y-%m-%d')
                                 eol_date = eol_datetime.date()
                                 return eol_date
+def trisquel_upstream():
+    with open('/usr/share/distro-info/trisquel.csv', 'r') as distro_data:
+                trisquel_distro_data = csv.DictReader(distro_data)
+                for line in trisquel_distro_data:
+                        if line['series'] == (release_name):
+                                codename_upstream = line['upstream']
+                                return(codename_upstream)
 
 trisquel_rel_desc = release_description
 trisquel_eol = trisquel_eol()
-
+trisquel_upstream_rel = trisquel_upstream()
diff --git a/helpers/make-distro-info-data b/helpers/make-distro-info-data
index e5847848..a85a0b18 100644
--- a/helpers/make-distro-info-data
+++ b/helpers/make-distro-info-data
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-#    Copyright (C) 2022 Luis Guzman <ark@switnet.org>
+#    Copyright (C) 2023 Luis Guzman <ark@switnet.org>
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 #
 
-VERSION=4
+VERSION=5
 
 . ./config
 
@@ -30,7 +30,7 @@ cp $DATA/trisquel.csv  ./
 # The Breaks prevents upgrades
 sed '/Breaks:/d' -i debian/control
 
-changelog "Adding trisquel distro info."
+changelog "Adding trisquel distro info and upstream equivalent."
 
 compile
 
diff --git a/helpers/make-software-properties b/helpers/make-software-properties
index b0dc3ebd..f218bb26 100644
--- a/helpers/make-software-properties
+++ b/helpers/make-software-properties
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-#    Copyright (C) 2022 Luis Guzman <ark@switnet.org>
+#    Copyright (C) 2023 Luis Guzman <ark@switnet.org>
 #    Copyright (C) 2011-2022  Ruben Rodriguez <ruben@trisquel.info>
 #    Copyright (C) 2019 Mason Hock <mason@masonhock.com>
 #    Copyright (C) 2011  Carlos Pais <freemind@lavabit.com>
@@ -20,37 +20,10 @@
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 #
 
-VERSION=9
+VERSION=11
 
 . ./config
 
-cat << EOF | patch -p1
---- source.orig/softwareproperties/SoftwareProperties.py        2014-04-14 17:10:58.000000000 +0200
-+++ source/softwareproperties/SoftwareProperties.py     2014-05-18 03:02:05.309290804 +0200
-@@ -722,8 +746,19 @@
-     site is in whitelist or the shortcut implementer adds it.
-     """
- 
--    deb_line = shortcut.SourceEntry().line
--    file = shortcut.sourceparts_file
-+    codenames = {}
-+    codenames["aramo"] = "jammy"
-+    codenames["nabia"] = "focal" 
-+    codenames["etiona"] = "bionic" 
-+    codenames["flidas"] = "xenial" 
-+    codenames["belenos"] = "trusty" 
-+    codenames["toutatis"] = "precise" 
-+    codenames["brigantia"] = "oneiric" 
-+    codenames["dagda"] = "natty"
-+    codenames["slaine"] = "maverick"
-+    codenames["taranis"] = "lucid"
-+    codenames["awen"] = "karmic" 
-+    (deb_line, file) = shortcut.expand(codename=codenames[self.distro.codename])
-     deb_line = self.expand_http_line(deb_line)
-     debsrc_entry_type = 'deb-src' if enable_source_code else '# deb-src'
-     debsrc_line = debsrc_entry_type + deb_line[3:]
-EOF
-
   #Temporary removal of livepatch LP:1965993
   #patch -p1 < $DATA/remove_livepatch_from_gtk_uiv1_1.patch
   #patch -p1 < $DATA/disable-livepatch.patch
@@ -59,8 +32,8 @@ rm softwareproperties/gtk/UbuntuProPage.py
 patch --no-backup-if-mismatch -p0 < $DATA/remove_snap_label.patch
 
 #Python specific changes
-cp $DATA/trisquel_info.py softwareproperties/gtk/
-sed -i '/import softwareproperties.SoftwareProperties/a from softwareproperties.gtk.trisquel_info import trisquel_rel_desc, trisquel_eol' softwareproperties/gtk/SoftwarePropertiesGtk.py
+cp $DATA/trisquel_info.py softwareproperties/
+sed -i '/import softwareproperties.SoftwareProperties/a from softwareproperties.trisquel_info import trisquel_rel_desc, trisquel_eol' softwareproperties/gtk/SoftwarePropertiesGtk.py
 sed -i 's|eol_date = distro.eol|eol_date = trisquel_eol|' softwareproperties/gtk/SoftwarePropertiesGtk.py
 sed -i 's|eol_text = .*|eol_text = trisquel_rel_desc|' softwareproperties/gtk/SoftwarePropertiesGtk.py
 #Allow to start and remove drivers tab for qt flavor
@@ -109,8 +82,10 @@ sed -i '/init_ubuntu_pro/d' softwareproperties/gtk/SoftwarePropertiesGtk.py
 
 #Livepatch - aramo
 patch --no-backup-if-mismatch -p0 < $DATA/aramo_rm_livepatch.patch
+#Patch codename for PPAs
+patch --no-backup-if-mismatch -p1 < $DATA/fix_PPA_upstream_codename.patch
 
-changelog "Removed Ubuntu-specifc tests, Livepatch, Snap"
+changelog "Removed Ubuntu-specifc tests, Livepatch, Snap and fix PPA integration."
 
 compile
 
-- 
GitLab