From 5b5fa69791f33b920534e73b0c4d91ea2cd53417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sun, 30 Aug 2026 18:14:23 -0300 Subject: [PATCH] build(httpd): centralize Apache configuration sources --- build-utils/sync-xcat-apache-configs | 113 +++++++++++++++++++++++++++ buildrpms.pl | 6 +- makerpm | 7 +- xCAT/xcat.conf | 2 +- xCAT/xcat.conf.apach24 | 2 +- xCATsn/xcat.conf | 2 +- xCATsn/xcat.conf.apach24 | 3 +- 7 files changed, 125 insertions(+), 10 deletions(-) create mode 100755 build-utils/sync-xcat-apache-configs diff --git a/build-utils/sync-xcat-apache-configs b/build-utils/sync-xcat-apache-configs new file mode 100755 index 000000000..47780ff9d --- /dev/null +++ b/build-utils/sync-xcat-apache-configs @@ -0,0 +1,113 @@ +#!/bin/sh + +set -eu + +usage() +{ + printf 'Usage: %s --check|--write|--stage DIRECTORY\n' "${0##*/}" >&2 +} + +case ${1-}:$# in + --check:1|--write:1) + mode=$1 + ;; + --stage:2) + mode=$1 + stage_directory=$2 + ;; + *) + usage + exit 2 + ;; +esac + +script_dir=$(CDPATH='' cd "$(dirname "$0")" && pwd -P) +repo_root=$(CDPATH='' cd "$script_dir/.." && pwd -P) +status=0 +temp_file= + +trap 'if [ -n "$temp_file" ]; then rm -f "$temp_file"; fi' 0 +trap 'exit 1' 1 2 3 15 + +has_expected_mode() +{ + mode_path=$1 + mode_match=$(find "$mode_path" -prune -type f -perm 0644 -print 2>/dev/null) + [ "$mode_match" = "$mode_path" ] +} + +replace_target() +{ + replace_source=$1 + replace_target=$2 + + if [ -d "$replace_target" ]; then + printf '%s cannot replace a directory\n' "$replace_target" >&2 + return 1 + fi + temp_file=$(mktemp "$replace_target.tmp.XXXXXX") + cp "$replace_source" "$temp_file" + chmod 0644 "$temp_file" + mv -f "$temp_file" "$replace_target" + temp_file= +} + +validate_source() +{ + source_relative=$1 + source_path=$repo_root/$source_relative + if [ ! -f "$source_path" ] || [ -L "$source_path" ]; then + printf '%s must be a regular file\n' "$source_relative" >&2 + status=1 + fi +} + +sync_pair() +{ + source_relative=$1 + target_relative=$2 + source_path=$repo_root/$source_relative + target_path=$repo_root/$target_relative + + content_matches=0 + if [ -f "$target_path" ] && [ ! -L "$target_path" ] && \ + cmp "$source_path" "$target_path" >/dev/null 2>&1; then + content_matches=1 + if has_expected_mode "$target_path"; then + return + fi + fi + + if [ "$mode" = "--check" ]; then + printf '%s is out of date; run %s --write\n' \ + "$target_relative" "${0##*/}" >&2 + status=1 + return + fi + + replace_target "$source_path" "$target_path" + if [ "$content_matches" -eq 0 ]; then + printf 'updated %s\n' "$target_relative" + fi +} + +validate_source xCAT/xcat.conf +validate_source xCAT/xcat.conf.apach24 +if [ "$status" -ne 0 ]; then + exit "$status" +fi + +if [ "$mode" = "--stage" ]; then + if [ ! -d "$stage_directory" ]; then + printf '%s is not a directory\n' "$stage_directory" >&2 + exit 1 + fi + replace_target "$repo_root/xCAT/xcat.conf" "$stage_directory/xcat.conf" + replace_target "$repo_root/xCAT/xcat.conf.apach24" \ + "$stage_directory/xcat.conf.apach24" +else + sync_pair xCAT/xcat.conf xCATsn/xcat.conf + sync_pair xCAT/xcat.conf.apach24 xCATsn/xcat.conf.apach24 +fi + +exit "$status" diff --git a/buildrpms.pl b/buildrpms.pl index 0304de400..fee5ada80 100755 --- a/buildrpms.pl +++ b/buildrpms.pl @@ -443,10 +443,10 @@ EOF tar --sort=name --owner=0 --group=0 --mtime="\@$SOURCE_DATE_EPOCH" -czf "$SOURCES/$pkg-$VERSION.tar.gz" $pkg tar --sort=name --owner=0 --group=0 --mtime="\@$SOURCE_DATE_EPOCH" -czf "$SOURCES/license.tar.gz" -C $pkg LICENSE.html tar --sort=name --owner=0 --group=0 --mtime="\@$SOURCE_DATE_EPOCH" -czf "$SOURCES/etc.tar.gz" -C xCAT etc - cp $pkg/xcat.conf $SOURCES - cp $pkg/xcat.conf.apach24 $SOURCES - cp $pkg/xCATSN $SOURCES EOF + system('build-utils/sync-xcat-apache-configs', '--stage', $SOURCES) == 0 + or die "FATAL: unable to stage canonical Apache configurations\n"; + cp "$pkg/xCATSN", $SOURCES; # xCATsn.spec consumes templates from xCAT shared templates payload. sh qq(tar --sort=name --owner=0 --group=0 --mtime="\@$SOURCE_DATE_EPOCH" -czf "$SOURCES/templates.tar.gz" xCAT/templates) unless -f "$SOURCES/templates.tar.gz"; } elsif ($pkg eq "xCAT-probe") { diff --git a/makerpm b/makerpm index c65a02da3..ae4a41fc8 100755 --- a/makerpm +++ b/makerpm @@ -141,8 +141,11 @@ function makexcat { elif [ "$RPMNAME" = "xCATsn" ]; then cd `dirname $0`/$RPMNAME tar --exclude .svn -czf $RPMROOT/SOURCES/license.tar.gz LICENSE.html - cp xcat.conf $RPMROOT/SOURCES - cp xcat.conf.apach24 $RPMROOT/SOURCES + ../build-utils/sync-xcat-apache-configs --stage "$RPMROOT/SOURCES" || { + RC=$? + cd - >/dev/null + return $RC + } cp xCATSN $RPMROOT/SOURCES cp -a ../xCAT/etc/rsyslog.d $RPMROOT/ cp -a ../xCAT/etc/logrotate.d $RPMROOT/ diff --git a/xCAT/xcat.conf b/xCAT/xcat.conf index c205a24f9..476d3c50b 100644 --- a/xCAT/xcat.conf +++ b/xCAT/xcat.conf @@ -2,7 +2,7 @@ # This configuration file allows a diskfull install to access the install images # via http. It also allows the xCAT documentation to be accessed via # http://localhost/xcat-doc/ -# Updates to xCAT/xcat.conf should also be made to xCATsn/xcat.conf +# Service-node copies are generated from the matching configuration under xCAT/. # ServerTokens Prod diff --git a/xCAT/xcat.conf.apach24 b/xCAT/xcat.conf.apach24 index 0b032f246..3dfa318a0 100644 --- a/xCAT/xcat.conf.apach24 +++ b/xCAT/xcat.conf.apach24 @@ -2,7 +2,7 @@ # This configuration file allows a diskfull install to access the install images # via http. It also allows the xCAT documentation to be accessed via # http://localhost/xcat-doc/ -# Updates to xCAT/xcat.conf should also be made to xCATsn/xcat.conf +# Service-node copies are generated from the matching configuration under xCAT/. # ServerTokens Prod diff --git a/xCATsn/xcat.conf b/xCATsn/xcat.conf index c205a24f9..476d3c50b 100644 --- a/xCATsn/xcat.conf +++ b/xCATsn/xcat.conf @@ -2,7 +2,7 @@ # This configuration file allows a diskfull install to access the install images # via http. It also allows the xCAT documentation to be accessed via # http://localhost/xcat-doc/ -# Updates to xCAT/xcat.conf should also be made to xCATsn/xcat.conf +# Service-node copies are generated from the matching configuration under xCAT/. # ServerTokens Prod diff --git a/xCATsn/xcat.conf.apach24 b/xCATsn/xcat.conf.apach24 index 251111903..3dfa318a0 100644 --- a/xCATsn/xcat.conf.apach24 +++ b/xCATsn/xcat.conf.apach24 @@ -2,7 +2,7 @@ # This configuration file allows a diskfull install to access the install images # via http. It also allows the xCAT documentation to be accessed via # http://localhost/xcat-doc/ -# Updates to xCAT/xcat.conf should also be made to xCATsn/xcat.conf +# Service-node copies are generated from the matching configuration under xCAT/. # ServerTokens Prod @@ -48,4 +48,3 @@ Alias /xcat-doc "/opt/xcat/share/doc" AllowOverride None Require all granted -