diff options
author | Aaron LI <aly@aaronly.me> | 2018-03-10 21:17:56 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-03-10 21:17:56 +0800 |
commit | 0ebe04baf7e619e09d00cd097311394cfa5bb48e (patch) | |
tree | e1647eeb3b1ae8440c94f6f4b6393a5abddf83c8 | |
parent | 0939553e448bd3c0e737397c1ed8c41d0cdaba5b (diff) | |
download | dfly-update-0ebe04baf7e619e09d00cd097311394cfa5bb48e.tar.bz2 |
Implement cleanup command to remove obsolete files, umount and delete image
-rwxr-xr-x | dfly-update | 55 |
1 files changed, 55 insertions, 0 deletions
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 ;; |