Skip to content

Commit 7dee9b4

Browse files
committed
Refactored packaging script creating temporary patched scripts instead of changing committed scripts
Previously running the build with a custom BUILDPREFIX would cause files committed to the repository to be changed. Now they are copied to a patched- prefixed version. Ticket: ENT-9880 Changelog: none
1 parent d0fb013 commit 7dee9b4

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎build-scripts/package‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ P="$BASEDIR/buildscripts/packaging/$PKG"
118118
if [ "$BUILDPREFIX" != /var/cfengine ]; then
119119
log_debug "Custom prefix detected: $BUILDPREFIX"
120120
safe_prefix="$(echo "$BUILDPREFIX" | sed -e 's:/::g')"
121-
file_to_patch=$P/../common/script-templates/$PACKAGING-script-common.sh
122-
if [ -f "$file_to_patch" ]; then
123-
# Update installation scripts to use custom prefix
124-
log_debug "Patching script template: $file_to_patch"
125-
sed "s:/var/cfengine:$BUILDPREFIX:" "$file_to_patch" >"$file_to_patch".new
126-
mv "$file_to_patch".new "$file_to_patch"
121+
source_script=$P/../common/script-templates/$PACKAGING-script-common.sh
122+
patched_script=$P/../common/script-templates/patched-$PACKAGING-script-common.sh
123+
if [ -f "$source_script" ]; then
124+
# Patch installation scripts for custom prefix, create patched-$PACKAGING-script-common.sh which is not version tracked
125+
log_debug "Patching from source: $source_script to patched script: $patched_script"
126+
sed "s:/var/cfengine:$BUILDPREFIX:" "$source_script" >"$patched_script"
127+
else
128+
log_error "Source $PACKAGING-script-common.sh not available at $source_script"
127129
fi
128130
else
129131
log_debug "Using default prefix: /var/cfengine"

‎packaging/common/produce-script‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
# action = <install|remove>
88
#
99
# script-header.sh
10-
# <type>-script-common.sh
10+
# patched-<type>-script-common.sh
11+
# note: patched- prefix files are not to be committed to the repository and are generated by build-scripts/package script
1112
# <type>-script-common-<action>.sh
1213
# script-common.sh
1314
# script-common-<action>.sh
@@ -35,7 +36,7 @@ include_script()
3536
}
3637

3738
include_script "$TEMPLATEDIR/script-header.sh"
38-
include_script "$TEMPLATEDIR/$PKG_TYPE-script-common.sh"
39+
include_script "$TEMPLATEDIR/patched-$PKG_TYPE-script-common.sh"
3940

4041
case "$PKG_TYPE" in
4142
deb|rpm)
@@ -57,13 +58,13 @@ echo "LMDB_VERSION=$LMDB_VERSION"
5758

5859
case "$SCRIPT_TYPE" in
5960
*install)
60-
include_script "$TEMPLATEDIR/$PKG_TYPE-script-common-install.sh"
61+
include_script "$TEMPLATEDIR/patched-$PKG_TYPE-script-common-install.sh"
6162
include_script "$TEMPLATEDIR/script-common.sh"
6263
include_script "$TEMPLATEDIR/script-common-install.sh"
6364
include_script "$TEMPLATEDIR/script-common-$SCRIPT_TYPE.sh"
6465
;;
6566
*remove)
66-
include_script "$TEMPLATEDIR/$PKG_TYPE-script-common-remove.sh"
67+
include_script "$TEMPLATEDIR/patched-$PKG_TYPE-script-common-remove.sh"
6768
include_script "$TEMPLATEDIR/script-common.sh"
6869
include_script "$TEMPLATEDIR/script-common-remove.sh"
6970
include_script "$TEMPLATEDIR/script-common-$SCRIPT_TYPE.sh"

0 commit comments

Comments
 (0)