commit:     1a135f1a0f1b26c277bb75db6667c6a816c2931f
Author:     benaryorg <binary <AT> benary <DOT> org>
AuthorDate: Thu Oct 30 15:47:19 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Dec 16 03:15:01 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=1a135f1a

etc-update: Allow overriding the os-family

This allows tests on CI runners to run the *etc-update* tests for
arbitrary target distributions.

Signed-off-by: benaryorg <binary <AT> benary.org>
Part-of: https://github.com/gentoo/portage/pull/1494
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/etc-update                                  | 22 ++++++++++++++--------
 lib/portage/tests/emerge/test_config_protect.py |  1 +
 man/etc-update.1                                |  6 ++++++
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/bin/etc-update b/bin/etc-update
index fff5d99550..e3bc3da251 100755
--- a/bin/etc-update
+++ b/bin/etc-update
@@ -34,14 +34,20 @@ get_config() {
                "${PORTAGE_CONFIGROOT}"etc/etc-update.conf)
 }
 
-OS_RELEASE_POSSIBLE_IDS=$(source /etc/os-release >/dev/null 2>&1; echo 
":${ID}:${ID_LIKE//[[:space:]]/:}:")
-
-case ${OS_RELEASE_POSSIBLE_IDS} in
-       *:suse:*|*:opensuse:*|*:opensuse-tumbleweed:*) OS_FAMILY='rpm';;
-       *:fedora:*|*:rhel:*) OS_FAMILY='rpm';;
-       *:arch:*) OS_FAMILY='arch' NEW_EXT='pacnew';;
-       *) OS_FAMILY='gentoo';;
-esac
+# Allow overriding the detected os family using an environment variable.
+# The primary use is for the CI runner to force a specific behaviour for tests.
+if [[ -n ${ETC_UPDATE_OS_FAMILY} ]]; then
+       OS_FAMILY="${ETC_UPDATE_OS_FAMILY}"
+else
+       OS_RELEASE_POSSIBLE_IDS=$(source /etc/os-release >/dev/null 2>&1; echo 
":${ID}:${ID_LIKE//[[:space:]]/:}:")
+
+       case ${OS_RELEASE_POSSIBLE_IDS} in
+               *:suse:*|*:opensuse:*|*:opensuse-tumbleweed:*) OS_FAMILY='rpm';;
+               *:fedora:*|*:rhel:*) OS_FAMILY='rpm';;
+               *:arch:*) OS_FAMILY='arch' NEW_EXT='pacnew';;
+               *) OS_FAMILY='gentoo';;
+       esac
+fi
 
 if [[ ${OS_FAMILY} == 'gentoo' ]]; then
        get_basename() {

diff --git a/lib/portage/tests/emerge/test_config_protect.py 
b/lib/portage/tests/emerge/test_config_protect.py
index 59a2c23b90..32a4790f5a 100644
--- a/lib/portage/tests/emerge/test_config_protect.py
+++ b/lib/portage/tests/emerge/test_config_protect.py
@@ -220,6 +220,7 @@ src_install() {
             "DISTDIR": distdir,
             "EMERGE_DEFAULT_OPTS": "-v",
             "EMERGE_WARNING_DELAY": "0",
+            "ETC_UPDATE_OS_FAMILY": "gentoo",
             "INFODIR": "",
             "INFOPATH": "",
             "PATH": path,

diff --git a/man/etc-update.1 b/man/etc-update.1
index 9b82e1f5c5..0f7f80b44c 100644
--- a/man/etc-update.1
+++ b/man/etc-update.1
@@ -18,6 +18,12 @@ See \fBmake.conf\fR(5) for more information.
 .PP
 \fIetc\-update\fR respects the normal \fIPORTAGE_CONFIGROOT\fR and
 \fIEROOT\fR variables for finding the aforementioned config protect variables.
+.PP
+Multiple target distributions are supported, including \fIportage\fR(5),
+\fIrpm\fR(1), \fIpacman\fR(1), and \fIdpkg\fR(1) based systems.  Detection of
+the target package management system is done by inspecting
+\fI/etc/os\-release\fR. \fIETC_UPDATE_OS_FAMILY\fR can be used to override this
+detection.
 .SH "OPTIONS"
 .TP
 .BR \-d ", " \-\-debug

Reply via email to