summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mergemaster
diff options
context:
space:
mode:
authordougb <dougb@FreeBSD.org>2009-12-12 02:19:41 +0000
committerdougb <dougb@FreeBSD.org>2009-12-12 02:19:41 +0000
commit4d14c7056213aa60d3ff6d841c0e645f0c7df388 (patch)
treea217f7733705420b7d1eade738e6a03c8a73acf8 /usr.sbin/mergemaster
parent26de328278d4a8cb7491ca3495b2706220b88c2f (diff)
downloadFreeBSD-src-4d14c7056213aa60d3ff6d841c0e645f0c7df388.zip
FreeBSD-src-4d14c7056213aa60d3ff6d841c0e645f0c7df388.tar.gz
Over time things that used to be files/directories/links can change
to something else. So add code to detect when things don't match and give the user choices about how to fix it. If we're using -P and something in the above check needs to be moved we need to have the directory there for it, so create it at the beginning and delete empty versions of it at the end. The case where something used to be a file or link and now is supposed to be a directory (e.g., /etc/security) is especially dangerous, so make failure to install a necessary directory in $DESTDIR a fatal error.
Diffstat (limited to 'usr.sbin/mergemaster')
-rwxr-xr-xusr.sbin/mergemaster/mergemaster.sh61
1 files changed, 59 insertions, 2 deletions
diff --git a/usr.sbin/mergemaster/mergemaster.sh b/usr.sbin/mergemaster/mergemaster.sh
index 646f7ff..7f7df5c 100755
--- a/usr.sbin/mergemaster/mergemaster.sh
+++ b/usr.sbin/mergemaster/mergemaster.sh
@@ -345,6 +345,7 @@ done
# Don't force the user to set this in the mergemaster rc file
if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
+ mkdir -p ${PRESERVE_FILES_DIR}
fi
# Check for the mtree database in DESTDIR
@@ -819,7 +820,8 @@ mm_install () {
if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
- install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
+ install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
+ install_error $1 ${DESTDIR}${INSTALL_DIR}
fi
FILE_MODE=`find_mode "${1}"`
@@ -968,6 +970,57 @@ if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
. "${MM_PRE_COMPARE_SCRIPT}"
fi
+# Things that were files/directories/links in one version can sometimes
+# change to something else in a newer version. So we need to explicitly
+# test for this, and warn the user if what we find does not match.
+#
+for COMPFILE in `find .` ; do
+ if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
+ INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
+ else
+ continue
+ fi
+ TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
+
+ if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
+ [ "$COMPFILE" = '.' ] && continue
+ TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
+ INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
+
+ echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
+ echo " but the new version has the type \"$TEMPROOT_TYPE\""
+ echo ''
+ echo " How would you like to handle this?"
+ echo ''
+ echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
+ case "$TEMPROOT_TYPE" in
+ 'symbolic link')
+ TARGET=`readlink $COMPFILE`
+ echo " and create a link to $TARGET in its place" ;;
+ *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
+ esac
+ echo ''
+ echo " Use 'i' to ignore this"
+ echo ''
+ echo -n " How to proceed? [i] "
+ read ANSWER
+ case "$ANSWER" in
+ [rR]) case "${PRESERVE_FILES}" in
+ [Yy][Ee][Ss])
+ mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
+ *) rm -rf ${DESTDIR}${COMPFILE#.} ;;
+ esac
+ case "$TEMPROOT_TYPE" in
+ 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
+ esac ;;
+ *) echo ''
+ echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
+ press_to_continue ;;
+ esac
+ echo ''
+ fi
+done
+
for COMPFILE in `find . -type f`; do
# First, check to see if the file exists in DESTDIR. If not, the
@@ -1269,5 +1322,9 @@ case "${PRE_WORLD}" in
;;
esac
-exit 0
+if [ -n "${PRESERVE_FILES}" ]; then
+ find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
+ rmdir $PRESERVE_FILES_DIR 2>/dev/null
+fi
+exit 0
OpenPOWER on IntegriCloud