nix-configs

Personal NixOS and home-manager configuration files
Log | Files | Refs

commit b9cf77ce9875d971f568caf8dad05f74a131e94f
parent 8f421ba5146ad2c09bba568d05a990b4d45b86bf
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Wed,  8 Apr 2026 18:28:22 +0100

Only run script if source has changed since last run

Diffstat:
Mscripts/tank-sort.nix | 24+++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/scripts/tank-sort.nix b/scripts/tank-sort.nix @@ -9,6 +9,8 @@ let # variables temp_mount="$(mktemp -d)" rclone_remote="seedbox:" + extensions="mp4,m4v,mkv" + state_file="/tmp/tank-sort.cache" destination_tvshows="/tank/media/videos/television" template_tvshows="{{ .Name }}/{{ .Name }} S{{ printf \"%02d\" .Season }}E{{ printf \"%02d\" .Episode }}{{ if ne .ExtraEpisode -1 }}-{{ printf \"%02d\" .ExtraEpisode }}{{end}}.{{ .Ext }}" destination_movies="/tank/media/videos/movies" @@ -26,6 +28,26 @@ let } trap cleanup EXIT + # check for changes on remote + current_hash="$(${pkgs.rclone}/bin/rclone lsjson "$rclone_remote" \ + --include "*.{''${extensions}}" \ + | ${pkgs.jq}/bin/jq -S '.[] | {Path, Size, ModTime}' \ + | sort \ + | sha256sum | cut -d' ' -f1)" + if [ -f "$state_file" ]; then + previous_hash="$(cat "$state_file")" + else + previous_hash="" + fi + + if [ "$current_hash" = "$previous_hash" ]; then + echo "No changes detected in remote. Exiting." + exit 0 + fi + + echo "Changes detected. Proceeding..." + echo "$current_hash" > "$state_file" + # mount remote echo "Mounting rclone remote..." if ! ${pkgs.rclone}/bin/rclone mount "$rclone_remote" "$temp_mount" \ @@ -62,7 +84,7 @@ let --movie-template "$template_movies" \ --recursive \ --overwrite-if-larger \ - --extensions "mp4,m4v,mkv" \ + --extensions "$extensions" \ "$temp_mount" echo "Media sort completed successfully"