diff --git a/.gitignore b/.gitignore index 92e2d4b56..20bc565ca 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ revision *.html ci/cache ci/packages +# Generated from *.in by build-scripts/package +packaging/common/script-templates/*-script-common.sh diff --git a/build-scripts/package b/build-scripts/package index 439121b14..5c7574d90 100755 --- a/build-scripts/package +++ b/build-scripts/package @@ -118,19 +118,16 @@ P="$BASEDIR/buildscripts/packaging/$PKG" if [ "$BUILDPREFIX" != /var/cfengine ]; then log_debug "Custom prefix detected: $BUILDPREFIX" safe_prefix="$(echo "$BUILDPREFIX" | sed -e 's:/::g')" - source_script="$P/../common/script-templates/$PACKAGING-script-common.sh" - patched_script="$P/../common/script-templates/patched-$PACKAGING-script-common.sh" - if [ -f "$source_script" ]; then - # Patch installation scripts for custom prefix, create patched-$PACKAGING-script-common.sh which is not version tracked - log_debug "Patching from source: $source_script to patched script: $patched_script" - sed "s:/var/cfengine:$BUILDPREFIX:" "$source_script" >"$patched_script" - else - log_error "Source $PACKAGING-script-common.sh not available at $source_script" - fi else log_debug "Using default prefix: /var/cfengine" fi +# Generate the install script snippets for the build prefix +for template in "$P"/../common/script-templates/*.in; do + log_debug "Generating ${template%.in} from $template" + sed "s:@BUILD_PREFIX@:$BUILDPREFIX:g" "$template" >"${template%.in}" +done + # Parse version string to separate main version from supplementary version # Format: MAIN_VERSION~SUPP_VERSION (e.g., 3.27.0~build1) log_debug "Parsing version string: $VERSION" diff --git a/packaging/common/produce-script b/packaging/common/produce-script index 3609e5495..f8573109c 100755 --- a/packaging/common/produce-script +++ b/packaging/common/produce-script @@ -6,16 +6,16 @@ # type = # action = # -# script-header.sh -# patched--script-common.sh -# note: patched- prefix files are not to be committed to the repository and are generated by build-scripts/package script +# script-header.sh (required) +# -script-common.sh (required) +# note: generated from -script-common.sh.in by build-scripts/package # -script-common-.sh -# script-common.sh +# script-common.sh (required) # script-common-.sh -# script-common-header-last.sh +# script-common-header-last.sh (required) # ../cfengine-PROJECT[-hub]/.sh # -# Any script that is missing will simply be skipped. +# A missing required script is an error. Any other missing script is skipped. if [ $# -ne 3 ]; then echo "Usage: $0 cfengine-PROJECT[-hub] pkg-type" @@ -35,8 +35,18 @@ include_script() fi } -include_script "$TEMPLATEDIR/script-header.sh" -include_script "$TEMPLATEDIR/patched-$PKG_TYPE-script-common.sh" +# Like include_script, but fails if the file is missing +require_script() +{ + if [ ! -f "$1" ]; then + echo "$0: error: required script $1 not found" >&2 + exit 1 + fi + cat "$1" +} + +require_script "$TEMPLATEDIR/script-header.sh" +require_script "$TEMPLATEDIR/$PKG_TYPE-script-common.sh" case "$PKG_TYPE" in deb|rpm) @@ -52,26 +62,27 @@ BUILT_ON_OS_VERSION="`expr "$OS_VERSION" : "\([0-9]*\)"`" echo "BUILT_ON_OS_VERSION=$BUILT_ON_OS_VERSION" # Shipped LMDB version, compared against the installed one by -# lmdb_migration_needed() (CFE-4701). -LMDB_VERSION="`sed -e 's,/*$,,' -e 's,.*/LMDB_,,' "$SCRIPTDIR/../../deps-packaging/lmdb/source" 2>/dev/null`" +# lmdb_migration_needed() (CFE-4701). The source file lists one mirror URL per +# line, so the version is taken from the first. +LMDB_VERSION="$(sed -n -e 's,/$,,' -e 's,.*/LMDB_,,' -e '1p' "$SCRIPTDIR/../../deps-packaging/lmdb/source" 2>/dev/null)" echo "LMDB_VERSION=$LMDB_VERSION" case "$SCRIPT_TYPE" in *install) include_script "$TEMPLATEDIR/$PKG_TYPE-script-common-install.sh" - include_script "$TEMPLATEDIR/script-common.sh" + require_script "$TEMPLATEDIR/script-common.sh" include_script "$TEMPLATEDIR/script-common-install.sh" include_script "$TEMPLATEDIR/script-common-$SCRIPT_TYPE.sh" ;; *remove) include_script "$TEMPLATEDIR/$PKG_TYPE-script-common-remove.sh" - include_script "$TEMPLATEDIR/script-common.sh" + require_script "$TEMPLATEDIR/script-common.sh" include_script "$TEMPLATEDIR/script-common-remove.sh" include_script "$TEMPLATEDIR/script-common-$SCRIPT_TYPE.sh" ;; esac -include_script "$TEMPLATEDIR/script-common-header-last.sh" +require_script "$TEMPLATEDIR/script-common-header-last.sh" # Not having a script is not an error. Not all scripts are used, # and not all projects are ported over. diff --git a/packaging/common/script-templates/bff-script-common.sh b/packaging/common/script-templates/bff-script-common.sh.in similarity index 90% rename from packaging/common/script-templates/bff-script-common.sh rename to packaging/common/script-templates/bff-script-common.sh.in index 6c326ceb7..d229c9c15 100644 --- a/packaging/common/script-templates/bff-script-common.sh +++ b/packaging/common/script-templates/bff-script-common.sh.in @@ -1,6 +1,6 @@ #!/usr/bin/ksh -PREFIX=/var/cfengine +PREFIX=@BUILD_PREFIX@ package_type() { diff --git a/packaging/common/script-templates/deb-script-common.sh b/packaging/common/script-templates/deb-script-common.sh.in similarity index 96% rename from packaging/common/script-templates/deb-script-common.sh rename to packaging/common/script-templates/deb-script-common.sh.in index e0075649e..52b1baee0 100644 --- a/packaging/common/script-templates/deb-script-common.sh +++ b/packaging/common/script-templates/deb-script-common.sh.in @@ -1,6 +1,6 @@ #!/bin/sh -PREFIX=/var/cfengine +PREFIX=@BUILD_PREFIX@ package_type() { diff --git a/packaging/common/script-templates/depot-script-common.sh b/packaging/common/script-templates/depot-script-common.sh.in similarity index 92% rename from packaging/common/script-templates/depot-script-common.sh rename to packaging/common/script-templates/depot-script-common.sh.in index aec58a9d4..7b9ea9310 100644 --- a/packaging/common/script-templates/depot-script-common.sh +++ b/packaging/common/script-templates/depot-script-common.sh.in @@ -1,6 +1,6 @@ #!/bin/sh -PREFIX=/var/cfengine +PREFIX=@BUILD_PREFIX@ package_type() { diff --git a/packaging/common/script-templates/macos-script-common.sh b/packaging/common/script-templates/macos-script-common.sh.in similarity index 98% rename from packaging/common/script-templates/macos-script-common.sh rename to packaging/common/script-templates/macos-script-common.sh.in index bef4fcb42..b51534d1a 100644 --- a/packaging/common/script-templates/macos-script-common.sh +++ b/packaging/common/script-templates/macos-script-common.sh.in @@ -8,7 +8,7 @@ # rpm/deb scriptlets -- upgrade detection has to be done by looking at what's # already on disk, same as HP-UX/AIX do. -PREFIX=/var/cfengine +PREFIX=@BUILD_PREFIX@ package_type() { diff --git a/packaging/common/script-templates/pkg-script-common.sh b/packaging/common/script-templates/pkg-script-common.sh.in similarity index 96% rename from packaging/common/script-templates/pkg-script-common.sh rename to packaging/common/script-templates/pkg-script-common.sh.in index 6cfda8f09..cb6df5a3e 100644 --- a/packaging/common/script-templates/pkg-script-common.sh +++ b/packaging/common/script-templates/pkg-script-common.sh.in @@ -21,7 +21,7 @@ if broken_posix_shell >/dev/null 2>&1; then exit 42 fi -PREFIX=/var/cfengine +PREFIX=@BUILD_PREFIX@ package_type() { diff --git a/packaging/common/script-templates/rpm-script-common.sh b/packaging/common/script-templates/rpm-script-common.sh.in similarity index 100% rename from packaging/common/script-templates/rpm-script-common.sh rename to packaging/common/script-templates/rpm-script-common.sh.in