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() --