From 1d94bef08279b1788db5bf142c26047139896673 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 9 Aug 2023 23:36:55 +0100 Subject: [PATCH 01/11] Added proxy setup service --- service/agama.gemspec | 2 +- service/bin/agama-proxy-setup | 111 ++++++++++++++++++ service/package/gem2rpm.yml | 4 +- service/share/agama-proxy-setup.service | 12 ++ .../share/{systemd.service => agama.service} | 0 5 files changed, 127 insertions(+), 2 deletions(-) create mode 100755 service/bin/agama-proxy-setup create mode 100644 service/share/agama-proxy-setup.service rename service/share/{systemd.service => agama.service} (100%) diff --git a/service/agama.gemspec b/service/agama.gemspec index 805729197b..bb2b561d4a 100644 --- a/service/agama.gemspec +++ b/service/agama.gemspec @@ -40,7 +40,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/openSUSE/agama" spec.license = "GPL-2.0-only" spec.files = Dir["lib/**/*.rb", "bin/*", "share/*", "etc/*"] - spec.executables = ["agamactl"] + spec.executables = ["agamactl", "agama-proxy-setup"] spec.metadata = { "rubygems_mfa_required" => "true" } spec.required_ruby_version = ">= 2.5.0" diff --git a/service/bin/agama-proxy-setup b/service/bin/agama-proxy-setup new file mode 100755 index 0000000000..ea99ebcdcf --- /dev/null +++ b/service/bin/agama-proxy-setup @@ -0,0 +1,111 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Copyright (c) [2023] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +# Helper script to create a configuration file for a selected list of products. + +require "yast" +require "uri" + +# This class is responsible of parsing the proxy url from the kernel cmdline or configured +# during the boot proccess of the system +class SetupProxy + include Singleton + include Yast + include Logger + + CMDLINE_PATH = "/etc/cmdline" + CMDLINE_MENU_CONF = "/etc/cmdline-menu.conf" + + attr_accessor :proxy + + # Constructor + def initialize + Yast.import "Proxy" + end + + def run + read + write + end + +private + + def read + self.proxy = proxy_from_cmdline || proxy_from_dracut + end + + # TODO + def proxy_from_dracut + return unless File.exist?(CMDLINE_MENU_CONF) + + options = File.read(CMDLINE_MENU_CONF) + proxy_url_from(options) + end + + def proxy_url_from(options) + proxy_url = options.split.find { |o| o.start_with?(/proxy/i) } + return unless proxy_url + + URI(proxy_url.downcase.gsub("proxy=", "")) + end + + def proxy_from_cmdline + return unless File.exist?(CMDLINE_PATH) + + options = File.read(CMDLINE_PATH) + proxy_url_from(options) + end + + def proxy_import_settings + ex = Proxy.Export + proto = proxy.scheme + + # save user name and password separately + ex["proxy_user"] = proxy.user + proxy.user = nil + ex["proxy_password"] = proxy.password + proxy.password = nil + ex["#{proto}_proxy"] = proxy.to_s + # Use the proxy also for https and ftp + if proto == "http" + ex["https_proxy"] = proxy.to_s + ex["ftp_proxy"] = proxy.to_s + end + ex["enabled"] = true + ex + end + + def write + return unless proxy + + Proxy.Read + ex = proxy_import_settings + + log.info "Writing proxy settings: #{proxy.scheme}_proxy = '#{proxy}'" + log.debug "Writing proxy settings: #{ex}" + + Proxy.Import(ex) + Proxy.Write + end +end + +SetupProxy.instance.run diff --git a/service/package/gem2rpm.yml b/service/package/gem2rpm.yml index 945bc01132..cc70ad5bc8 100644 --- a/service/package/gem2rpm.yml +++ b/service/package/gem2rpm.yml @@ -8,7 +8,8 @@ install -D -m 0644 %{buildroot}%{gem_base}/gems/%{mod_full_name}/share/dbus.conf %{buildroot}%{_datadir}/dbus-1/agama.conf install --directory %{buildroot}%{_datadir}/dbus-1/agama-services install -m 0644 --target-directory=%{buildroot}%{_datadir}/dbus-1/agama-services %{buildroot}%{gem_base}/gems/%{mod_full_name}/share/org.opensuse.Agama*.service - install -D -m 0644 %{buildroot}%{gem_base}/gems/%{mod_full_name}/share/systemd.service %{buildroot}%{_unitdir}/agama.service + install -D -m 0644 %{buildroot}%{gem_base}/gems/%{mod_full_name}/share/agama.service %{buildroot}%{_unitdir}/agama.service + install -D -m 0644 %{buildroot}%{gem_base}/gems/%{mod_full_name}/share/agama-proxy-setup.service %{buildroot}%{_unitdir}/agama-proxy-setup.service install -D -m 0644 %{buildroot}%{gem_base}/gems/%{mod_full_name}/etc/agama.yaml %{buildroot}%{_sysconfdir}/agama.yaml :main: :preamble: |- @@ -36,4 +37,5 @@ %dir %{_datadir}/dbus-1/agama-services\n %{_datadir}/dbus-1/agama-services/org.opensuse.Agama*.service\n %{_unitdir}/agama.service\n + %{_unitdir}/agama-proxy-setup.service\n %config %{_sysconfdir}/agama.yaml\n" diff --git a/service/share/agama-proxy-setup.service b/service/share/agama-proxy-setup.service new file mode 100644 index 0000000000..3a46bbc232 --- /dev/null +++ b/service/share/agama-proxy-setup.service @@ -0,0 +1,12 @@ +[Unit] +Description=Configure wide proxy setup for agama and systemd services +Before=agama.service +Wants=local-fs.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/agama-proxy-setup + +[Install] +WantedBy=default.target + diff --git a/service/share/systemd.service b/service/share/agama.service similarity index 100% rename from service/share/systemd.service rename to service/share/agama.service From 4385a7bdee74732ea6ff23eb082f851b5449cc0b Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Mon, 14 Aug 2023 07:38:42 +0100 Subject: [PATCH 02/11] Moved to lib, added test and documentation --- doc/boot_arguments.md | 11 +++ service/bin/agama-proxy-setup | 109 +----------------------- service/lib/agama/proxy_setup.rb | 110 +++++++++++++++++++++++++ service/test/agama/proxy_setup_test.rb | 78 ++++++++++++++++++ 4 files changed, 201 insertions(+), 107 deletions(-) create mode 100644 service/lib/agama/proxy_setup.rb create mode 100644 service/test/agama/proxy_setup_test.rb diff --git a/doc/boot_arguments.md b/doc/boot_arguments.md index f31be92504..69e4a65fa6 100644 --- a/doc/boot_arguments.md +++ b/doc/boot_arguments.md @@ -26,3 +26,14 @@ agama.web.ssl=true agama.web.ssl_cert=http://192.168.122.1/mycert.pem agama.web. ``` Changing complex options (e.g., collections) is not supported yet. + +## Proxy Setup + +Agama supports proxy setup using the `proxy=` kernel command line option like +`proxy=http:192.168.122.1:3128`. + +When the installation system boots, the agama-proxy-setup service will read the proxy url to be +used from the kernel command line options or through the dracut ask prompt configuration file +writing it to the /etc/sysconfig/proxy. After that the microOS Tools setup-systemd-proxy-env +systemd service will make the proxy variables from that file available to all the systemd units +writing a systemd config file with all the variables as Enviroment ones. diff --git a/service/bin/agama-proxy-setup b/service/bin/agama-proxy-setup index ea99ebcdcf..8d16341175 100755 --- a/service/bin/agama-proxy-setup +++ b/service/bin/agama-proxy-setup @@ -1,111 +1,6 @@ #!/usr/bin/env ruby # frozen_string_literal: true -# Copyright (c) [2023] SUSE LLC -# -# All Rights Reserved. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of version 2 of the GNU General Public License as published -# by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, contact SUSE LLC. -# -# To contact SUSE LLC about this file by physical or electronic mail, you may -# find current contact information at www.suse.com. +require "agama/proxy_setup" -# Helper script to create a configuration file for a selected list of products. - -require "yast" -require "uri" - -# This class is responsible of parsing the proxy url from the kernel cmdline or configured -# during the boot proccess of the system -class SetupProxy - include Singleton - include Yast - include Logger - - CMDLINE_PATH = "/etc/cmdline" - CMDLINE_MENU_CONF = "/etc/cmdline-menu.conf" - - attr_accessor :proxy - - # Constructor - def initialize - Yast.import "Proxy" - end - - def run - read - write - end - -private - - def read - self.proxy = proxy_from_cmdline || proxy_from_dracut - end - - # TODO - def proxy_from_dracut - return unless File.exist?(CMDLINE_MENU_CONF) - - options = File.read(CMDLINE_MENU_CONF) - proxy_url_from(options) - end - - def proxy_url_from(options) - proxy_url = options.split.find { |o| o.start_with?(/proxy/i) } - return unless proxy_url - - URI(proxy_url.downcase.gsub("proxy=", "")) - end - - def proxy_from_cmdline - return unless File.exist?(CMDLINE_PATH) - - options = File.read(CMDLINE_PATH) - proxy_url_from(options) - end - - def proxy_import_settings - ex = Proxy.Export - proto = proxy.scheme - - # save user name and password separately - ex["proxy_user"] = proxy.user - proxy.user = nil - ex["proxy_password"] = proxy.password - proxy.password = nil - ex["#{proto}_proxy"] = proxy.to_s - # Use the proxy also for https and ftp - if proto == "http" - ex["https_proxy"] = proxy.to_s - ex["ftp_proxy"] = proxy.to_s - end - ex["enabled"] = true - ex - end - - def write - return unless proxy - - Proxy.Read - ex = proxy_import_settings - - log.info "Writing proxy settings: #{proxy.scheme}_proxy = '#{proxy}'" - log.debug "Writing proxy settings: #{ex}" - - Proxy.Import(ex) - Proxy.Write - end -end - -SetupProxy.instance.run +Agama::ProxySetup.instance.run diff --git a/service/lib/agama/proxy_setup.rb b/service/lib/agama/proxy_setup.rb new file mode 100644 index 0000000000..4bf8b27851 --- /dev/null +++ b/service/lib/agama/proxy_setup.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Copyright (c) [2023] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +# Helper script to create a configuration file for a selected list of products. + +require "yast" +require "uri" + +module Agama + # This class is responsible of parsing the proxy url from the kernel cmdline or configured + # during the boot proccess of the system writing the configuration to /etc/sysconfig/proxy + class ProxySetup + include Singleton + include Yast + include Logger + + CMDLINE_PATH = "/etc/cmdline" + CMDLINE_MENU_CONF = "/etc/cmdline-menu.conf" + + attr_accessor :proxy + + # Constructor + def initialize + Yast.import "Proxy" + end + + def run + read + write + end + + private + + def read + self.proxy = proxy_from_cmdline || proxy_from_dracut + end + + # TODO + def proxy_from_dracut + return unless File.exist?(CMDLINE_MENU_CONF) + + options = File.read(CMDLINE_MENU_CONF) + proxy_url_from(options) + end + + def proxy_url_from(options) + proxy_url = options.split.find { |o| o.start_with?(/proxy/i) } + return unless proxy_url + + URI(proxy_url.downcase.gsub("proxy=", "")) + end + + def proxy_from_cmdline + return unless File.exist?(CMDLINE_PATH) + + options = File.read(CMDLINE_PATH) + proxy_url_from(options) + end + + def proxy_import_settings + ex = Proxy.Export + proto = proxy.scheme + + # save user name and password separately + ex["proxy_user"] = proxy.user + proxy.user = nil + ex["proxy_password"] = proxy.password + proxy.password = nil + ex["#{proto}_proxy"] = proxy.to_s + # Use the proxy also for https and ftp + if proto == "http" + ex["https_proxy"] = proxy.to_s + ex["ftp_proxy"] = proxy.to_s + end + ex["enabled"] = true + ex + end + + def write + return unless proxy + + Proxy.Read + ex = proxy_import_settings + Proxy.Import(ex) + + log.info "Writing proxy settings: #{proxy.scheme}_proxy = '#{proxy}'" + log.debug "Writing proxy settings: #{ex}" + + Proxy.Write + end + end +end diff --git a/service/test/agama/proxy_setup_test.rb b/service/test/agama/proxy_setup_test.rb new file mode 100644 index 0000000000..484541296a --- /dev/null +++ b/service/test/agama/proxy_setup_test.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +# Copyright (c) [2023] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require_relative "../test_helper" +require "agama/proxy_setup" + +describe Agama::ProxySetup do + subject(:proxy) { described_class.instance } + before do + proxy.proxy = nil + end + + describe "#run" do + let(:file_content) { "proxy=#{proxy_url}" } + let(:proxy_url) { "https://yast:1234@192.168.122.1:3128" } + + before do + allow(Yast::Proxy).to receive(:Read) + allow(Yast::Proxy).to receive(:Write) + end + + context "when some configuration is given through the kernel command line" do + before do + allow(proxy).to receive(:proxy_from_cmdline).and_return(URI(proxy_url)) + allow(proxy).to receive(:write) + end + + it "reads the given proxy configuraion" do + expect(proxy.proxy).to be_nil + proxy.run + expect(proxy.proxy).to be_a(URI) + end + + it "writes the proxy configuration to /etc/sysconfig/proxy" do + allow(proxy).to receive(:write).and_call_original + expect(Yast::Proxy).to receive(:Write) + proxy.run + config = Yast::Proxy.Export + expect(config).to include("https_proxy" => "https://192.168.122.1:3128", + "proxy_password" => "1234", + "proxy_user" => "yast", + "enabled" => true) + end + + context "when an http url is given" do + let(:proxy_url) { "http://192.168.122.1:3128" } + + it "sets also the https and ftp with the same url" do + allow(proxy).to receive(:write).and_call_original + proxy.run + config = Yast::Proxy.Export + expect(config).to include("http_proxy" => "http://192.168.122.1:3128", + "https_proxy" => "http://192.168.122.1:3128", + "ftp_proxy" => "http://192.168.122.1:3128", + "enabled" => true) + end + end + end + end +end From 94c53879e0d50375c7bda4bf879b0b162d359fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Alejandro=20Anderssen=20Gonz=C3=A1lez?= Date: Wed, 16 Aug 2023 08:10:20 +0100 Subject: [PATCH 03/11] Apply suggestions from code review Applied fixes suggested from code review Co-authored-by: Martin Vidner --- doc/boot_arguments.md | 2 +- service/lib/agama/proxy_setup.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/boot_arguments.md b/doc/boot_arguments.md index 69e4a65fa6..6f1a8693ba 100644 --- a/doc/boot_arguments.md +++ b/doc/boot_arguments.md @@ -30,7 +30,7 @@ Changing complex options (e.g., collections) is not supported yet. ## Proxy Setup Agama supports proxy setup using the `proxy=` kernel command line option like -`proxy=http:192.168.122.1:3128`. +`proxy=http://192.168.122.1:3128`. When the installation system boots, the agama-proxy-setup service will read the proxy url to be used from the kernel command line options or through the dracut ask prompt configuration file diff --git a/service/lib/agama/proxy_setup.rb b/service/lib/agama/proxy_setup.rb index 4bf8b27851..bdf984e27e 100644 --- a/service/lib/agama/proxy_setup.rb +++ b/service/lib/agama/proxy_setup.rb @@ -32,9 +32,10 @@ class ProxySetup include Yast include Logger - CMDLINE_PATH = "/etc/cmdline" + CMDLINE_PATH = "/proc/cmdline" CMDLINE_MENU_CONF = "/etc/cmdline-menu.conf" + # @return [URI::Generic] attr_accessor :proxy # Constructor From 80832179250414bed36e828c95b08247ccbadc41 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 16 Aug 2023 08:22:06 +0100 Subject: [PATCH 04/11] Improved proxy URL documentation --- doc/boot_arguments.md | 3 ++- service/lib/agama/proxy_setup.rb | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/boot_arguments.md b/doc/boot_arguments.md index 6f1a8693ba..451ff0f24b 100644 --- a/doc/boot_arguments.md +++ b/doc/boot_arguments.md @@ -30,7 +30,8 @@ Changing complex options (e.g., collections) is not supported yet. ## Proxy Setup Agama supports proxy setup using the `proxy=` kernel command line option like -`proxy=http://192.168.122.1:3128`. +`proxy=http://192.168.122.1:3128` when the installation requires to use an HTTP, HTTPS os FTPS +source . The supported proxy URL format is: protocol://[user[:password]@]host[:port] When the installation system boots, the agama-proxy-setup service will read the proxy url to be used from the kernel command line options or through the dracut ask prompt configuration file diff --git a/service/lib/agama/proxy_setup.rb b/service/lib/agama/proxy_setup.rb index bdf984e27e..50e8925281 100644 --- a/service/lib/agama/proxy_setup.rb +++ b/service/lib/agama/proxy_setup.rb @@ -19,8 +19,6 @@ # To contact SUSE LLC about this file by physical or electronic mail, you may # find current contact information at www.suse.com. -# Helper script to create a configuration file for a selected list of products. - require "yast" require "uri" From 999718dd17cb595483561faeb8aa7b665de3ddaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Alejandro=20Anderssen=20Gonz=C3=A1lez?= Date: Wed, 16 Aug 2023 14:51:42 +0100 Subject: [PATCH 05/11] Update doc/boot_arguments.md Co-authored-by: Martin Vidner --- doc/boot_arguments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/boot_arguments.md b/doc/boot_arguments.md index 451ff0f24b..960e978e42 100644 --- a/doc/boot_arguments.md +++ b/doc/boot_arguments.md @@ -30,7 +30,7 @@ Changing complex options (e.g., collections) is not supported yet. ## Proxy Setup Agama supports proxy setup using the `proxy=` kernel command line option like -`proxy=http://192.168.122.1:3128` when the installation requires to use an HTTP, HTTPS os FTPS +`proxy=http://192.168.122.1:3128` when the installation requires to use an HTTP, HTTPS or FTP source . The supported proxy URL format is: protocol://[user[:password]@]host[:port] When the installation system boots, the agama-proxy-setup service will read the proxy url to be From b1c76c5359e3f225baa9a1679f42df4e08bcc86b Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 16 Aug 2023 15:31:44 +0100 Subject: [PATCH 06/11] Do not read current config --- service/lib/agama/proxy_setup.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/service/lib/agama/proxy_setup.rb b/service/lib/agama/proxy_setup.rb index 50e8925281..93ee61ef70 100644 --- a/service/lib/agama/proxy_setup.rb +++ b/service/lib/agama/proxy_setup.rb @@ -75,33 +75,33 @@ def proxy_from_cmdline end def proxy_import_settings - ex = Proxy.Export proto = proxy.scheme - # save user name and password separately - ex["proxy_user"] = proxy.user + settings = { + "proxy_user" => proxy.user, + "proxy_password" => proxy.password, + "enabled" => true + } proxy.user = nil - ex["proxy_password"] = proxy.password proxy.password = nil - ex["#{proto}_proxy"] = proxy.to_s + + settings["#{proto}_proxy"] = proxy.to_s # Use the proxy also for https and ftp if proto == "http" - ex["https_proxy"] = proxy.to_s - ex["ftp_proxy"] = proxy.to_s + settings["https_proxy"] = proxy.to_s + settings["ftp_proxy"] = proxy.to_s end - ex["enabled"] = true - ex + settings end def write return unless proxy - Proxy.Read - ex = proxy_import_settings - Proxy.Import(ex) + settings = proxy_import_settings + Proxy.Import(settings) log.info "Writing proxy settings: #{proxy.scheme}_proxy = '#{proxy}'" - log.debug "Writing proxy settings: #{ex}" + log.debug "Writing proxy settings: #{settings}" Proxy.Write end From 37196ad943a2d860bf74894817538063adfd8859 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 16 Aug 2023 17:44:20 +0100 Subject: [PATCH 07/11] Fix setup-service.sh --- setup-service.sh | 82 ++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/setup-service.sh b/setup-service.sh index 2e84ec9a58..c9c70a401d 100755 --- a/setup-service.sh +++ b/setup-service.sh @@ -16,45 +16,45 @@ MYDIR=$(realpath $(dirname $0)) # Ensure root privileges for the installation. # In a testing container, we are root but there is no sudo. if [ $(id --user) != 0 ]; then - SUDO=sudo - if [ $($SUDO id --user) != 0 ]; then - echo "We are not root and cannot sudo, cannot continue." - exit 1 - fi + SUDO=sudo + if [ $($SUDO id --user) != 0 ]; then + echo "We are not root and cannot sudo, cannot continue." + exit 1 + fi else - SUDO="" + SUDO="" fi # Helper: # Like "sed -e $1 < $2 > $3" but $3 is a system file owned by root sudosed() { - echo "$2 -> $3" - sed -e "$1" "$2" | $SUDO tee "$3" > /dev/null + echo "$2 -> $3" + sed -e "$1" "$2" | $SUDO tee "$3" >/dev/null } # - Install RPM dependencies # this repo can be removed once python-language-data reaches Factory -test -f /etc/zypp/repos.d/d_l_python.repo || \ - $SUDO zypper --non-interactive \ - addrepo https://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_Tumbleweed/ d_l_python +test -f /etc/zypp/repos.d/d_l_python.repo || + $SUDO zypper --non-interactive \ + addrepo https://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_Tumbleweed/ d_l_python $SUDO zypper --non-interactive --gpg-auto-import-keys install gcc gcc-c++ make openssl-devel ruby-devel \ - python-langtable-data git augeas-devel jemalloc-devel awk || exit 1 + python-langtable-data git augeas-devel jemalloc-devel awk || exit 1 # only install cargo if it is not available (avoid conflicts with rustup) which cargo || $SUDO zypper --non-interactive install cargo # - Install service rubygem dependencies ( - cd $MYDIR/service - bundle config set --local path 'vendor/bundle' - bundle install + cd $MYDIR/service + bundle config set --local path 'vendor/bundle' + bundle install ) # - build also rust service ( - cd $MYDIR/rust - cargo build + cd $MYDIR/rust + cargo build ) # - D-Bus configuration @@ -64,38 +64,38 @@ $SUDO cp -v $MYDIR/service/share/dbus.conf /usr/share/dbus-1/agama.conf # (this could be left out but then we would rely # on the manual startup via bin/agamactl) ( - cd $MYDIR/service/share - DBUSDIR=/usr/share/dbus-1/agama-services - - # cleanup previous installation - [[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR - - # create services - $SUDO mkdir -p $DBUSDIR - for SVC in org.opensuse.Agama*.service; do - sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC - done - sudosed "s@\(ExecStart\)=/usr/bin/@\1=$MYDIR/service/bin/@" \ - systemd.service /usr/lib/systemd/system/agama.service + cd $MYDIR/service/share + DBUSDIR=/usr/share/dbus-1/agama-services + + # cleanup previous installation + [[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR + + # create services + $SUDO mkdir -p $DBUSDIR + for SVC in org.opensuse.Agama*.service; do + sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC + done + sudosed "s@\(ExecStart\)=/usr/bin/@\1=$MYDIR/service/bin/@" \ + agama.service /usr/lib/systemd/system/agama.service ) # and same for rust service ( - cd $MYDIR/rust/share - DBUSDIR=/usr/share/dbus-1/agama-services - for SVC in org.opensuse.Agama*.service; do - # it is intention to use debug here to get more useful debugging output - sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/rust/target/debug/@" $SVC $DBUSDIR/$SVC - done + cd $MYDIR/rust/share + DBUSDIR=/usr/share/dbus-1/agama-services + for SVC in org.opensuse.Agama*.service; do + # it is intention to use debug here to get more useful debugging output + sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/rust/target/debug/@" $SVC $DBUSDIR/$SVC + done ) # systemd reload and start of service ( - $SUDO systemctl daemon-reload - # Start the separate dbus-daemon for Agama - # (in CI we run a custom cockpit-ws which replaces the cockpit.socket - # dependency, continue in that case) - $SUDO systemctl start agama.service || pgrep cockpit-ws + $SUDO systemctl daemon-reload + # Start the separate dbus-daemon for Agama + # (in CI we run a custom cockpit-ws which replaces the cockpit.socket + # dependency, continue in that case) + $SUDO systemctl start agama.service || pgrep cockpit-ws ) # - Make sure NetworkManager is running From 24c6619d60693106415bdd048f2a4d32047f0b29 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 17 Aug 2023 23:58:21 +0100 Subject: [PATCH 08/11] Revert "Fix setup-service.sh" This reverts commit 37196ad943a2d860bf74894817538063adfd8859. --- setup-service.sh | 82 ++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/setup-service.sh b/setup-service.sh index c9c70a401d..2e84ec9a58 100755 --- a/setup-service.sh +++ b/setup-service.sh @@ -16,45 +16,45 @@ MYDIR=$(realpath $(dirname $0)) # Ensure root privileges for the installation. # In a testing container, we are root but there is no sudo. if [ $(id --user) != 0 ]; then - SUDO=sudo - if [ $($SUDO id --user) != 0 ]; then - echo "We are not root and cannot sudo, cannot continue." - exit 1 - fi + SUDO=sudo + if [ $($SUDO id --user) != 0 ]; then + echo "We are not root and cannot sudo, cannot continue." + exit 1 + fi else - SUDO="" + SUDO="" fi # Helper: # Like "sed -e $1 < $2 > $3" but $3 is a system file owned by root sudosed() { - echo "$2 -> $3" - sed -e "$1" "$2" | $SUDO tee "$3" >/dev/null + echo "$2 -> $3" + sed -e "$1" "$2" | $SUDO tee "$3" > /dev/null } # - Install RPM dependencies # this repo can be removed once python-language-data reaches Factory -test -f /etc/zypp/repos.d/d_l_python.repo || - $SUDO zypper --non-interactive \ - addrepo https://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_Tumbleweed/ d_l_python +test -f /etc/zypp/repos.d/d_l_python.repo || \ + $SUDO zypper --non-interactive \ + addrepo https://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_Tumbleweed/ d_l_python $SUDO zypper --non-interactive --gpg-auto-import-keys install gcc gcc-c++ make openssl-devel ruby-devel \ - python-langtable-data git augeas-devel jemalloc-devel awk || exit 1 + python-langtable-data git augeas-devel jemalloc-devel awk || exit 1 # only install cargo if it is not available (avoid conflicts with rustup) which cargo || $SUDO zypper --non-interactive install cargo # - Install service rubygem dependencies ( - cd $MYDIR/service - bundle config set --local path 'vendor/bundle' - bundle install + cd $MYDIR/service + bundle config set --local path 'vendor/bundle' + bundle install ) # - build also rust service ( - cd $MYDIR/rust - cargo build + cd $MYDIR/rust + cargo build ) # - D-Bus configuration @@ -64,38 +64,38 @@ $SUDO cp -v $MYDIR/service/share/dbus.conf /usr/share/dbus-1/agama.conf # (this could be left out but then we would rely # on the manual startup via bin/agamactl) ( - cd $MYDIR/service/share - DBUSDIR=/usr/share/dbus-1/agama-services - - # cleanup previous installation - [[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR - - # create services - $SUDO mkdir -p $DBUSDIR - for SVC in org.opensuse.Agama*.service; do - sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC - done - sudosed "s@\(ExecStart\)=/usr/bin/@\1=$MYDIR/service/bin/@" \ - agama.service /usr/lib/systemd/system/agama.service + cd $MYDIR/service/share + DBUSDIR=/usr/share/dbus-1/agama-services + + # cleanup previous installation + [[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR + + # create services + $SUDO mkdir -p $DBUSDIR + for SVC in org.opensuse.Agama*.service; do + sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC + done + sudosed "s@\(ExecStart\)=/usr/bin/@\1=$MYDIR/service/bin/@" \ + systemd.service /usr/lib/systemd/system/agama.service ) # and same for rust service ( - cd $MYDIR/rust/share - DBUSDIR=/usr/share/dbus-1/agama-services - for SVC in org.opensuse.Agama*.service; do - # it is intention to use debug here to get more useful debugging output - sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/rust/target/debug/@" $SVC $DBUSDIR/$SVC - done + cd $MYDIR/rust/share + DBUSDIR=/usr/share/dbus-1/agama-services + for SVC in org.opensuse.Agama*.service; do + # it is intention to use debug here to get more useful debugging output + sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/rust/target/debug/@" $SVC $DBUSDIR/$SVC + done ) # systemd reload and start of service ( - $SUDO systemctl daemon-reload - # Start the separate dbus-daemon for Agama - # (in CI we run a custom cockpit-ws which replaces the cockpit.socket - # dependency, continue in that case) - $SUDO systemctl start agama.service || pgrep cockpit-ws + $SUDO systemctl daemon-reload + # Start the separate dbus-daemon for Agama + # (in CI we run a custom cockpit-ws which replaces the cockpit.socket + # dependency, continue in that case) + $SUDO systemctl start agama.service || pgrep cockpit-ws ) # - Make sure NetworkManager is running From 7743dce7a4af94537f12cceaba67625047c7ac8e Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 18 Aug 2023 00:01:10 +0100 Subject: [PATCH 09/11] Fix setup-service --- .editorconfig | 9 +++++++++ setup-service.sh | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..d12b0a8762 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# 2 space indentation +[{*.sh}] +indent_style = space +indent_size = 2 diff --git a/setup-service.sh b/setup-service.sh index 2e84ec9a58..4760be186f 100755 --- a/setup-service.sh +++ b/setup-service.sh @@ -76,7 +76,7 @@ $SUDO cp -v $MYDIR/service/share/dbus.conf /usr/share/dbus-1/agama.conf sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC done sudosed "s@\(ExecStart\)=/usr/bin/@\1=$MYDIR/service/bin/@" \ - systemd.service /usr/lib/systemd/system/agama.service + agama.service /usr/lib/systemd/system/agama.service ) # and same for rust service From 548dd65984f09b4534d1fb9d1854db941029cda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Alejandro=20Anderssen=20Gonz=C3=A1lez?= Date: Fri, 18 Aug 2023 00:10:33 +0100 Subject: [PATCH 10/11] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Imobach González Sosa --- doc/boot_arguments.md | 4 ++-- service/lib/agama/proxy_setup.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/boot_arguments.md b/doc/boot_arguments.md index 960e978e42..cc66b2c612 100644 --- a/doc/boot_arguments.md +++ b/doc/boot_arguments.md @@ -31,9 +31,9 @@ Changing complex options (e.g., collections) is not supported yet. Agama supports proxy setup using the `proxy=` kernel command line option like `proxy=http://192.168.122.1:3128` when the installation requires to use an HTTP, HTTPS or FTP -source . The supported proxy URL format is: protocol://[user[:password]@]host[:port] +source. The supported proxy URL format is: protocol://[user[:password]@]host[:port] -When the installation system boots, the agama-proxy-setup service will read the proxy url to be +When the installation system boots, the agama-proxy-setup service will read the proxy URL to be used from the kernel command line options or through the dracut ask prompt configuration file writing it to the /etc/sysconfig/proxy. After that the microOS Tools setup-systemd-proxy-env systemd service will make the proxy variables from that file available to all the systemd units diff --git a/service/lib/agama/proxy_setup.rb b/service/lib/agama/proxy_setup.rb index 93ee61ef70..9852db68ca 100644 --- a/service/lib/agama/proxy_setup.rb +++ b/service/lib/agama/proxy_setup.rb @@ -24,7 +24,8 @@ module Agama # This class is responsible of parsing the proxy url from the kernel cmdline or configured - # during the boot proccess of the system writing the configuration to /etc/sysconfig/proxy + # through the dracut ask prompt configuration file (/etc/cmdline-menu.conf) during the boot + # proccess of the system writing the configuration to /etc/sysconfig/proxy class ProxySetup include Singleton include Yast @@ -52,7 +53,6 @@ def read self.proxy = proxy_from_cmdline || proxy_from_dracut end - # TODO def proxy_from_dracut return unless File.exist?(CMDLINE_MENU_CONF) From d8bdfeaa5f2926dfc7ad57512fcba8e6a2f5f3c3 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 18 Aug 2023 16:12:26 +0100 Subject: [PATCH 11/11] Added changelog --- service/package/rubygem-agama.changes | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/package/rubygem-agama.changes b/service/package/rubygem-agama.changes index 4ea828cd84..5fded27b4d 100644 --- a/service/package/rubygem-agama.changes +++ b/service/package/rubygem-agama.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Fri Aug 18 14:17:13 UTC 2023 - Knut Anderssen + +- Add proxy setup support (bsc#1212677, gh#openSUSE/agama#696). + ------------------------------------------------------------------- Mon Aug 7 10:52:35 UTC 2023 - Imobach Gonzalez Sosa