From 6c54c80c53c817332773ac0f6f99e991b8f3419b Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 8 Jan 2019 16:39:34 +0800 Subject: Also use cpdup -X to ignore files when copying new /etc Add the new function make_cpignore() to generate the ignore file for cpdup(1), considering the substitution from '/etc' to '/etc.hdd'. Explicitly remove possible existing 'etc.new' directory left by the previous run. --- dfly-update | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/dfly-update b/dfly-update index 5eed602..c6cfc2d 100755 --- a/dfly-update +++ b/dfly-update @@ -200,6 +200,18 @@ backup_world() { exit ${EC_TAR} } +# Make the ignore file for cpdup(1) +make_cpignore() { + local cpignore=$(mktemp -t ${NAME}) || exit ${EC_TMPFILE} + local f f2 + for f in ${FILES_IGNORE}; do + f2=$(echo "${f}" | sed 's|^/etc/|/etc.hdd/|') + # NOTE: 'cpdup -X' doesn't normalize multiple '/' to be one. + echo "${MNT_DIR%/}/${f2#/}" >> ${cpignore} + done + echo ${cpignore} +} + # Install the new system (kernel and world, excluding /etc) install_system() { local file item path cpignore @@ -217,13 +229,8 @@ install_system() { exit ${EC_MTREE} done - echo " => Collecting files to be ignored ..." - cpignore=$(mktemp -t ${NAME}) || exit ${EC_TMPFILE} - for file in ${FILES_IGNORE}; do - # NOTE: 'cpdup -X' doesn't normalize multiple '/' to be one. - echo "${MNT_DIR%/}/${file#/}" >> ${cpignore} - echo " * ${file} " - done + echo " => Collecting ignored files for cpdup ..." + cpignore=$(make_cpignore) || exit ${EC_TMPFILE} echo " => Installing kernel and world ..." for item in ${INSTALL_LIST}; do @@ -287,22 +294,18 @@ add_users() { # Upgrade the system with new configuration files upgrade_system() { - local etcdir file file_etc file_new + local etcdir file file_etc file_new cpignore [ -d "${CACHE_DIR}" ] || mkdir "${CACHE_DIR}" etcdir="${CACHE_DIR}/etc.new" + rm -rf "${etcdir}" + echo " => Collecting ignored files for cpdup ..." + cpignore=$(make_cpignore) || exit ${EC_TMPFILE} echo " => Coping new /etc to: ${etcdir}" - ${CPDUP} -o ${MNT_DIR}/etc.hdd ${etcdir} || exit ${EC_CPDUP} - - echo " => Removing ignored files ..." - for file_etc in ${FILES_IGNORE}; do - file_new="${etcdir}/${file_etc#/etc/}" - if [ -f "${file_new}" ]; then - rm -f "${file_new}" - echo " * ${file_new} " - fi - done + ${CPDUP} -o -X ${cpignore} ${MNT_DIR%/}/etc.hdd ${etcdir} || + exit ${EC_CPDUP} + rm -f ${cpignore} echo " => Identifying new/updated config files ..." (cd "${etcdir}" && find -s . -type f) | while read -r file; do -- cgit v1.2.2