From 74b1d46f394fe85a35c790bd06eed451985b65e8 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 14 Jan 2025 17:29:42 +0100 Subject: [PATCH 01/24] create also file with kernel only files for bootloader proposal --- .../dracut/modules.d/99agama-cmdline/README | 4 ++- .../99agama-cmdline/kernel-cmdline-conf.sh | 33 +++++++++++++++++++ .../modules.d/99agama-cmdline/module-setup.sh | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README index 2787db46c2..516fb55eae 100644 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README @@ -2,5 +2,7 @@ dracut agama-cmdline module ------------------------------- This module writes any agama configuration given through the kernel cmdline -to its own cmdline conf file copying it to the sysroot. +to its own cmdline conf file copying it to the sysroot. And also creates other +cmdline conf file with only kernel parameters that can be used for +bootloader parameter proposals. diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh new file mode 100755 index 0000000000..bdc419d93b --- /dev/null +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh @@ -0,0 +1,33 @@ +#! /bin/sh + +[ -e /dracut-state.sh ] && . /dracut-state.sh + +. /lib/dracut-lib.sh + +get_kernel_args() { + local _i _found _path + + mkdir -p "$NEWROOT/etc/agama.d" + _path="$NEWROOT/etc/agama.d/kernel.cmdline.conf" + # ensure that kernel cmdline line is created to avoid reading agama params + # if there is no kernel params + touch "$_path" + + for _i in $CMDLINE; do + case $_i in + LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_* | root=* | info=* | autoyast* ) + _found=1 + ;; + esac + + if [ -z "$_found" ]; then + printf "Non-Agama parameter found ($_i)" + echo "$_i" >>"$_path" + fi + unset _found + done + + return 0 +} + +get_kernel_args diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh index 24a6bcd321..ea2d9de271 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh @@ -18,4 +18,5 @@ installkernel() { install() { inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" + inst_hook pre-pivot 99 "$moddir/kernel-cmdline-conf.sh" } From 0d11399e7b998098384e61fa5c6e4772fddffba2 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 15 Jan 2025 15:04:21 +0100 Subject: [PATCH 02/24] Revert "create also file with kernel only files for bootloader proposal" This reverts commit 74b1d46f394fe85a35c790bd06eed451985b65e8. We decided to not go with dracut approach and instead use systemd service --- .../dracut/modules.d/99agama-cmdline/README | 4 +-- .../99agama-cmdline/kernel-cmdline-conf.sh | 33 ------------------- .../modules.d/99agama-cmdline/module-setup.sh | 1 - 3 files changed, 1 insertion(+), 37 deletions(-) delete mode 100755 live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README index 516fb55eae..2787db46c2 100644 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README @@ -2,7 +2,5 @@ dracut agama-cmdline module ------------------------------- This module writes any agama configuration given through the kernel cmdline -to its own cmdline conf file copying it to the sysroot. And also creates other -cmdline conf file with only kernel parameters that can be used for -bootloader parameter proposals. +to its own cmdline conf file copying it to the sysroot. diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh deleted file mode 100755 index bdc419d93b..0000000000 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/kernel-cmdline-conf.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /bin/sh - -[ -e /dracut-state.sh ] && . /dracut-state.sh - -. /lib/dracut-lib.sh - -get_kernel_args() { - local _i _found _path - - mkdir -p "$NEWROOT/etc/agama.d" - _path="$NEWROOT/etc/agama.d/kernel.cmdline.conf" - # ensure that kernel cmdline line is created to avoid reading agama params - # if there is no kernel params - touch "$_path" - - for _i in $CMDLINE; do - case $_i in - LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_* | root=* | info=* | autoyast* ) - _found=1 - ;; - esac - - if [ -z "$_found" ]; then - printf "Non-Agama parameter found ($_i)" - echo "$_i" >>"$_path" - fi - unset _found - done - - return 0 -} - -get_kernel_args diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh index ea2d9de271..24a6bcd321 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh @@ -18,5 +18,4 @@ installkernel() { install() { inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" - inst_hook pre-pivot 99 "$moddir/kernel-cmdline-conf.sh" } From 6cc2517b319ece8bb2f64cde568464e4d7396027 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 15 Jan 2025 22:12:30 +0100 Subject: [PATCH 03/24] add script to filter out kernel cmdline to live root --- live/Makefile | 3 +++ live/README.md | 1 + live/root/usr/bin/kernel-cmdline-conf.sh | 31 ++++++++++++++++++++++++ live/test/fixtures/expected/cmdline | 1 + live/test/fixtures/source/cmdline | 1 + live/test/kernel_cmdline_test.rb | 20 +++++++++++++++ 6 files changed, 57 insertions(+) create mode 100755 live/root/usr/bin/kernel-cmdline-conf.sh create mode 100644 live/test/fixtures/expected/cmdline create mode 100644 live/test/fixtures/source/cmdline create mode 100755 live/test/kernel_cmdline_test.rb diff --git a/live/Makefile b/live/Makefile index cb1535e0d9..083e38f44e 100644 --- a/live/Makefile +++ b/live/Makefile @@ -57,4 +57,7 @@ build: $(DESTDIR) $(MAKE) all (cd $(DESTDIR) && osc build -M $(FLAVOR) images) +check: + for i in ./test/*_test.*; do $${i}; done + .PHONY: build all clean diff --git a/live/README.md b/live/README.md index a37116fa73..24e2cbe677 100644 --- a/live/README.md +++ b/live/README.md @@ -37,6 +37,7 @@ This directory contains a set of files that are used to build the Agama Live ISO PXE boot, see a separate [PXE documentation](PXE.md) for more details about the PXE boot - [config-cdroot](config-cdroot) subdirectory contains file which are copied to the uncompressed root of the ISO image, the files can be accessed just by mounting the ISO file or the DVD medium +- [test](test) subdirectory contains tests to verify correctness of content. Can be run with `make check` ## Building the Sources diff --git a/live/root/usr/bin/kernel-cmdline-conf.sh b/live/root/usr/bin/kernel-cmdline-conf.sh new file mode 100755 index 0000000000..b3f54f944c --- /dev/null +++ b/live/root/usr/bin/kernel-cmdline-conf.sh @@ -0,0 +1,31 @@ +#! /bin/sh + +SOURCE="${1:-/proc/cmdline}" +TARGET="${2:-/etc/agama.d/kernel.cmdline.conf}" + +write_kernel_args() { + DIR=$(dirname "${TARGET}") + mkdir -p "$DIR" + # ensure that kernel cmdline line is created to avoid reading agama params + # if there is no kernel params + touch "${TARGET}" + + for _i in $(cat "${SOURCE}"); do + case ${_i} in + # remove all agama kernel params + LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_* | autoyast* ) + _found=1 + ;; + esac + + if [ -z "$_found" ]; then + echo "Non-Agama parameter found ($_i)" + echo -n " $_i" >>"${TARGET}" + fi + unset _found + done + + return 0 +} + +write_kernel_args diff --git a/live/test/fixtures/expected/cmdline b/live/test/fixtures/expected/cmdline new file mode 100644 index 0000000000..d07b617330 --- /dev/null +++ b/live/test/fixtures/expected/cmdline @@ -0,0 +1 @@ + BOOT_IMAGE=/boot/vmlinuz splash=silent mitigations=auto quiet nosimplefb=1 \ No newline at end of file diff --git a/live/test/fixtures/source/cmdline b/live/test/fixtures/source/cmdline new file mode 100644 index 0000000000..257755c118 --- /dev/null +++ b/live/test/fixtures/source/cmdline @@ -0,0 +1 @@ +BOOT_IMAGE=/boot/vmlinuz splash=silent agama.auto=ftp://example.suse.cz/profile.json LIBSTORAGE_MULTIPATH=1 mitigations=auto Y2DEBUG=1 quiet nosimplefb=1 diff --git a/live/test/kernel_cmdline_test.rb b/live/test/kernel_cmdline_test.rb new file mode 100755 index 0000000000..98e646052d --- /dev/null +++ b/live/test/kernel_cmdline_test.rb @@ -0,0 +1,20 @@ +#! /usr/bin/rspec +require "tmpdir" + +describe "kernel-cmdline-conf.sh" do + it "filters out any agama params" do + script_path = File.expand_path("../root/usr/bin/kernel-cmdline-conf.sh", __dir__, ) + source_path = File.expand_path("fixtures/source/cmdline", __dir__, ) + expected_path = File.expand_path("fixtures/expected/cmdline", __dir__, ) + tmpdir = Dir.mktmpdir do |tmpdir| + target_path = File.join(tmpdir, "cmdline") + command = "#{script_path} #{source_path} #{target_path}" + puts command + cmd_result = system(command) + expect(cmd_result).to eq true + expected = File.read(expected_path) + result = File.read(target_path) + expect(result).to eq expected + end + end +end From 8d4679fa92434061ad602fe1150f5bf2ca5fdd08 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 16 Jan 2025 09:59:22 +0100 Subject: [PATCH 04/24] add systemd service for filtering kernel --- .../system/agama-cmdline-process.service | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 live/root/etc/systemd/system/agama-cmdline-process.service diff --git a/live/root/etc/systemd/system/agama-cmdline-process.service b/live/root/etc/systemd/system/agama-cmdline-process.service new file mode 100644 index 0000000000..744479f9b6 --- /dev/null +++ b/live/root/etc/systemd/system/agama-cmdline-process.service @@ -0,0 +1,20 @@ +[Unit] +Description=Agama kernel cmdline processing + +# have to be after network to be able to download info files +After=network-online.target + +# before starting the Agama servers so they read configuration parsed +Before=agama-web-server.service +Before=agama.service +Before=x11-autologin.service + +[Service] +Type=oneshot +Environment=TERM=linux +ExecStart=kernel-cmdline-conf.sh +StandardInput=tty +TimeoutSec=0 + +[Install] +WantedBy=default.target From ae97e492c75de90dfb075e5f9cac85bbfc14351d Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 17 Jan 2025 11:36:11 +0100 Subject: [PATCH 05/24] remove space and add note --- live/root/usr/bin/kernel-cmdline-conf.sh | 1 + live/test/fixtures/source/cmdline | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/live/root/usr/bin/kernel-cmdline-conf.sh b/live/root/usr/bin/kernel-cmdline-conf.sh index b3f54f944c..f44320b85c 100755 --- a/live/root/usr/bin/kernel-cmdline-conf.sh +++ b/live/root/usr/bin/kernel-cmdline-conf.sh @@ -13,6 +13,7 @@ write_kernel_args() { for _i in $(cat "${SOURCE}"); do case ${_i} in # remove all agama kernel params + # Add here also all linuxrc supported parameters LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_* | autoyast* ) _found=1 ;; diff --git a/live/test/fixtures/source/cmdline b/live/test/fixtures/source/cmdline index 257755c118..d43325ea28 100644 --- a/live/test/fixtures/source/cmdline +++ b/live/test/fixtures/source/cmdline @@ -1 +1 @@ -BOOT_IMAGE=/boot/vmlinuz splash=silent agama.auto=ftp://example.suse.cz/profile.json LIBSTORAGE_MULTIPATH=1 mitigations=auto Y2DEBUG=1 quiet nosimplefb=1 +BOOT_IMAGE=/boot/vmlinuz splash=silent agama.auto=ftp://example.suse.cz/profile.json LIBSTORAGE_MULTIPATH=1 mitigations=auto Y2DEBUG=1 quiet nosimplefb=1 From 10a9a8f7164cc3d613dca5e345e6e8ac77fdfd7d Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 17 Jan 2025 16:54:37 +0100 Subject: [PATCH 06/24] first version of info expansion script --- live/root/usr/bin/info-cmdline-conf.sh | 25 +++++++++ live/test/fixtures/expected/info_cmdline | 3 ++ live/test/fixtures/expected/info_cmdline.info | 2 + live/test/fixtures/source/info_cmdline | 1 + live/test/info_cmdline_test.rb | 51 +++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100755 live/root/usr/bin/info-cmdline-conf.sh create mode 100644 live/test/fixtures/expected/info_cmdline create mode 100644 live/test/fixtures/expected/info_cmdline.info create mode 100644 live/test/fixtures/source/info_cmdline create mode 100755 live/test/info_cmdline_test.rb diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh new file mode 100755 index 0000000000..44db9a88a2 --- /dev/null +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -0,0 +1,25 @@ +#! /bin/sh + +set -e + +TARGET="${1:-/etc/agama.d/cmdline.conf}" +INFO_CONTENT="${2:-/etc/agama.d/cmdline.info.conf}" + +expand_info_arg() { + INFO_URL=$(sed -n 's/.*[ ^]info=\([^[:space:]]\+\).*/\1/p' "$TARGET") + if [ -z "${INFO_URL}" ]; then + return 0 + fi + + curl --silent "${INFO_URL}" > "${INFO_CONTENT}" + # remove info param + sed -in 's/[ ^]info=[^[:space:]]\+//' "${TARGET}" + # and add content of info file + cat "${INFO_CONTENT}" + cat "${INFO_CONTENT}" >> "${TARGET}" + cat "${INFO_CONTENT}" + + return 0 +} + +expand_info_arg diff --git a/live/test/fixtures/expected/info_cmdline b/live/test/fixtures/expected/info_cmdline new file mode 100644 index 0000000000..ca2bb594ab --- /dev/null +++ b/live/test/fixtures/expected/info_cmdline @@ -0,0 +1,3 @@ +BOOT_IMAGE=/boot/vmlinuz splash=silent nosimplefb=1 +agama.install_url=ftp://test.com/repo +live.password=secret \ No newline at end of file diff --git a/live/test/fixtures/expected/info_cmdline.info b/live/test/fixtures/expected/info_cmdline.info new file mode 100644 index 0000000000..9de6db162f --- /dev/null +++ b/live/test/fixtures/expected/info_cmdline.info @@ -0,0 +1,2 @@ +agama.install_url=ftp://test.com/repo +live.password=secret \ No newline at end of file diff --git a/live/test/fixtures/source/info_cmdline b/live/test/fixtures/source/info_cmdline new file mode 100644 index 0000000000..022b06e668 --- /dev/null +++ b/live/test/fixtures/source/info_cmdline @@ -0,0 +1 @@ +BOOT_IMAGE=/boot/vmlinuz splash=silent info=https://pastebin.com/raw/krzAVL8S nosimplefb=1 diff --git a/live/test/info_cmdline_test.rb b/live/test/info_cmdline_test.rb new file mode 100755 index 0000000000..244b125186 --- /dev/null +++ b/live/test/info_cmdline_test.rb @@ -0,0 +1,51 @@ +#! /usr/bin/rspec +require "tmpdir" + +describe "info-cmdline-conf.sh" do + let(:script_path) { File.expand_path("../root/usr/bin/info-cmdline-conf.sh", __dir__, ) } + + context "There is no info parameter" do + let(:source_path) { File.expand_path("fixtures/source/cmdline", __dir__, ) } + let(:expected_path) { File.expand_path("fixtures/source/cmdline", __dir__, ) } + + + it "do nothing" do + Dir.mktmpdir do |tmpdir| + target_path = File.join(tmpdir, "cmdline") + FileUtils.cp(source_path, target_path) + info_path = File.join(tmpdir, "cmdline.info") + command = "#{script_path} #{target_path} #{info_path}" + cmd_result = system(command) + expect(cmd_result).to eq true + expected = File.read(expected_path) + result = File.read(target_path) + expect(result).to eq expected + expect(File.exists?(info_path)).to eq false + end + end + end + + context "There is info parameter" do + let(:source_path) { File.expand_path("fixtures/source/info_cmdline", __dir__, ) } + let(:expected_path) { File.expand_path("fixtures/expected/info_cmdline", __dir__, ) } + let(:expected_info_path) { File.expand_path("fixtures/expected/info_cmdline.info", __dir__, ) } + + it "removes info parameter and add its content" do + Dir.mktmpdir do |tmpdir| + target_path = File.join(tmpdir, "cmdline") + FileUtils.cp(source_path, target_path) + info_path = File.join(tmpdir, "cmdline.info") + command = "#{script_path} #{target_path} #{info_path}" + cmd_result = system(command) + expect(cmd_result).to eq true + expected = File.read(expected_path) + result = File.read(target_path) + expect(result).to eq expected + + expected_info = File.read(expected_info_path) + result_info = File.read(info_path) + expect(result_info).to eq expected_info + end + end + end +end From d761a98c7b428d94d074960dd4d64ab08b3fb6cb Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Jan 2025 10:15:56 +0100 Subject: [PATCH 07/24] change param from info to agama.info --- live/root/usr/bin/info-cmdline-conf.sh | 4 ++-- live/test/fixtures/source/info_cmdline | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh index 44db9a88a2..e80fef7cda 100755 --- a/live/root/usr/bin/info-cmdline-conf.sh +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -6,14 +6,14 @@ TARGET="${1:-/etc/agama.d/cmdline.conf}" INFO_CONTENT="${2:-/etc/agama.d/cmdline.info.conf}" expand_info_arg() { - INFO_URL=$(sed -n 's/.*[ ^]info=\([^[:space:]]\+\).*/\1/p' "$TARGET") + INFO_URL=$(sed -n 's/.*[ ^]agama\.info=\([^[:space:]]\+\).*/\1/p' "$TARGET") if [ -z "${INFO_URL}" ]; then return 0 fi curl --silent "${INFO_URL}" > "${INFO_CONTENT}" # remove info param - sed -in 's/[ ^]info=[^[:space:]]\+//' "${TARGET}" + sed -in 's/[ ^]agama\.info=[^[:space:]]\+//' "${TARGET}" # and add content of info file cat "${INFO_CONTENT}" cat "${INFO_CONTENT}" >> "${TARGET}" diff --git a/live/test/fixtures/source/info_cmdline b/live/test/fixtures/source/info_cmdline index 022b06e668..32aeff0894 100644 --- a/live/test/fixtures/source/info_cmdline +++ b/live/test/fixtures/source/info_cmdline @@ -1 +1 @@ -BOOT_IMAGE=/boot/vmlinuz splash=silent info=https://pastebin.com/raw/krzAVL8S nosimplefb=1 +BOOT_IMAGE=/boot/vmlinuz splash=silent agama.info=https://pastebin.com/raw/krzAVL8S nosimplefb=1 From b476c61f8833f9ba91d4e23a000cfc3394e77a35 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Jan 2025 14:19:00 +0100 Subject: [PATCH 08/24] update systemd services config and scripts --- .../systemd/system/agama-cmdline-process.service | 3 ++- .../etc/systemd/system/agama-self-update.service | 8 +++----- .../systemd/system/live-password-cmdline.service | 5 ++--- .../systemd/system/live-password-dialog.service | 4 ++-- .../systemd/system/live-password-systemd.service | 4 ++-- live/root/usr/bin/agama-kernel-cmdline.sh | 4 ++++ live/root/usr/bin/agama-self-update | 4 ++++ live/root/usr/bin/live-password | 15 ++++++++++++--- live/src/config.sh | 1 + 9 files changed, 32 insertions(+), 16 deletions(-) create mode 100755 live/root/usr/bin/agama-kernel-cmdline.sh diff --git a/live/root/etc/systemd/system/agama-cmdline-process.service b/live/root/etc/systemd/system/agama-cmdline-process.service index 744479f9b6..661d6166f8 100644 --- a/live/root/etc/systemd/system/agama-cmdline-process.service +++ b/live/root/etc/systemd/system/agama-cmdline-process.service @@ -2,6 +2,7 @@ Description=Agama kernel cmdline processing # have to be after network to be able to download info files +# TODO: what to do in air gap scenario where we still need process cmdline? After=network-online.target # before starting the Agama servers so they read configuration parsed @@ -12,7 +13,7 @@ Before=x11-autologin.service [Service] Type=oneshot Environment=TERM=linux -ExecStart=kernel-cmdline-conf.sh +ExecStart=agama-kernel-cmdline.sh StandardInput=tty TimeoutSec=0 diff --git a/live/root/etc/systemd/system/agama-self-update.service b/live/root/etc/systemd/system/agama-self-update.service index 5d80b9ef55..820cf16f10 100644 --- a/live/root/etc/systemd/system/agama-self-update.service +++ b/live/root/etc/systemd/system/agama-self-update.service @@ -3,6 +3,9 @@ Description=Agama self-update After=network-online.target +# and after we process agama params like info which can contain password +After=agama-cmdline-process.service + # before starting the Agama servers so they use the new packages Before=agama-web-server.service Before=agama.service @@ -11,11 +14,6 @@ Before=x11-autologin.service Before=live-password-dialog.service Before=live-password-systemd.service -# kernel command line option -ConditionKernelCommandLine=|agama.self_update -# linuxrc/YaST backward compatibility -ConditionKernelCommandLine=|agama.selfupdate - [Service] Type=oneshot Environment=TERM=linux diff --git a/live/root/etc/systemd/system/live-password-cmdline.service b/live/root/etc/systemd/system/live-password-cmdline.service index 3307967f7b..f2b183a3a0 100644 --- a/live/root/etc/systemd/system/live-password-cmdline.service +++ b/live/root/etc/systemd/system/live-password-cmdline.service @@ -9,9 +9,8 @@ Before=agama-web-server.service Before=live-password-dialog.service Before=live-password-systemd.service -# plain text password or hashed password passed via kernel command line -ConditionKernelCommandLine=|live.password -ConditionKernelCommandLine=|live.password_hash +# and after we process agama params like info which can contain password +After=agama-cmdline-process.service [Service] ExecStart=live-password --kernel diff --git a/live/root/etc/systemd/system/live-password-dialog.service b/live/root/etc/systemd/system/live-password-dialog.service index f463684ce1..5bde8e9584 100644 --- a/live/root/etc/systemd/system/live-password-dialog.service +++ b/live/root/etc/systemd/system/live-password-dialog.service @@ -22,8 +22,8 @@ Before=serial-getty@ttyS1.service Before=serial-getty@ttyS2.service Before=serial-getty@ttysclp0.service -# kernel command line option -ConditionKernelCommandLine=live.password_dialog +# and after we process agama params like info which can contain kernel parameters +After=agama-cmdline-process.service [Service] Type=oneshot diff --git a/live/root/etc/systemd/system/live-password-systemd.service b/live/root/etc/systemd/system/live-password-systemd.service index eb81bae6c3..8aef371671 100644 --- a/live/root/etc/systemd/system/live-password-systemd.service +++ b/live/root/etc/systemd/system/live-password-systemd.service @@ -22,8 +22,8 @@ Before=serial-getty@ttyS1.service Before=serial-getty@ttyS2.service Before=serial-getty@ttysclp0.service -# kernel command line option -ConditionKernelCommandLine=live.password_systemd +# and after we process agama params like info which can contain kernel parameters +After=agama-cmdline-process.service [Service] Type=oneshot diff --git a/live/root/usr/bin/agama-kernel-cmdline.sh b/live/root/usr/bin/agama-kernel-cmdline.sh new file mode 100755 index 0000000000..28711db05f --- /dev/null +++ b/live/root/usr/bin/agama-kernel-cmdline.sh @@ -0,0 +1,4 @@ +#! /bin/sh + +kernel-cmdline-conf.sh +info-cmdline-conf.sh diff --git a/live/root/usr/bin/agama-self-update b/live/root/usr/bin/agama-self-update index e1958571f5..9578421891 100755 --- a/live/root/usr/bin/agama-self-update +++ b/live/root/usr/bin/agama-self-update @@ -5,6 +5,10 @@ # This script updates the Agama packages in the Live system from the # Agama Devel OBS project. +# check if self-update is required +if ! grep -q "[[:space:]^]agama.self_update=1\([[:space:]]\|$\)" /etc/agama.d/cmdline.conf; then + exit 0 +fi # first try a quick and simple solution, refreshing the distributions repository takes a # lot of time so try using only the agama-devel for update diff --git a/live/root/usr/bin/live-password b/live/root/usr/bin/live-password index 76ebf390d9..362e9be5ad 100755 --- a/live/root/usr/bin/live-password +++ b/live/root/usr/bin/live-password @@ -27,6 +27,11 @@ msg_box() { } ask_password() { + # check if user wants dialog password + if ! grep -q "[[:space:]^]live.password_dialog=1\([[:space:]]\|$\)" /etc/agama.d/cmdline.conf; then + exit 0 + fi + if ! PWD1=$(dialog --keep-tite --title "$TITLE" --backtitle "$BTITLE" --stdout --insecure --passwordbox "Password:" 8 40); then confirm_exit ask_password @@ -36,7 +41,7 @@ ask_password() { confirm_exit ask_password fi - + if [ "$PWD1" != "$PWD2" ]; then msg_box "Passwords do not match.\nPlease try again." ask_password @@ -51,6 +56,10 @@ ask_password() { # functions for entering the password using the "systemd-ask-password" tool ask_password_systemd() { + # check if user wants systemd password + if ! grep -q "[[:space:]^]live.password_systemd=1\([[:space:]]\|$\)" /etc/agama.d/cmdline.conf; then + exit 0 + fi if ! PWD1=$(systemd-ask-password --timeout=0 "Set login password: "); then exit 1 fi @@ -142,12 +151,12 @@ random_password() { if [ "$1" = "--kernel" ]; then # get the password from the kernel command line - PWD=$(awk -F 'live.password=' '{sub(/ .*$/, "", $2); print $2}' < /proc/cmdline) + PWD=$(awk -F 'live.password=' '{sub(/ .*$/, "", $2); print $2}' < /etc/agama.d/cmdline.conf) if [ -n "$PWD" ]; then echo "$PWD" | passwd --stdin fi - PWD=$(awk -F 'live.password_hash=' '{sub(/ .*$/, "", $2); print $2}' < /proc/cmdline) + PWD=$(awk -F 'live.password_hash=' '{sub(/ .*$/, "", $2); print $2}' < /etc/agama.d/cmdline.conf) if [ -n "$PWD" ]; then usermod -p "$PWD" root fi diff --git a/live/src/config.sh b/live/src/config.sh index 607fe25094..91a2b94c94 100644 --- a/live/src/config.sh +++ b/live/src/config.sh @@ -44,6 +44,7 @@ systemctl enable agama-hostname.service systemctl enable agama-proxy-setup.service systemctl enable agama-certificate-issue.path systemctl enable agama-certificate-wait.service +systemctl enable agama-cmdline-process.service systemctl enable agama-welcome-issue.service systemctl enable agama-avahi-issue.service systemctl enable agama-url-issue.service From cf47628cf635d7498fb7c2cba6685397ef756192 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Jan 2025 16:08:24 +0100 Subject: [PATCH 09/24] fix matching start of line --- live/root/usr/bin/info-cmdline-conf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh index e80fef7cda..bdbd293c5b 100755 --- a/live/root/usr/bin/info-cmdline-conf.sh +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -6,14 +6,14 @@ TARGET="${1:-/etc/agama.d/cmdline.conf}" INFO_CONTENT="${2:-/etc/agama.d/cmdline.info.conf}" expand_info_arg() { - INFO_URL=$(sed -n 's/.*[ ^]agama\.info=\([^[:space:]]\+\).*/\1/p' "$TARGET") + INFO_URL=$(sed -n 's/\(.*[[:space:]]\|^\)agama\.info=\([^[:space:]]\+\).*/\2/p' "$TARGET") if [ -z "${INFO_URL}" ]; then return 0 fi curl --silent "${INFO_URL}" > "${INFO_CONTENT}" # remove info param - sed -in 's/[ ^]agama\.info=[^[:space:]]\+//' "${TARGET}" + sed -in 's/([[:space:]]\|^\)[ ^]agama\.info=[^[:space:]]\+//' "${TARGET}" # and add content of info file cat "${INFO_CONTENT}" cat "${INFO_CONTENT}" >> "${TARGET}" From c3e592045934beb8dcfcc007acd654e895686dfb Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Jan 2025 17:36:12 +0100 Subject: [PATCH 10/24] remove debug output and fix sed --- live/root/usr/bin/info-cmdline-conf.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh index bdbd293c5b..6531c608fc 100755 --- a/live/root/usr/bin/info-cmdline-conf.sh +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -13,11 +13,9 @@ expand_info_arg() { curl --silent "${INFO_URL}" > "${INFO_CONTENT}" # remove info param - sed -in 's/([[:space:]]\|^\)[ ^]agama\.info=[^[:space:]]\+//' "${TARGET}" + sed -in 's/\([[:space:]]\|^\)[ ^]agama\.info=[^[:space:]]\+//' "${TARGET}" # and add content of info file - cat "${INFO_CONTENT}" cat "${INFO_CONTENT}" >> "${TARGET}" - cat "${INFO_CONTENT}" return 0 } From e35af4e582a65368e1b172ac2ecc1189be2b2541 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Jan 2025 19:52:34 +0100 Subject: [PATCH 11/24] allow password on kernel command line to handle new lines --- live/root/usr/bin/live-password | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/live/root/usr/bin/live-password b/live/root/usr/bin/live-password index 362e9be5ad..ef26470b6c 100755 --- a/live/root/usr/bin/live-password +++ b/live/root/usr/bin/live-password @@ -150,13 +150,14 @@ random_password() { } if [ "$1" = "--kernel" ]; then - # get the password from the kernel command line - PWD=$(awk -F 'live.password=' '{sub(/ .*$/, "", $2); print $2}' < /etc/agama.d/cmdline.conf) + # get the password from the kernel command line. It can contain newlines + PWD=$(grep 'live.password=' < /etc/agama.d/cmdline.conf | awk -F 'live.password=' '{sub(/ .*$/, "", $2); print $2}') if [ -n "$PWD" ]; then echo "$PWD" | passwd --stdin fi - PWD=$(awk -F 'live.password_hash=' '{sub(/ .*$/, "", $2); print $2}' < /etc/agama.d/cmdline.conf) + # get the password hash from the kernel command line. It can contain newlines + PWD=$(grep 'live.password_hash=' < /etc/agama.d/cmdline.conf | awk -F 'live.password_hash=' '{sub(/ .*$/, "", $2); print $2}') if [ -n "$PWD" ]; then usermod -p "$PWD" root fi From 01387673854093f71679471525157dc7d3f520f2 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 20 Jan 2025 20:15:15 +0100 Subject: [PATCH 12/24] remove properly info param --- live/root/usr/bin/info-cmdline-conf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh index 6531c608fc..c0c1edf671 100755 --- a/live/root/usr/bin/info-cmdline-conf.sh +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -13,7 +13,7 @@ expand_info_arg() { curl --silent "${INFO_URL}" > "${INFO_CONTENT}" # remove info param - sed -in 's/\([[:space:]]\|^\)[ ^]agama\.info=[^[:space:]]\+//' "${TARGET}" + sed -in 's/\([[:space:]]\|^\)agama\.info=[^[:space:]]\+//' "${TARGET}" # and add content of info file cat "${INFO_CONTENT}" >> "${TARGET}" From c693a25ca759fbe9b598f09e59a5cb3a2eef5a31 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 21 Jan 2025 10:39:02 +0100 Subject: [PATCH 13/24] add ci for live directory --- .github/workflows/ci-live.yml | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/ci-live.yml diff --git a/.github/workflows/ci-live.yml b/.github/workflows/ci-live.yml new file mode 100644 index 0000000000..6ccafe9f7c --- /dev/null +++ b/.github/workflows/ci-live.yml @@ -0,0 +1,59 @@ +name: CI - Service + +on: + push: + paths: + # NOTE: GitHub Actions do not allow using YAML references, the same path + # list is used below for the pull request event. Keep both lists in sync!! + + # this file as well + - .github/workflows/ci-live.yml + # any change in the service subfolder + - live/** + + pull_request: + paths: + # NOTE: GitHub Actions do not allow using YAML references, the same path + # list is used above for the push event. Keep both lists in sync!! + + # this file as well + - .github/workflows/ci-live.yml + # any change in the service subfolder + - live/** + + # allow running manually + workflow_dispatch: + +jobs: + ruby_tests: + runs-on: ubuntu-latest + env: + COVERAGE: 1 + + defaults: + run: + working-directory: ./live + + strategy: + fail-fast: false + matrix: + distro: [ "tumbleweed" ] + + container: + image: registry.opensuse.org/yast/head/containers_${{matrix.distro}}/yast-ruby + + steps: + + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Configure and refresh repositories + # disable unused repositories to have faster refresh + run: zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && zypper ref + + - name: Install Ruby development files + run: zypper --non-interactive install + make + + - name: Run the tests + run: make check From 49603158de5b34c958daf4b6c7d629d0bb27a883 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 21 Jan 2025 11:39:40 +0100 Subject: [PATCH 14/24] Update live/test/info_cmdline_test.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Knut Alejandro Anderssen González --- live/test/info_cmdline_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live/test/info_cmdline_test.rb b/live/test/info_cmdline_test.rb index 244b125186..93c1672c0d 100755 --- a/live/test/info_cmdline_test.rb +++ b/live/test/info_cmdline_test.rb @@ -9,7 +9,7 @@ let(:expected_path) { File.expand_path("fixtures/source/cmdline", __dir__, ) } - it "do nothing" do + it "does nothing" do Dir.mktmpdir do |tmpdir| target_path = File.join(tmpdir, "cmdline") FileUtils.cp(source_path, target_path) From 67abcfc881f626ef867b6a29a64c7b3bd4499ff2 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 21 Jan 2025 11:42:55 +0100 Subject: [PATCH 15/24] fix ci name --- .github/workflows/ci-live.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-live.yml b/.github/workflows/ci-live.yml index 6ccafe9f7c..044657aa1d 100644 --- a/.github/workflows/ci-live.yml +++ b/.github/workflows/ci-live.yml @@ -1,4 +1,4 @@ -name: CI - Service +name: CI - ISO definition on: push: From bde6563440f805f85038df4792214142be784465 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 29 Jan 2025 16:24:15 +0100 Subject: [PATCH 16/24] update kernel cmdline location --- autoinstallation/bin/agama-auto | 2 +- live/root/usr/bin/info-cmdline-conf.sh | 4 ++-- live/root/usr/bin/kernel-cmdline-conf.sh | 2 +- live/root/usr/bin/live-password | 4 ++-- .../lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh | 4 ++-- service/lib/agama/cmdline_args.rb | 1 - service/lib/agama/config_reader.rb | 2 +- service/lib/agama/software/product_builder.rb | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/autoinstallation/bin/agama-auto b/autoinstallation/bin/agama-auto index 5e1b4e76f5..b42695dc31 100755 --- a/autoinstallation/bin/agama-auto +++ b/autoinstallation/bin/agama-auto @@ -6,7 +6,7 @@ export YAST_SKIP_XML_VALIDATION=1 if [ -z "$1" ] then - url=$(awk -F 'agama.auto=' '{sub(/ .*$/, "", $2); print $2}' < /proc/cmdline) + url=$( grep 'agama.auto=' < /run/agama/cmdline.d/agama | awk -F 'agama.auto=' '{sub(/ .*$/, "", $2); print $2}' ) else url="$1" fi diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh index c0c1edf671..5550fb59df 100755 --- a/live/root/usr/bin/info-cmdline-conf.sh +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -2,8 +2,8 @@ set -e -TARGET="${1:-/etc/agama.d/cmdline.conf}" -INFO_CONTENT="${2:-/etc/agama.d/cmdline.info.conf}" +TARGET="${1:-/run/agama/cmdline.d/agama}" +INFO_CONTENT="${2:-/run/agama/cmdline.d/info}" expand_info_arg() { INFO_URL=$(sed -n 's/\(.*[[:space:]]\|^\)agama\.info=\([^[:space:]]\+\).*/\2/p' "$TARGET") diff --git a/live/root/usr/bin/kernel-cmdline-conf.sh b/live/root/usr/bin/kernel-cmdline-conf.sh index f44320b85c..484ae8af76 100755 --- a/live/root/usr/bin/kernel-cmdline-conf.sh +++ b/live/root/usr/bin/kernel-cmdline-conf.sh @@ -1,7 +1,7 @@ #! /bin/sh SOURCE="${1:-/proc/cmdline}" -TARGET="${2:-/etc/agama.d/kernel.cmdline.conf}" +TARGET="${2:-/run/agama/cmdline.d/kernel}" write_kernel_args() { DIR=$(dirname "${TARGET}") diff --git a/live/root/usr/bin/live-password b/live/root/usr/bin/live-password index ef26470b6c..1bad905eb1 100755 --- a/live/root/usr/bin/live-password +++ b/live/root/usr/bin/live-password @@ -151,13 +151,13 @@ random_password() { if [ "$1" = "--kernel" ]; then # get the password from the kernel command line. It can contain newlines - PWD=$(grep 'live.password=' < /etc/agama.d/cmdline.conf | awk -F 'live.password=' '{sub(/ .*$/, "", $2); print $2}') + PWD=$(grep 'live.password=' < /run/agama/cmdline.d/agama | awk -F 'live.password=' '{sub(/ .*$/, "", $2); print $2}') if [ -n "$PWD" ]; then echo "$PWD" | passwd --stdin fi # get the password hash from the kernel command line. It can contain newlines - PWD=$(grep 'live.password_hash=' < /etc/agama.d/cmdline.conf | awk -F 'live.password_hash=' '{sub(/ .*$/, "", $2); print $2}') + PWD=$(grep 'live.password_hash=' < /run/agama/cmdline.d/agama | awk -F 'live.password_hash=' '{sub(/ .*$/, "", $2); print $2}') if [ -n "$PWD" ]; then usermod -p "$PWD" root fi diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh index 612843ddd7..c747d0ed16 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh @@ -6,6 +6,6 @@ if [ -e /etc/cmdline.d/99-agama-cmdline.conf ]; then echo "Creating agama conf" - mkdir -p "$NEWROOT/etc/agama.d" - cp /etc/cmdline.d/99-agama-cmdline.conf "$NEWROOT/etc/agama.d/cmdline.conf" + mkdir -p "$NEWROOT/run/agama/cmdline.d" + cp /etc/cmdline.d/99-agama-cmdline.conf "$NEWROOT/run/agama/cmdline.d/agama" fi diff --git a/service/lib/agama/cmdline_args.rb b/service/lib/agama/cmdline_args.rb index 2863f86856..272937376e 100644 --- a/service/lib/agama/cmdline_args.rb +++ b/service/lib/agama/cmdline_args.rb @@ -22,7 +22,6 @@ module Agama # This class is responsible for reading Agama kernel cmdline options class CmdlineArgs - CMDLINE_PATH = "/proc/cmdline" CMDLINE_PREFIX = "agama." attr_accessor :config_url diff --git a/service/lib/agama/config_reader.rb b/service/lib/agama/config_reader.rb index debad5b1c1..cba181b65b 100644 --- a/service/lib/agama/config_reader.rb +++ b/service/lib/agama/config_reader.rb @@ -117,7 +117,7 @@ def copy_file(location, target) # @return [CmdlineArgs] def cmdline_args - @cmdline_args ||= CmdlineArgs.read_from(File.join(workdir, "/proc/cmdline")) + @cmdline_args ||= CmdlineArgs.read_from(File.join(workdir, "/run/agama/cmdline.d/agama")) end # return [Config] diff --git a/service/lib/agama/software/product_builder.rb b/service/lib/agama/software/product_builder.rb index a2507507bd..8b85e10162 100644 --- a/service/lib/agama/software/product_builder.rb +++ b/service/lib/agama/software/product_builder.rb @@ -37,7 +37,7 @@ def initialize(config, logger: Logger.new($stdout)) # # @return [Array] def build - cmdline_args = CmdlineArgs.read_from("/proc/cmdline") + cmdline_args = CmdlineArgs.read_from("/run/agama/cmdline.d/agama") @logger.info cmdline_args config.products.map do |id, attrs| data = product_data_from_config(id) From 74f7c333ab25276454eb83b1d512a92cef8db552 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 29 Jan 2025 16:29:44 +0100 Subject: [PATCH 17/24] follow redirects in info file url --- live/root/usr/bin/info-cmdline-conf.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/live/root/usr/bin/info-cmdline-conf.sh b/live/root/usr/bin/info-cmdline-conf.sh index 5550fb59df..df343c120a 100755 --- a/live/root/usr/bin/info-cmdline-conf.sh +++ b/live/root/usr/bin/info-cmdline-conf.sh @@ -11,7 +11,9 @@ expand_info_arg() { return 0 fi - curl --silent "${INFO_URL}" > "${INFO_CONTENT}" + # TODO: should we use also --location-trusted if info file url contain user and password? + # if so check with security team + curl --location --silent "${INFO_URL}" > "${INFO_CONTENT}" # remove info param sed -in 's/\([[:space:]]\|^\)agama\.info=[^[:space:]]\+//' "${TARGET}" # and add content of info file From 2a78da5b1201be196f7a8dcb45eb9b036c3fbb5a Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 30 Jan 2025 09:22:38 +0100 Subject: [PATCH 18/24] avoid exception if cmdline args does not exist --- service/lib/agama/cmdline_args.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service/lib/agama/cmdline_args.rb b/service/lib/agama/cmdline_args.rb index 272937376e..5a8af78ff6 100644 --- a/service/lib/agama/cmdline_args.rb +++ b/service/lib/agama/cmdline_args.rb @@ -36,9 +36,11 @@ def initialize(data = {}) # Reads the kernel command line options def self.read_from(path) - options = File.read(path) args = new({}) + return args unless File.exist?(path) + + options = File.read(path) options.split.each do |option| next unless option.start_with?(CMDLINE_PREFIX) From e0184bdc33e44514ac23b5d990f32458cbd43692 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 30 Jan 2025 09:31:06 +0100 Subject: [PATCH 19/24] adapt fixtures to reflect new structure --- .../fixtures/root_dir/{proc/cmdline => run/agama/cmdline.d/agama} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename service/test/fixtures/root_dir/{proc/cmdline => run/agama/cmdline.d/agama} (100%) diff --git a/service/test/fixtures/root_dir/proc/cmdline b/service/test/fixtures/root_dir/run/agama/cmdline.d/agama similarity index 100% rename from service/test/fixtures/root_dir/proc/cmdline rename to service/test/fixtures/root_dir/run/agama/cmdline.d/agama From 4dc697b368213890385c064fd6f7f431a8797696 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 30 Jan 2025 09:37:06 +0100 Subject: [PATCH 20/24] more test adaptation --- service/test/agama/cmdline_args_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/service/test/agama/cmdline_args_test.rb b/service/test/agama/cmdline_args_test.rb index fee3a392f8..e68c608c7c 100644 --- a/service/test/agama/cmdline_args_test.rb +++ b/service/test/agama/cmdline_args_test.rb @@ -28,28 +28,28 @@ describe ".read_from" do it "reads the kernel command line options and return a CmdlineArgs object" do - args = described_class.read_from(File.join(workdir, "/proc/cmdline")) + args = described_class.read_from(File.join(workdir, "/run/agama/cmdline.d/agama")) expect(args.data["auto"]).to eq("http://mydomain.org/tumbleweed.jsonnet") end it "sets #config_url if specified on cmdline" do - args = described_class.read_from(File.join(workdir, "/proc/cmdline")) + args = described_class.read_from(File.join(workdir, "/run/agama/cmdline.d/agama")) expect(args.config_url).to eql("http://example.org/agama.yaml") end it "converts 'true' and 'false' values into booleans" do - args = described_class.read_from(File.join(workdir, "/proc/cmdline")) + args = described_class.read_from(File.join(workdir, "/run/agama/cmdline.d/agama")) expect(args.data["web"]).to eql({ "ssl" => true }) end it "converts keys with dots after 'agama.' to hash" do - args = described_class.read_from(File.join(workdir, "/proc/cmdline")) + args = described_class.read_from(File.join(workdir, "/run/agama/cmdline.d/agama")) # here fixture has agama.web.ssl=true and result is this hash expect(args.data["web"]).to eq({ "ssl" => true }) end it "properly parse values that contain '='" do - args = described_class.read_from(File.join(workdir, "/proc/cmdline")) + args = described_class.read_from(File.join(workdir, "/run/agama/cmdline.d/agama")) expect(args.data["install_url"]).to eq("cd:/?devices=/dev/sr1") end end From 5348b50a909fd576f27a5c09f203be34f61b1a50 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Mon, 27 Jan 2025 16:33:10 +0000 Subject: [PATCH 21/24] Added module for translating ifcfg option --- .../99agama-cmdline/agama-network-compat.sh | 178 ++++++++++++++++++ .../modules.d/99agama-cmdline/module-setup.sh | 1 + 2 files changed, 179 insertions(+) create mode 100755 live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh new file mode 100755 index 0000000000..4efdae138d --- /dev/null +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh @@ -0,0 +1,178 @@ +#!/bin/sh + +[ -e /dracut-state.sh ] && . /dracut-state.sh + +. /lib/dracut-lib.sh +. /lib/net-lib.sh + +ifcfg_to_ip() { + local ip + local v="${2}", + local interface="$1" + local mac="$3" + local conf_path="/etc/cmdline.d/40-agama-network.conf" + set -- + while [ -n "$v" ]; do + set -- "$@" "${v%%,*}" + v=${v#*,} + done + + if [[ $# -eq 0 ]]; then + echo "IFCFG 0 options given, must be wrong" + return 1 + fi + + ### See https://en.opensuse.org/SDB:Linuxrc#Network_Config + # ifcfg==[try,]dhcp*,[rfc2132,]OPTION1=value1,OPTION2=value2... + if str_starts "$1" "dhcp"; then + autoconf="$1" + if [ "$autoconf" = "dhcp4" ]; then + echo "AUTOCONF" + autoconf="dhcp" + fi + case $autoconf in + "dhcp" | "dhcp6") + if [ "$interface" = "*" ]; then + echo "ip=${1}" >>"/etc/cmdline.d/40-agama-network.conf" + else + echo "ip=${interface}:${1}" >>$conf_path + fi + ;; + *) + echo "No supported option ${1}" + ;; + esac + + return 0 + fi + + # ifcifg==ip,gateway,nameserver,domain + if strglob "$1" "*.*.*.*/*"; then + [[ -n "$2" ]] && gateway=$2 + [[ -n "$3" ]] && nameserver=$3 + [[ -n "$4" ]] && domain=$4 + + ip="$1 " + set -- + while [ -n "$ip" ]; do + set -- "$@" "${ip%% *}" + ip="${ip#* }" + done + + ## TODO: IP is a LIST_IP + ip="$1" + mask=${ip##*/} + ip=${ip%%/*} + shift + + ## Configure the first interface, the gateway must belong to the same network + echo "ip=${ip}::${gateway}:$mask::${interface}" >>$conf_path + + ## Configure multiple addresses for the same interface + while [[ $# -gt 0 ]]; do + ip="$1" + mask=${ip##*/} + ip=${ip%%/*} + echo "ip=${ip}:::$mask::${interface}" >>$conf_path + shift + done + + ## Configure nameservers + if [[ -n $nameserver ]]; then + nameserver="$nameserver " + while [ -n "$nameserver" ]; do + echo "nameserver=${nameserver%% *}" >>$conf_path + nameserver="${nameserver#* }" + done + fi + fi + + return 0 +} + +translate_ifcfg() { + local i + local first + local match + local vlan + local phydevice + local conf_path="/etc/cmdline.d/40-agama-network.conf" + + while read i; do + set -- + echo "### Processing $i ###" + set -- "$@" "${i%%=*}" + options="${i#*=}" + pattern="$1" + first=0 + match=0 + unset vlan phydevice + + if str_starts "$options" "try,"; then + options="${i#*try,*}" + first=1 + fi + + # The pattern Looks like a VLAN like eth0.10 + if strglobin "$pattern" "*.[0-9]*"; then + phydevice=${pattern%.*} + vlan="vlan=$1:$phydevice" + echo "$vlan" >>$conf_path + ifcfg_to_ip "$pattern" "$options" + continue + fi + + # We cannot iterate over devices by now, therefore only '*' or an specific + # interface name is supported + #if [ "$pattern" = "*" ]; then + ifcfg_to_ip "$pattern" "$options" + continue + #fi + + # nm-initrd-generator is executed too early and there are no + # devices at all, therefore this code does not make sense by now + for path in /sys/class/net/*; do + iface=${path##*/} + mac=$(cat "$path/address") + echo " $path" + case $iface in + lo) + echo "Skipping lo interface" + continue + ;; + $pattern) + ifcfg_to_ip "$iface" "$options" + if [[ $first == 1 ]]; then + echo "try given, breaking" + match=1 + fi + #if [ -n "$ip" ]; then + # echo "ip=${ip}" >>"/etc/cmdline.d/agama_network.conf" + #fi + ;; + esac + case $mac in + $pattern) + ifcfg_to_ip "$iface" "$options" "$mac" + if [[ $first == 1 ]]; then + echo "try given, breaking" + match=1 + fi + ;; + esac + + if [[ "$match" -eq 1 ]] && [[ $first == 1 ]]; then + break + fi + done + echo + + set -- + unset options pattern + done <<<"$(getargs ifcfg=)" + + unset CMDLINE + return 0 +} + +translate_ifcfg diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh index 24a6bcd321..a25645c0f0 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh @@ -17,5 +17,6 @@ installkernel() { # called by dracut install() { inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" + inst_hook cmdline 99 "$moddir/agama-network-compat.sh" inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" } From 1be61eb2b9ec02c347f14cef3d29f511764db3e1 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Tue, 28 Jan 2025 21:57:54 +0000 Subject: [PATCH 22/24] Simplify scripts as many options are not supported --- .../99agama-cmdline/agama-network-compat.sh | 64 ++----------------- 1 file changed, 7 insertions(+), 57 deletions(-) diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh index 4efdae138d..e30400f123 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash [ -e /dracut-state.sh ] && . /dracut-state.sh @@ -9,7 +9,6 @@ ifcfg_to_ip() { local ip local v="${2}", local interface="$1" - local mac="$3" local conf_path="/etc/cmdline.d/40-agama-network.conf" set -- while [ -n "$v" ]; do @@ -50,7 +49,6 @@ ifcfg_to_ip() { if strglob "$1" "*.*.*.*/*"; then [[ -n "$2" ]] && gateway=$2 [[ -n "$3" ]] && nameserver=$3 - [[ -n "$4" ]] && domain=$4 ip="$1 " set -- @@ -92,25 +90,20 @@ ifcfg_to_ip() { translate_ifcfg() { local i - local first - local match local vlan local phydevice local conf_path="/etc/cmdline.d/40-agama-network.conf" - while read i; do + while read -r i; do set -- echo "### Processing $i ###" set -- "$@" "${i%%=*}" options="${i#*=}" pattern="$1" - first=0 - match=0 unset vlan phydevice if str_starts "$options" "try,"; then options="${i#*try,*}" - first=1 fi # The pattern Looks like a VLAN like eth0.10 @@ -118,60 +111,17 @@ translate_ifcfg() { phydevice=${pattern%.*} vlan="vlan=$1:$phydevice" echo "$vlan" >>$conf_path - ifcfg_to_ip "$pattern" "$options" - continue fi - # We cannot iterate over devices by now, therefore only '*' or an specific - # interface name is supported - #if [ "$pattern" = "*" ]; then + # Try to translate the pattern as it is, we cannot try to apply the config to check if + # it is valid because the nm-initrd-generator is called by a cmdline hook unless we call + # explicitly passing the getcmdline result ifcfg_to_ip "$pattern" "$options" - continue - #fi - - # nm-initrd-generator is executed too early and there are no - # devices at all, therefore this code does not make sense by now - for path in /sys/class/net/*; do - iface=${path##*/} - mac=$(cat "$path/address") - echo " $path" - case $iface in - lo) - echo "Skipping lo interface" - continue - ;; - $pattern) - ifcfg_to_ip "$iface" "$options" - if [[ $first == 1 ]]; then - echo "try given, breaking" - match=1 - fi - #if [ -n "$ip" ]; then - # echo "ip=${ip}" >>"/etc/cmdline.d/agama_network.conf" - #fi - ;; - esac - case $mac in - $pattern) - ifcfg_to_ip "$iface" "$options" "$mac" - if [[ $first == 1 ]]; then - echo "try given, breaking" - match=1 - fi - ;; - esac - - if [[ "$match" -eq 1 ]] && [[ $first == 1 ]]; then - break - fi - done - echo set -- - unset options pattern - done <<<"$(getargs ifcfg=)" + unset options pattern CMDLINE + done <<<"$(getargs ifcfg)" - unset CMDLINE return 0 } From 69d73518ecae7258e2d72ed46a1e1f0f295068f1 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 31 Jan 2025 12:46:34 +0000 Subject: [PATCH 23/24] Changes based on CR --- .../lib/dracut/modules.d/99agama-cmdline/README | 17 +++++++++++++++++ .../99agama-cmdline/agama-network-compat.sh | 9 ++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README index 2787db46c2..5d32a1ab7e 100644 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README @@ -4,3 +4,20 @@ dracut agama-cmdline module This module writes any agama configuration given through the kernel cmdline to its own cmdline conf file copying it to the sysroot. +It also tries to translate the linuxrc ifcfg kernel cmdline argument to the +corresponding ip one but only basic scenarios are supported. + +## Supported examples + + ifcfg=*=dhcp + ip=dhcp + + ifcfg=eth0=dhcp + ip=eth0:dhcp + + ifcfg=eth0.10=192.168.0.100/24,192.168.0.1 + vlan=eth0.10:eth0 ip=192.168.0.100::192.168.0.1:24::eth0.10 + + ifcfg="eth0=192.168.0.33/24 10.0.0.100/24,192.168.0.1,192.168.0.1 10.0.0.1,suse.de" + ip=192.168.0.33::192.168.0.1:24::eth0 nameserver=192.168.0.1 nameserver=10.0.0.1 ip=10.0.0.100:::24::eth0 + diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh index e30400f123..8a54c182c4 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh @@ -16,23 +16,18 @@ ifcfg_to_ip() { v=${v#*,} done - if [[ $# -eq 0 ]]; then - echo "IFCFG 0 options given, must be wrong" - return 1 - fi - ### See https://en.opensuse.org/SDB:Linuxrc#Network_Config # ifcfg==[try,]dhcp*,[rfc2132,]OPTION1=value1,OPTION2=value2... if str_starts "$1" "dhcp"; then autoconf="$1" if [ "$autoconf" = "dhcp4" ]; then - echo "AUTOCONF" autoconf="dhcp" fi case $autoconf in "dhcp" | "dhcp6") if [ "$interface" = "*" ]; then - echo "ip=${1}" >>"/etc/cmdline.d/40-agama-network.conf" + echo "ip=${1}" >>$conf_path + else echo "ip=${interface}:${1}" >>$conf_path fi From 58e31c56b154bbd6da37a0d68e903cbb5393685f Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 31 Jan 2025 12:54:14 +0000 Subject: [PATCH 24/24] Added changelog --- live/src/agama-installer.changes | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/live/src/agama-installer.changes b/live/src/agama-installer.changes index b8e7b46303..9b111e9946 100644 --- a/live/src/agama-installer.changes +++ b/live/src/agama-installer.changes @@ -1,3 +1,13 @@ +------------------------------------------------------------------- +Fri Jan 31 12:49:24 UTC 2025 - Knut Anderssen + +- Added support for giving a file url with extra kernel cmdline + arguments (agama.info) which was known as the info file in + linuxrc. +- Added basic support for translating the ifcfg kernel cmdline arg + to its ip equivalent (gh#agama-project/agama#1896). +- Moved the kernel cmdline conf under /run/agama/cmdline.d + ------------------------------------------------------------------- Wed Jan 15 16:53:28 UTC 2025 - Eugenio Paolantonio