[sysadmin/neon-tooling] /: port add & remove repository to use deb822 source files

Carlos De Maine <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 53922705b16a09485e20bbc328f468003aa2bb74 by Carlos De Maine.
Committed on 04/08/2026 at 02:48.
Pushed by carlosdem into branch 'master'.

port add & remove repository to use deb822 source files

M  +62   -30   lib/apt/repository.rb
M  +34   -25   nci/lib/setup_repo.rb

https://invent.kde.org/sysadmin/neon-tooling/-/commit/53922705b16a09485e20bbc328f468003aa2bb74

diff --git a/lib/apt/repository.rb b/lib/apt/repository.rb
index 9af17f4b..6cf50577 100644
--- a/lib/apt/repository.rb
+++ b/lib/apt/repository.rb
@@ -26,22 +26,40 @@ require 'tty/command'
 module Apt
   # Represents a repository
   class Repository
-    def initialize(name)
+    DEFAULT_SOURCES_DIR = '/etc/apt/sources.list.d/'
+
+    class << self
+      def config_dir
+        @config_dir ||= DEFAULT_SOURCES_DIR
+      end
+      attr_writer :config_dir
+    end
+
+    def initialize(name, deb822_sources: nil)
       require_relative '../apt.rb'
       @name = name
+      @deb822_sources = deb822_sources
       @series ||= OS::VERSION_CODENAME
       @type = ENV.fetch('TYPE')
-      @filename = nil
-      @file_path = "/etc/apt/sources.list.d/archive_uri-http_archive_neon_kde_org_#{@type}-#{@series}.list"
-      self.class.send(:install_add_apt_repository)
-      @default_args = []
-      if self.class.send(:disable_auto_update?)
-        # Since Ubuntu 18.04 the default behavior is to automatically run an
-        # update which will fail without retrying if there was a network error.
-        # We largely have retry systems in place and generally want more control
-        # over when updates happen, so alway disable the auto-update
-        @default_args << '--no-update'
+      if @name.start_with?("http://")
+        @name = @name.delete_prefix("http://")
+        @name = @name.tr('/', '_')
+        @name = "archive_uri-http_#{@name}-#{@series}"
+        @deb822_sources = <<~DEB822_SOURCES
+        X-Repolib-Name: KDE neon #{@series} #{@type}
+        Types: deb
+        URIs: http://archive.neon.kde.org/#{@type}
+        Suites: #{@series}
+        Components: main
+        Signed-By: /etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc
+        DEB822_SOURCES
       end
+      self.class.send(:install_add_apt_repository)
+      #@default_args = []
+    end
+
+    def path
+      "#{self.class.config_dir}/#{@name}.sources"
     end
 
     # (see #add)
@@ -49,23 +67,30 @@ module Apt
       new(name).add
     end
 
-    # Add Repository to sources.list
+    # Add Repository to archive_uri-http_archive_neon_kde_org_#{@type}-#{@series}.sources
     def add
       unless ENV['PANGEA_UNDER_TEST'] # Hello this is a hack to not update the tests
         self.class.send(:install_add_apt_repository)
       end
-      args = [] + @default_args
-      args << '-y'
-      args << @name
+      #args = [] + @default_args
+      #args << '-y'
+      #args << @name
       if ENV['PANGEA_UNDER_TEST'] # Hello this is a hack to not update the tests
-        system('add-apt-repository', *args)
+        #system('add-apt-repository', *args)
       else
-        TTY::Command.new.run!('add-apt-repository', *args).success?
+        #TTY::Command.new.run!('add-apt-repository', *args).success?
+        if File.exist?(path)
+          puts "Repository already exists."
+          false
+        else
+        File.write(path, @deb822_sources)
+        new_source = File.read(path)
+        puts new_source
+        puts "Adding repository."
+        true
+        end
       end
-      old_string = "deb http:"
-      new_contents = File.read(@file_path).gsub(old_string, 'deb [ signed-by=/etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc ] http:')
-      File.write(@file_path, new_contents)
-          end
+    end
 
     # (see #remove)
     def self.remove(name)
@@ -77,17 +102,24 @@ module Apt
       unless ENV['PANGEA_UNDER_TEST'] # Hello this is a hack to not update the tests
         self.class.send(:install_add_apt_repository)
       end
-      old_string = "deb [ signed-by=/etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc ] http:"
-      new_contents = File.read(@file_path).gsub(old_string, 'deb http:')
-      File.write(@file_path, new_contents)
-      args = [] + @default_args
-      args << '-y'
-      args << '-r'
-      args << @name
+      #args = [] + @default_args
+      #args << '-y'
+      #args << '-r'
+      #args << @name
       if ENV['PANGEA_UNDER_TEST'] # Hello this is a hack to not update the tests
-        system('add-apt-repository', *args)
+        #system('add-apt-repository', *args)
       else
-        TTY::Command.new.run!('add-apt-repository', *args).success?
+        #TTY::Command.new.run!('add-apt-repository', *args).success?
+        if File.exist?(path)
+          source_to_rm = File.read(path)
+          puts source_to_rm
+          File.delete(path)
+          puts "Removing repository."
+          return
+        else
+          puts "No repository source file, we must be running install_check.rb."
+          return
+        end
       end
     end
 
diff --git a/nci/lib/setup_repo.rb b/nci/lib/setup_repo.rb
index 01eccdb6..51b5ed6b 100644
--- a/nci/lib/setup_repo.rb
+++ b/nci/lib/setup_repo.rb
@@ -157,14 +157,13 @@ APT::Default-Release "#{setup_repo_codename}";
       set_default_release!
       add_repo_key!
       NCI.series.each_key do |dist|
-        # This doesn't use Apt::Repository because it uses apt-add-repository
-        # which smartly says
-        #   Error: 'deb-src http://archive.neon.kde.org/unstable xenial main'
-        #   invalid
-        # obviously.
-        lines = debsrcline(dist: dist)
-        File.write("/etc/apt/sources.list.d/neon_src_#{dist}.list", lines)
-        puts "lines: #{lines}"
+        type = ENV.fetch('TYPE')
+        src_repo_content = deb822_src_sources(type: type, dist: dist)
+        repo_name = "neon_src_#{dist}"
+
+        src_content = deb822_src_sources(type: type, dist: dist)
+        @add_source_repo = Apt::Repository.new(repo_name, deb822_sources: src_repo_content)
+        @add_source_repo.add
       end
       disable_all_src
     end
@@ -187,36 +186,46 @@ APT::Default-Release "#{setup_repo_codename}";
       type.tr('-', '/')
     end
 
-    def debline(type: ENV.fetch('TYPE'), dist: setup_repo_codename)
+    def deb822_sources(type: ENV.fetch('TYPE'), dist: setup_repo_codename)
       repo = type_to_repo(type, dist)
+      repo_uri = NCI.divert_repo?(repo) ? "http://archive.neon.kde.org/tmp/#{type}" : "http://archive.neon.kde.org/#{type}"
 
-      if NCI.divert_repo?(repo)
-        return format('deb http://archive.neon.kde.org/tmp/%<repo>s %<dist>s main',
-                      repo: repo, dist: dist)
-      end
+      deb822_sources = <<~DEB822_SOURCES
+      X-Repolib-Name: KDE neon #{dist} #{type}
+      Types: deb
+      URIs: #{repo_uri}
+      Suites: #{dist}
+      Components: main
+      Signed-By: /etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc
+      DEB822_SOURCES
 
-      format('deb http://archive.neon.kde.org/%<repo>s %<dist>s main',
-             repo: repo, dist: dist)
     end
 
-    def debsrcline(type: ENV.fetch('TYPE'), dist: setup_repo_codename)
-      repo = type_to_repo(type, dist)
+    def deb822_src_sources(type: ENV.fetch('TYPE'), dist: setup_repo_codename)
+      src_repo = type_to_repo(type, dist)
+      src_repo_uri = NCI.divert_repo?(src_repo) ? "http://archive.neon.kde.org/tmp/#{type}" : "http://archive.neon.kde.org/#{type}"
 
-      if NCI.divert_repo?(repo)
-        return format('deb-src [ signed-by=/etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc ] http://archive.neon.kde.org/tmp/%<repo>s %<dist>s main',
-                      repo: repo, dist: dist)
-      end
+      deb822_src_sources = <<~DEB822_SRC_SOURCES
+      X-Repolib-Name: KDE neon #{dist} #{type}
+      Types: deb-src
+      URIs: #{src_repo_uri}
+      Suites: #{dist}
+      Components: main
+      Signed-By: /etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc
+      DEB822_SRC_SOURCES
 
-      format('deb-src [ signed-by=/etc/apt/keyrings/444D_ABCF_3667_D028_3F89__4EDD_E6D4_7362_5575_1E5D.asc ] http://archive.neon.kde.org/%<repo>s %<dist>s main',
-             repo: repo, dist: dist)
     end
 
     def add_repo!
       add_repo_key!
       Retry.retry_it(times: 5, sleep: 4) do
-        raise 'adding repo failed' unless Apt::Repository.add(debline)
+        type = ENV.fetch('TYPE')
+        dist = setup_repo_codename
+        repo_content = deb822_sources(type: type, dist: dist)
+        @add_repo = Apt::Repository.new("archive_uri-http_archive_neon_kde_org_#{type}-#{dist}",
+                                               deb822_sources: repo_content)
+        raise 'adding repo failed' unless @add_repo.add
       end
-      puts "added #{debline}"
     end
   end
 end
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.