From 9aedc04976eefb2d42c9a3f72e18c91a0b775a58 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Tue, 7 Jan 2025 10:18:35 +0000 Subject: [PATCH 1/6] Initial implementation for agama cmdline conf --- .../systemd/system/agama-cmdline-env.service | 17 ++++++++++ live/root/usr/bin/agama-cmdline-env | 24 ++++++++++++++ .../dracut/modules.d/99agama-cmdline/README | 6 ++++ .../99agama-cmdline/agama-cmdline-conf.sh | 32 +++++++++++++++++++ .../modules.d/99agama-cmdline/module-setup.sh | 21 ++++++++++++ .../99agama-cmdline/save-agama-conf.sh | 11 +++++++ 6 files changed, 111 insertions(+) create mode 100644 live/root/etc/systemd/system/agama-cmdline-env.service create mode 100755 live/root/usr/bin/agama-cmdline-env create mode 100644 live/root/usr/lib/dracut/modules.d/99agama-cmdline/README create mode 100755 live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh create mode 100755 live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh create mode 100755 live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh diff --git a/live/root/etc/systemd/system/agama-cmdline-env.service b/live/root/etc/systemd/system/agama-cmdline-env.service new file mode 100644 index 0000000000..096d5b5df4 --- /dev/null +++ b/live/root/etc/systemd/system/agama-cmdline-env.service @@ -0,0 +1,17 @@ +[Unit] +Description=Export the configuration from kernel command line as environment variables + +# before starting the Agama server +Before=agama-web-server.service +Before=agama.service + +# before the interactive setting methods so they can override it +Before=live-password-dialog.service +Before=live-password-systemd.service + +[Service] +ExecStart=source /usr/bin/agama-cmdline-env +Type=oneshot + +[Install] +WantedBy=default.target diff --git a/live/root/usr/bin/agama-cmdline-env b/live/root/usr/bin/agama-cmdline-env new file mode 100755 index 0000000000..4e4dded3b9 --- /dev/null +++ b/live/root/usr/bin/agama-cmdline-env @@ -0,0 +1,24 @@ +#!/bin/sh + +#----[ import_agama_env ]----# +function import_agama_env () { +#-------------------------------------------------- +# import agama cmdline information as environment +# variables to the current environment +# --- + TERM_SAVE=$TERM + if [ -f /etc/agama.d/cmdline.conf ]; then + IFS_SAVE=$IFS +IFS=" +" + for i in `cat /etc/agama.d/cmdline.conf | sed -e s'@=@%@'`;do + varname=`echo $i | cut -f 1 -d% | tr -d " " | sed -e s'@\.@_@'` + varvals=`echo $i | cut -f 2 -d%` + varvals=`echo $varvals | sed -e s'@^ *@@' -e s'@ *$@@'` + export $varname=$varvals + done + IFS=$IFS_SAVE + fi +} + +import_agama_env diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README new file mode 100644 index 0000000000..2787db46c2 --- /dev/null +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/README @@ -0,0 +1,6 @@ +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. + diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh new file mode 100755 index 0000000000..f006ca30f1 --- /dev/null +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh @@ -0,0 +1,32 @@ +#! /bin/sh + +[ -e /dracut-state.sh ] && . /dracut-state.sh + +. /lib/dracut-lib.sh + +get_agama_args() { + local _i _found + + for _i in $CMDLINE; do + case $_i in + LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_*) + _found=1 + ;; + esac + + if [ -n "$_found" ]; then + printf "Agama variable found ($_i)" + printf $_i + if ! strstr "$_i" "="; then + # Set the variable as a boolean if there is no assignation + _i="${_i}=1" + fi + echo $_i >>/etc/cmdline.d/99-agama-cmdline.conf + fi + unset _found + done + + return 0 +} + +get_agama_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 new file mode 100755 index 0000000000..d957ddab0e --- /dev/null +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# called by dracut +check() { + return 0 +} + +# called by dracut +depends() { + return 0 +} + +installkernel() { + return 0 +} + +# called by dracut +install() { + inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" + inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" +} 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 new file mode 100755 index 0000000000..99a328b7ee --- /dev/null +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +[ -e /dracut-state.sh ] && . /dracut-state.sh + +. /lib/dracut-lib.sh + +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" +fi From 57054c91e97cc5c4f81afe13319e5be1b1b81ad1 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 8 Jan 2025 08:26:18 +0000 Subject: [PATCH 2/6] Enable agama-cmdline service --- live/src/config.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/live/src/config.sh b/live/src/config.sh index d326a0c76b..9a991eb07e 100644 --- a/live/src/config.sh +++ b/live/src/config.sh @@ -16,7 +16,7 @@ suseSetupProduct DISTRO=$(grep "^NAME" /etc/os-release | cut -f2 -d\= | tr -d '"' | tr " " "_") REPO="/etc/zypp/repos.d/agama-${DISTRO}.repo" if [ -f "${REPO}.disabled" ]; then - mv "${REPO}.disabled" $REPO + mv "${REPO}.disabled" $REPO fi rm /etc/zypp/repos.d/*.disabled @@ -29,12 +29,13 @@ rpm --import /tmp/Devel_YaST_Agama_Head_key.gpg rm /tmp/Devel_YaST_Agama_Head_key.gpg # import the openSUSE keys, but check if there is any if stat -t /usr/lib/rpm/gnupg/keys/*.asc 2>/dev/null 1>/dev/null; then - rpm --import /usr/lib/rpm/gnupg/keys/*.asc + rpm --import /usr/lib/rpm/gnupg/keys/*.asc fi # activate services systemctl enable sshd.service systemctl enable NetworkManager.service +systemctl enable agama-cmdline-env.service systemctl enable avahi-daemon.service systemctl enable agama.service systemctl enable agama-web-server.service @@ -82,11 +83,11 @@ echo "root_disk=live:LABEL=$label" >>/etc/cmdline.d/10-liveroot.conf # if there's a default network location, add it here # echo "root_net=" >> /etc/cmdline.d/10-liveroot.conf echo 'install_items+=" /etc/cmdline.d/10-liveroot.conf "' >/etc/dracut.conf.d/10-liveroot-file.conf -echo 'add_dracutmodules+=" dracut-menu "' >>/etc/dracut.conf.d/10-liveroot-file.conf +echo 'add_dracutmodules+=" dracut-menu agama-cmdline "' >>/etc/dracut.conf.d/10-liveroot-file.conf -if [ "${arch}" = "s390x" ];then - # workaround for custom bootloader setting - touch /config.bootoptions +if [ "${arch}" = "s390x" ]; then + # workaround for custom bootloader setting + touch /config.bootoptions fi # replace the @@LIVE_MEDIUM_LABEL@@ with the real Live partition label name from KIWI @@ -111,7 +112,7 @@ rm /var/log/zypper.log /var/log/zypp/history # reduce the "vim-data" content, this package is huge (37MB unpacked!), keep only # support for JSON (for "agama config edit") and Ruby (fixing/debugging the Ruby # service) -rpm -ql vim-data | grep -v -e '/ruby.vim$' -e '/json.vim$' -e colors | xargs rm 2> /dev/null || true +rpm -ql vim-data | grep -v -e '/ruby.vim$' -e '/json.vim$' -e colors | xargs rm 2>/dev/null || true du -h -s /usr/{share,lib}/locale/ @@ -125,7 +126,7 @@ du -h -s /usr/{share,lib}/locale/ mkdir -p /etc/agama.d # emulate "localectl list-locales" call, it cannot be used here because it # insists on running systemd as PID 1 :-/ -ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8#" > /etc/agama.d/locales +ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8#" >/etc/agama.d/locales # delete translations and unusupported languages (makes ISO about 22MiB smaller) # build list of ignore options for "ls" with supported languages like "-I cs* -I de* -I es* ..." @@ -138,7 +139,7 @@ ls -1 "${IGNORE_OPTS[@]}" -I "en_US*" -I "C.*" /usr/lib/locale/ | xargs -I% sh - # delete unused translations (MO files) for t in zypper gettext-runtime p11-kit; do - rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo + rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo done du -h -s /usr/{share,lib}/locale/ From b8a69c5ed05197642322b15bebf80730ab8e9eb4 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 8 Jan 2025 09:23:57 +0000 Subject: [PATCH 3/6] Use a EnvironmentFile for agama --- .../systemd/system/agama-cmdline-env.service | 17 ------------- live/root/usr/bin/agama-cmdline-env | 24 ------------------- live/src/config.sh | 1 - rust/share/agama-web-server.service | 1 + service/share/agama.service | 1 + 5 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 live/root/etc/systemd/system/agama-cmdline-env.service delete mode 100755 live/root/usr/bin/agama-cmdline-env diff --git a/live/root/etc/systemd/system/agama-cmdline-env.service b/live/root/etc/systemd/system/agama-cmdline-env.service deleted file mode 100644 index 096d5b5df4..0000000000 --- a/live/root/etc/systemd/system/agama-cmdline-env.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Export the configuration from kernel command line as environment variables - -# before starting the Agama server -Before=agama-web-server.service -Before=agama.service - -# before the interactive setting methods so they can override it -Before=live-password-dialog.service -Before=live-password-systemd.service - -[Service] -ExecStart=source /usr/bin/agama-cmdline-env -Type=oneshot - -[Install] -WantedBy=default.target diff --git a/live/root/usr/bin/agama-cmdline-env b/live/root/usr/bin/agama-cmdline-env deleted file mode 100755 index 4e4dded3b9..0000000000 --- a/live/root/usr/bin/agama-cmdline-env +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -#----[ import_agama_env ]----# -function import_agama_env () { -#-------------------------------------------------- -# import agama cmdline information as environment -# variables to the current environment -# --- - TERM_SAVE=$TERM - if [ -f /etc/agama.d/cmdline.conf ]; then - IFS_SAVE=$IFS -IFS=" -" - for i in `cat /etc/agama.d/cmdline.conf | sed -e s'@=@%@'`;do - varname=`echo $i | cut -f 1 -d% | tr -d " " | sed -e s'@\.@_@'` - varvals=`echo $i | cut -f 2 -d%` - varvals=`echo $varvals | sed -e s'@^ *@@' -e s'@ *$@@'` - export $varname=$varvals - done - IFS=$IFS_SAVE - fi -} - -import_agama_env diff --git a/live/src/config.sh b/live/src/config.sh index 9a991eb07e..65f6e9f0c7 100644 --- a/live/src/config.sh +++ b/live/src/config.sh @@ -35,7 +35,6 @@ fi # activate services systemctl enable sshd.service systemctl enable NetworkManager.service -systemctl enable agama-cmdline-env.service systemctl enable avahi-daemon.service systemctl enable agama.service systemctl enable agama-web-server.service diff --git a/rust/share/agama-web-server.service b/rust/share/agama-web-server.service index 0c8b27a4d8..210161d554 100644 --- a/rust/share/agama-web-server.service +++ b/rust/share/agama-web-server.service @@ -6,6 +6,7 @@ After=network-online.target agama.service agama-hostname.service BindsTo=agama.service [Service] +EnvironmentFile=-"/etc/agama.d/cmdline.conf" Environment="AGAMA_LOG=debug,zbus=info" Type=notify ExecStart=/usr/bin/agama-web-server serve --address :::80 --address2 :::443 diff --git a/service/share/agama.service b/service/share/agama.service index f9b9bcfeb3..0392ff5783 100644 --- a/service/share/agama.service +++ b/service/share/agama.service @@ -5,6 +5,7 @@ After=network-online.target [Service] Type=forking ExecStart=/usr/bin/agamactl --daemon +EnviromentFile=-/etc/agama.d/cmdline.conf PIDFile=/run/agama/bus.pid User=root TimeoutStopSec=5 From 90a2d77819f41fb79d03d85c09c91dd82f338db4 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 8 Jan 2025 12:12:54 +0000 Subject: [PATCH 4/6] Added changelog --- live/src/agama-installer.changes | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/live/src/agama-installer.changes b/live/src/agama-installer.changes index 8d573634a3..7113bb56f0 100644 --- a/live/src/agama-installer.changes +++ b/live/src/agama-installer.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Jan 8 12:10:39 UTC 2025 - Knut Anderssen + +- Make agama kernel cmdline options available in the sysroot at + /etc/agama.d/cmdline.conf and set it as a EnvironmentFile + in Agama related services (gh#agama-project/agama#1866). + ------------------------------------------------------------------- Tue Dec 10 12:46:06 UTC 2024 - Michal Filka From f1de0ade3383d1a3fc79f7e77faa689737e7139d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Alejandro=20Anderssen=20Gonz=C3=A1lez?= Date: Wed, 8 Jan 2025 13:04:46 +0000 Subject: [PATCH 5/6] Update live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh --- .../lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh index f006ca30f1..eca0743012 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh @@ -16,7 +16,6 @@ get_agama_args() { if [ -n "$_found" ]; then printf "Agama variable found ($_i)" - printf $_i if ! strstr "$_i" "="; then # Set the variable as a boolean if there is no assignation _i="${_i}=1" From 6bd88fc2ccc4c6ee50ca5470632ddf2d1eff8cab Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 8 Jan 2025 14:16:28 +0000 Subject: [PATCH 6/6] Fix indentation --- .../99agama-cmdline/agama-cmdline-conf.sh | 36 +++++++++---------- .../modules.d/99agama-cmdline/module-setup.sh | 10 +++--- .../99agama-cmdline/save-agama-conf.sh | 6 ++-- live/src/config.sh | 12 +++---- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh index eca0743012..e1ec13f79b 100755 --- a/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh +++ b/live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-cmdline-conf.sh @@ -5,27 +5,27 @@ . /lib/dracut-lib.sh get_agama_args() { - local _i _found + local _i _found - for _i in $CMDLINE; do - case $_i in - LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_*) - _found=1 - ;; - esac + for _i in $CMDLINE; do + case $_i in + LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_*) + _found=1 + ;; + esac - if [ -n "$_found" ]; then - printf "Agama variable found ($_i)" - if ! strstr "$_i" "="; then - # Set the variable as a boolean if there is no assignation - _i="${_i}=1" - fi - echo $_i >>/etc/cmdline.d/99-agama-cmdline.conf - fi - unset _found - done + if [ -n "$_found" ]; then + printf "Agama variable found ($_i)" + if ! strstr "$_i" "="; then + # Set the variable as a boolean if there is no assignation + _i="${_i}=1" + fi + echo $_i >>/etc/cmdline.d/99-agama-cmdline.conf + fi + unset _found + done - return 0 + return 0 } get_agama_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 d957ddab0e..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 @@ -2,20 +2,20 @@ # called by dracut check() { - return 0 + return 0 } # called by dracut depends() { - return 0 + return 0 } installkernel() { - return 0 + return 0 } # called by dracut install() { - inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" - inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" + inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" + inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" } 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 99a328b7ee..612843ddd7 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 @@ -5,7 +5,7 @@ . /lib/dracut-lib.sh 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" + echo "Creating agama conf" + mkdir -p "$NEWROOT/etc/agama.d" + cp /etc/cmdline.d/99-agama-cmdline.conf "$NEWROOT/etc/agama.d/cmdline.conf" fi diff --git a/live/src/config.sh b/live/src/config.sh index 65f6e9f0c7..607fe25094 100644 --- a/live/src/config.sh +++ b/live/src/config.sh @@ -16,7 +16,7 @@ suseSetupProduct DISTRO=$(grep "^NAME" /etc/os-release | cut -f2 -d\= | tr -d '"' | tr " " "_") REPO="/etc/zypp/repos.d/agama-${DISTRO}.repo" if [ -f "${REPO}.disabled" ]; then - mv "${REPO}.disabled" $REPO + mv "${REPO}.disabled" $REPO fi rm /etc/zypp/repos.d/*.disabled @@ -29,7 +29,7 @@ rpm --import /tmp/Devel_YaST_Agama_Head_key.gpg rm /tmp/Devel_YaST_Agama_Head_key.gpg # import the openSUSE keys, but check if there is any if stat -t /usr/lib/rpm/gnupg/keys/*.asc 2>/dev/null 1>/dev/null; then - rpm --import /usr/lib/rpm/gnupg/keys/*.asc + rpm --import /usr/lib/rpm/gnupg/keys/*.asc fi # activate services @@ -85,8 +85,8 @@ echo 'install_items+=" /etc/cmdline.d/10-liveroot.conf "' >/etc/dracut.conf.d/10 echo 'add_dracutmodules+=" dracut-menu agama-cmdline "' >>/etc/dracut.conf.d/10-liveroot-file.conf if [ "${arch}" = "s390x" ]; then - # workaround for custom bootloader setting - touch /config.bootoptions + # workaround for custom bootloader setting + touch /config.bootoptions fi # replace the @@LIVE_MEDIUM_LABEL@@ with the real Live partition label name from KIWI @@ -138,7 +138,7 @@ ls -1 "${IGNORE_OPTS[@]}" -I "en_US*" -I "C.*" /usr/lib/locale/ | xargs -I% sh - # delete unused translations (MO files) for t in zypper gettext-runtime p11-kit; do - rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo + rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo done du -h -s /usr/{share,lib}/locale/ @@ -180,7 +180,7 @@ du -h -s /lib/modules /lib/firmware # disable the services included by dependencies for s in purge-kernels; do - systemctl -f disable $s || true + systemctl -f disable $s || true done # Only used for OpenCL and X11 acceleration on vmwgfx (?), saves ~50MiB