From 0ebe04baf7e619e09d00cd097311394cfa5bb48e Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 10 Mar 2018 21:17:56 +0800 Subject: Implement cleanup command to remove obsolete files, umount and delete image --- dfly-update | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/dfly-update b/dfly-update index 6177aa2..088c706 100755 --- a/dfly-update +++ b/dfly-update @@ -500,6 +500,43 @@ upgrade_system() { echo "+---------+" } +# Clean up obsolete and deprecated files +cleanup() { + [ $# -eq 0 ] || \ + error ${EC_ARGS} "cleanup: invalid arguments: $@" + local mk_upgrade=/etc/upgrade/Makefile_upgrade.inc + local tmpfile=$(mktemp -t ${NAME}) || exit ${EC_TMPFILE} + local item + echo "Removing obsolete and deprecated files ..." + make -f ${mk_upgrade} -V TO_REMOVE | tr ' ' '\n' > ${tmpfile} + make -f ${mk_upgrade} -V TO_REMOVE_LATE | tr ' ' '\n' >> ${tmpfile} + + # Credit: https://stackoverflow.com/a/10929511 + while IFS='' read -r item || [ -n "${item}" ]; do + if [ -e ${item} -o -L ${item} ]; then + echo " * ${item}" + chflags -Rf noschg ${item} + rm -rf ${item} + fi + done < ${tmpfile} + rm -f ${tmpfile} + echo " => DONE" +} + +# Post-upgrade checking and report: +# * check /etc for newly installed files that need manual merge +postupgrade() { + [ $# -eq 0 ] || \ + error ${EC_ARGS} "postupgrade: invalid arguments: $@" + echo "+=========================================================+" + echo "The following config files need manual merge:" + echo "+---------------------------------------------------------+" + find /etc -name "*.${NEW_SUF}" | sort + + echo "+=========================================================+" + echo "Upgrade the packages by:" + echo " # pkg upgrade -f" + echo "" } @@ -534,6 +571,8 @@ Usage: Back up the current kernel and world upgrade Install the new kernel, world, and config files + cleanup + Clean up obsolete files, umount and remove image file _EOF_ echo cmd_version @@ -629,6 +668,18 @@ cmd_upgrade() { upgrade_system } +# Clean up obsolete files, umount and remove image +cmd_cleanup() { + [ $# -eq 0 ] || \ + error ${EC_ARGS} "cmd_cleanup: invalid arguments: $@" + cleanup + local filepath=$(get_vn_filename ${MNT_DIR}) + umount_image ${MNT_DIR} + rm -f ${filepath} + echo "Removed image file: ${filepath}" + postupgrade +} + # # Main @@ -663,6 +714,10 @@ case "${COMMAND}" in shift cmd_upgrade ;; + cleanup) + shift + cmd_cleanup + ;; help|--help|-h|*) cmd_usage ;; -- cgit v1.2.2