Changed behavior of how binary packaging installs config files.

The pre/post install scripts for RPMs should not perform any logic
to backup config files, instead relying on the standard logic
that RPMs normally do.

For Mac packages, when an existing config file differs from the package's
version, the previous version is always kept and an alert is displayed to
the user explaining the situation.
This commit is contained in:
Jon Siwek 2011-01-19 16:56:30 -06:00
parent 1d8ad8e946
commit 5247a64eaa
5 changed files with 40 additions and 24 deletions

@ -1 +1 @@
Subproject commit c2769d9cd826ecaa08431d6af329db75a7d43583
Subproject commit ab273570c22b04f977877a2eb707c982319fd9c7

@ -1 +1 @@
Subproject commit 13986eb50729f45834eb050be4a6233c83f9295d
Subproject commit 1fe790706fcf3d9338b8fb073956c02a55686bb0

View file

@ -140,14 +140,12 @@ macro(SetPackageMetadata)
set(CPACK_RPM_PACKAGE_LICENSE "BSD")
endmacro(SetPackageMetadata)
# Sets pre and post install scripts for PackageMaker and RPM packages.
# Sets pre and post install scripts for PackageMaker 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)
# Note that RPMs already have a robust mechanism for dealing with
# user-modified files, so we do not need this additional functionality
macro(SetPackageInstallScripts VERSION)
if (INSTALLED_CONFIG_FILES)
# Remove duplicates from the list of installed config files
@ -160,6 +158,14 @@ macro(SetPackageInstallScripts)
set(INSTALLED_CONFIG_FILES "${_tmp}" CACHE STRING "" FORCE)
endif ()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Leaving the set of installed config files empty will just
# bypass the logic in the pre/post install scripts and let
# the RPM do their own thing (regarding backups, etc.)
# when upgrading packages.
set (INSTALLED_CONFIG_FILES "")
endif ()
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in
@ -189,7 +195,7 @@ macro(ConfigurePackaging _version)
SetPackageGenerators()
SetPackageFileName(${_version})
SetPackageMetadata()
SetPackageInstallScripts()
SetPackageInstallScripts(${_version})
set(CPACK_SET_DESTDIR true)
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

View file

@ -15,10 +15,6 @@ destination as the one that contains the root filesystem.
If you have existing configuration files that are modified or
otherwise different from the version included in the package,
this installer will attempt to prevent clobbering them by
backing them up like:
@CMAKE_INSTALL_PREFIX@/etc/<file>.<nextAvailableNumber>
this installer will attempt to prevent overwirting them,
but its also advisable to make your own backups of important
files before proceeding.

View file

@ -3,8 +3,9 @@
# 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
version=@VERSION@
newFiles=""
# check whether it's safe to remove backup configuration files that
# the most recent package install created
@ -13,22 +14,25 @@ if [ -e ${backupNamesFile} ]; then
backupFileList=`cat ${backupNamesFile}`
for backupFile in ${backupFileList}; do
origFile=`echo ${backupFile} | sed 's/\(.*\)\..*/\1/'`
origFileName=`echo ${backupFile} | sed 's/\(.*\)\..*/\1/'`
diff ${origFile} ${backupFile} > /dev/null 2>&1
diff ${origFileName} ${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}
# The backup file differs from the newly installed version,
# since we can't tell if the backup version has been modified
# by the user, we should restore it to its original location
# and rename the new version appropriately.
newFileName=${origFileName}.${version}
newFiles="${newFiles}\n${newFileName}"
mv ${origFileName} ${newFileName}
mv ${backupFile} ${origFileName}
fi
done
@ -36,6 +40,16 @@ if [ -e ${backupNamesFile} ]; then
rm ${backupNamesFile}
fi
if [ -n "${newFiles}" ]; then
# Use some apple script to display a message to user
/usr/bin/osascript << EOF
tell application "System Events"
activate
display alert "Existing configuration files differ from the ones that would be installed by this package. To avoid overwriting configuration which you may have modified, the following new config files have been installed:\n${newFiles}\n\nIf you have previously modified configuration files, please make sure that they are still compatible, else you should update your config files to the new versions."
end tell
EOF
fi
# make sure that world-writeable dirs have the sticky bit set
# so that unprivileged can't rename/remove files within