aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-03-10 21:16:45 +0800
committerAaron LI <aly@aaronly.me>2018-03-10 21:16:45 +0800
commiteab95d09049bbd6a32e2db58649f749a674b1271 (patch)
tree7dfe67f351cdf1079cf276a693c8c2b3c76715d7
parent14dad9665b5f0d5c07ac83456bd2f71307923654 (diff)
downloaddfly-update-eab95d09049bbd6a32e2db58649f749a674b1271.tar.bz2
Add upgrade_system() to upgrade the config files
-rwxr-xr-xdfly-update44
1 files changed, 44 insertions, 0 deletions
diff --git a/dfly-update b/dfly-update
index 29f9b6e..5d75acf 100755
--- a/dfly-update
+++ b/dfly-update
@@ -456,6 +456,50 @@ install_system() {
echo " => DONE"
}
+# Upgrade the system with configurations
+upgrade_system() {
+ [ $# -eq 0 ] || \
+ error ${EC_ARGS} "upgrade_system: invalid arguments: $@"
+ local etcdir="${CACHE_DIR}/etc.new"
+ local file file_new
+ [ ! -d "${CACHE_DIR}" ] && mkdir -v "${CACHE_DIR}"
+ echo "Upgrading system ..."
+ echo " => Coping new /etc to: ${etcdir}"
+ cpdup -o -u ${MNT_DIR}/etc.hdd ${etcdir} || exit ${EC_CPDUP}
+
+ echo " => Removing ignored files ..."
+ for file in ${FILES_IGNORE}; do
+ file_new="${etcdir}/${file#/etc/}"
+ if [ -f "${file_new}" ]; then
+ echo -n " * ${file_new} "
+ rm -f "${file_new}"
+ echo "(ignored)"
+ fi
+ done
+ echo " => Renaming changed files while deleting others ..."
+ find /etc/ -type f | while read -r file; do
+ file_new="${etcdir}/${file#/etc/}"
+ if [ -f "${file_new}" ]; then
+ echo -n " * ${file_new} "
+ if cmp -s "${file}" "${file_new}"; then
+ rm -f "${file_new}"
+ echo "(same)"
+ else
+ mv "${file_new}" "${file_new}.${NEW_SUF}"
+ echo "[NEW]"
+ fi
+ fi
+ done
+
+ echo " => Coping new configurations over ..."
+ cpdup -o -u -I ${etcdir} /etc || exit ${EC_CPDUP}
+ echo " => DONE"
+ rm -rf "${etcdir}"
+ echo "+---------+"
+ echo "| WARNING | Files with '${NEW_SUF}' suffix need manual merge!"
+ echo "+---------+"
+}
+
}