From 9e2f0a4676cc0f12e910509e2e1b0b4fff23fb17 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Fri, 12 Aug 2022 11:51:38 +0200 Subject: [PATCH] Styx: Improve macOS application copying --- home/hosts/Styx.nix | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/home/hosts/Styx.nix b/home/hosts/Styx.nix index 214e73f..4dab261 100644 --- a/home/hosts/Styx.nix +++ b/home/hosts/Styx.nix @@ -62,6 +62,7 @@ in tokei viddy wget + xxHash xz ]; }; @@ -81,15 +82,27 @@ in in lib.hm.dag.entryAfter [ "writeBoundary" ] '' baseDir="$HOME/Applications/Home Manager Apps" - if [ -d "$baseDir" ]; then - rm -f "''${baseDir}/.DS_Store" - rm -rf "$baseDir" - fi - mkdir -p "$baseDir" + $DRY_RUN_CMD mkdir -p "$baseDir" + for appFile in ${apps}/Applications/*; do + appFileChecksum="$(find "$appFile/Contents/MacOS" -type f -exec md5 -q {} \; | md5 -q)" target="$baseDir/$(basename "$appFile")" - $DRY_RUN_CMD cp ''${VERBOSE_ARG:+-v} -fHRL "$appFile" "$baseDir" - $DRY_RUN_CMD chmod ''${VERBOSE_ARG:+-v} -R +w "$target" + + if [ -d "$target" ]; then + targetChecksum="$(find "$target/Contents/MacOS" -type f -exec md5 -q {} \; | md5 -q)" + else + targetChecksum="0" + fi + + if [ "$appFileChecksum" = "$targetChecksum" ]; then + echo "Application not changed: $(basename "$appFile")" + else + echo -n "Coyping application $(basename "$appFile"): " + $DRY_RUN_CMD rm -rf "$target" + $DRY_RUN_CMD cp ''${VERBOSE_ARG:+-v} -fHRL "$appFile" "$baseDir" + $DRY_RUN_CMD chmod ''${VERBOSE_ARG:+-v} -R +w "$target" + echo 'Done' + fi done ''; }