From 3f229cac4c98a6c03008467bcb127ca417211506 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:46:31 -0300 Subject: [PATCH] refactor(build): install the genesis postscripts through write_script builddebs.pl stages the genesis bmcsetup and getipmi helpers into the xCAT package by writing the rewritten text and then chmod'ing it, which is the third copy of the write-then-make-executable pair the previous change collapsed. It was left out because it uses 0755 while the published repo helper uses 0775. Give write_script an optional mode, defaulting to the 0775 it already used, and use it for the postscripts with 0755. The two modes stay exactly as they were -- the postscripts are deliberately not group-writable -- and the test asserts that the caller's mode is honoured rather than overwritten by the default. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- BuildUtils.pm | 13 ++++++++----- builddebs.pl | 3 +-- xCAT-test/unit/build_utils.t | 6 ++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/BuildUtils.pm b/BuildUtils.pm index fe3f3e2fd..3e9067bc3 100644 --- a/BuildUtils.pm +++ b/BuildUtils.pm @@ -85,13 +85,16 @@ sub write_file { } # Write a helper script and make it executable. Both builders ship a -# mklocalrepo.sh beside the packages they publish; a script written without the -# executable bit is published broken, so the mode is not left to the caller to -# remember. +# mklocalrepo.sh beside the packages they publish, and builddebs.pl installs the +# genesis postscripts the same way; a script written without the executable bit +# is shipped broken, so the mode is not left to the caller to remember. It +# still varies -- the published repo helper is group-writable, the postscripts +# are not -- so the caller may say, and 0775 is only the default. sub write_script { - my ($path, $content) = @_; + my ($path, $content, $mode) = @_; + $mode = 0775 unless defined $mode; write_file($path, $content); - chmod 0775, $path or die "Cannot chmod $path: $!\n"; + chmod $mode, $path or die "Cannot chmod $path: $!\n"; return; } diff --git a/builddebs.pl b/builddebs.pl index c3a7d8637..1868cb98d 100755 --- a/builddebs.pl +++ b/builddebs.pl @@ -199,8 +199,7 @@ sub with_prepared_tree { $claim->("postscripts/$f"); my $text = read_file($src); $text =~ s/xcat\.genesis\.\Q$f\E/$f/g; - write_file($dst, $text); - chmod 0755, $dst; + write_script($dst, $text, 0755); } } # xCAT-genesis-scripts keeps a control file per architecture. diff --git a/xCAT-test/unit/build_utils.t b/xCAT-test/unit/build_utils.t index 1d1a53609..9fe0f6e25 100644 --- a/xCAT-test/unit/build_utils.t +++ b/xCAT-test/unit/build_utils.t @@ -373,6 +373,12 @@ isnt( git_revision( git => sub { '' }, read_file => sub { '' } ), '', ok( -x $path, 'and is executable, which is the point of writing it this way' ); is( (stat $path)[2] & 07777, 0775, 'with the mode both builders published before' ); + + # The genesis postscripts builddebs.pl installs are 0755, not 0775, so the + # mode has to stay the caller's to choose. + my $ps = File::Spec->catfile($dir, 'bmcsetup'); + BuildUtils::write_script($ps, "#!/bin/sh\n", 0755); + is( (stat $ps)[2] & 07777, 0755, 'a caller may ask for a different mode' ); } # ---------------------------------------------------------------- sh() --