Changes to CMake logic for binary packaging

- pre/post install scripts now track configuration files that may
  be clobbered on package install/upgrade through the
  INSTALLED_CONFIG_FILES CMake variable and attempts to make backups
  when the distribution's file differs from the existing file.
This commit is contained in:
Jon Siwek 2011-01-13 21:52:29 -06:00
parent 7936782057
commit 8d4f487add
10 changed files with 151 additions and 10 deletions

View file

@ -168,6 +168,11 @@ CheckOptionalBuildSources(aux/broccoli Broccoli INSTALL_BROCCOLI)
######################################################################## ########################################################################
## Packaging Setup ## Packaging Setup
if (INSTALL_BROCTL)
# CPack RPM Generator may not automatically detect this
set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.4.0")
endif ()
# If this CMake project is a sub-project of another, we will not # If this CMake project is a sub-project of another, we will not
# configure the generic packaging because CPack will fail in the case # configure the generic packaging because CPack will fail in the case
# that the parent project has already configured packaging # that the parent project has already configured packaging

@ -1 +1 @@
Subproject commit 4e1dad4ee69b85d04af72c0faaff47fddf3240e2 Subproject commit eca3047a90e11975df8c1d523c796fe45bc4ea4e

@ -1 +1 @@
Subproject commit 7b829fbe8d6fa36c33c0c07a8f09cc0d68cd17f1 Subproject commit 148ce0f3abdea5019fa1642d8108b09cc4c8d7a0

@ -1 +1 @@
Subproject commit 2bf6c82eed841d2a8e7104875717296fe50ca126 Subproject commit b1336188695fb900ac30c48164fea831c2aae2f4

@ -1 +1 @@
Subproject commit a05be1242b4e06dca1bb1a38ed871e7e2d78181b Subproject commit a6ebc3ee2fc986a62244e03a3d7c7162aa33838b

View file

@ -134,12 +134,54 @@ macro(SetPackageMetadata)
set(CPACK_RPM_PACKAGE_LICENSE "BSD") set(CPACK_RPM_PACKAGE_LICENSE "BSD")
endmacro(SetPackageMetadata) endmacro(SetPackageMetadata)
# Sets pre and post install scripts for PackageMaker and RPM packages.
# The main functionality that such scripts offer is a way to make backups
# of "configuration" files that a user may have modified.
# A better way to prevent an RPM from not overwriting config files is
# with the %config(noreplace) .spec attribute, but CPack does not have any
# good hooks into using that yet, so we re-use the pre/post install scripts
# See also: http://public.kitware.com/Bug/view.php?id=10294
macro(SetPackageInstallScripts)
# Remove duplicates from the list of installed config files
separate_arguments(INSTALLED_CONFIG_FILES)
list(REMOVE_DUPLICATES INSTALLED_CONFIG_FILES)
# Space delimit the list again
foreach (_file ${INSTALLED_CONFIG_FILES})
set(_tmp "${_tmp} ${_file}")
endforeach ()
set(INSTALLED_CONFIG_FILES "${_tmp}" CACHE STRING "" FORCE)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in
${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh
@ONLY)
set(CPACK_PREFLIGHT_SCRIPT
${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh)
endif ()
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in
${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh
@ONLY)
set(CPACK_POSTUPGRADE_SCRIPT
${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE
${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh)
endif ()
endmacro(SetPackageInstallScripts)
# Main macro to configure all the packaging options # Main macro to configure all the packaging options
macro(ConfigurePackaging _version) macro(ConfigurePackaging _version)
SetPackageVersion(${_version}) SetPackageVersion(${_version})
SetPackageGenerators() SetPackageGenerators()
SetPackageFileName(${_version}) SetPackageFileName(${_version})
SetPackageMetadata() SetPackageMetadata()
SetPackageInstallScripts()
set(CPACK_SET_DESTDIR true) set(CPACK_SET_DESTDIR true)
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

View file

@ -13,8 +13,12 @@ You may choose to update your PATH environment variable:
If you have more than one volume, please choose the install If you have more than one volume, please choose the install
destination as the one that contains the root filesystem. destination as the one that contains the root filesystem.
If you have an existing broccoli.conf file that is modified or If you have existing configuration files that are modified or
otherwise different from the version included in the package, it otherwise different from the version included in the package,
will be overwritten and a backup of the existing file placed in: this installer will attempt to prevent clobbering them by
backing them up like:
@CMAKE_INSTALL_PREFIX@/etc/broccoli.conf.<nextAvailableNumber> @CMAKE_INSTALL_PREFIX@/etc/<file>.<nextAvailableNumber>
but its also advisable to make your own backups of important
files before proceeding.

56
cmake/package_postupgrade.sh.in Executable file
View file

@ -0,0 +1,56 @@
#!/bin/sh
# This script is meant to be used by binary packages post-installation.
# Variables between @ symbols are replaced by CMake at configure time.
backupDesc="# Backup made by install of @CMAKE_PROJECT_NAME@ version @VERSION@"
backupNamesFile=/tmp/bro_install_backups
# check whether it's safe to remove backup configuration files that
# the most recent package install created
if [ -e ${backupNamesFile} ]; then
backupFileList=`cat ${backupNamesFile}`
for backupFile in ${backupFileList}; do
origFile=`echo ${backupFile} | sed 's/\(.*\)\..*/\1/'`
diff ${origFile} ${backupFile} > /dev/null 2>&1
if [ $? -eq 0 ]; then
# if the installed version and the backup version don't differ
# then we can remove the backup version
rm ${backupFile}
else
# keep the backup, prepend text explaining what created it
tmpfile=/tmp/bro_install_tmp$$
echo ${backupDesc} > ${tmpfile}
echo "" >> ${tmpfile}
cat ${backupFile} >> ${tmpfile}
cp ${tmpfile} ${backupFile}
rm ${tmpfile}
fi
done
rm ${backupNamesFile}
fi
# make sure that world-writeable dirs have the sticky bit set
# so that unprivileged can't rename/remove files within
if [ -d /var/opt/bro/spool ]; then
chmod +t /var/opt/bro/spool
fi
if [ -d /var/opt/bro/spool/tmp ]; then
chmod +t /var/opt/bro/spool/tmp
fi
if [ -d /var/opt/bro/spool/policy ]; then
chmod +t /var/opt/bro/spool/policy
fi
if [ -d /var/opt/bro/logs ]; then
chmod +t /var/opt/bro/logs
fi

34
cmake/package_preinstall.sh.in Executable file
View file

@ -0,0 +1,34 @@
#!/bin/sh
# This script is meant to be used by binary packages pre-installation.
# Variables between @ symbols are replaced by CMake at configure time.
configFiles="@INSTALLED_CONFIG_FILES@"
backupNamesFile=/tmp/bro_install_backups
# Checks if a config file exists in a default location and makes a backup
# so that a modified version is not clobbered
backupFile () {
origFile="$1"
if [ -e ${origFile} ]; then
# choose a file suffix that doesn't already exist
ver=1
while [ -e ${origFile}.${ver} ]; do
ver=$(( ver + 1 ))
done
backupFile=${origFile}.${ver}
cp ${origFile} ${backupFile}
# the post upgrade script will check whether the installed
# config file actually differs from existing version
# and delete unnecessary backups
echo "${backupFile}" >> ${backupNamesFile}
fi
}
for file in ${configFiles}; do
backupFile "${file}"
done

4
configure vendored
View file

@ -45,7 +45,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
--with-perftools=PATH path to Google Perftools install root --with-perftools=PATH path to Google Perftools install root
Packaging Options (for developers): Packaging Options (for developers):
--enable-package toggles special build logic for binary packaging --package toggles special build logic for binary packaging
--ignore-dirs=PATHS paths to ignore when creating source package --ignore-dirs=PATHS paths to ignore when creating source package
(semicolon delimited and quoted when multiple) (semicolon delimited and quoted when multiple)
--pkg-name-prefix=NAME use the given name as the package prefix instead --pkg-name-prefix=NAME use the given name as the package prefix instead
@ -165,7 +165,7 @@ while [ $# -ne 0 ]; do
--with-perftools=*) --with-perftools=*)
append_cache_entry GooglePerftools_ROOT_DIR PATH $optarg append_cache_entry GooglePerftools_ROOT_DIR PATH $optarg
;; ;;
--enable-package) --package)
append_cache_entry PACKAGING_MODE BOOL true append_cache_entry PACKAGING_MODE BOOL true
;; ;;
--ignore-dirs=*) --ignore-dirs=*)