diff --git a/toys/README b/toys/README index e518275..9b7785b 100644 --- a/toys/README +++ b/toys/README @@ -6,3 +6,11 @@ Options: -u: update source directory -r: rename files -n: (with -r): show what would be done. + +cleandestinations +================= +Checks destinations for possibly unwanted files (e.g. files not created by +AtOM). + +Options: + -r: remove unwanted files. diff --git a/toys/cleandestinations b/toys/cleandestinations new file mode 100755 index 0000000..15605a8 --- /dev/null +++ b/toys/cleandestinations @@ -0,0 +1,78 @@ +#!/bin/bash + +# config structures +declare -A \ + destinationchannels \ + destinationfat32compat \ + destinationcopymime \ + destinationformat \ + destinationfrequency \ + destinationid \ + destinationloss \ + destinationmaxbps \ + destinationnormalize \ + destinationpath \ + destinationquality \ + destinationrename \ + destinationnoresample \ + destinationrenamepath \ + destinationskipmime \ +|| { + echo "Check your Bash version. You need >= 4.0" >&2 + exit $EBASHVERS +} + +declare -r \ + DOCDIR=./doc \ + LIBDIR=./lib \ + SHAREDIR=./share +declare -r \ + exampleconf=$DOCDIR/example.cfg \ + schema=$SHAREDIR/schema.sql \ + \ + oldIFS="$IFS" + +LC_ALL=C + +shopt -s extglob + +for function in "$LIBDIR"/*/* +do + source "$function" +done + +while getopts 'rD' opt +do + case $opt in + r) remove=1 ;; + D) (( debug++ )) ;; + esac +done + +getConfig + +openDatabase + +checkwanted() { + Select id <<<"filename = $1" +} + +for destination in "${!destinationpath[@]}" +do + echo -ne "\rScanning destination $destination... \033[K" + while read filename + do + if ! Select destination_files id \ + >/dev/null \ + <<<"filename = $filename" + then + echo -e $'\r'"$filename\033[K" + (( remove )) && rm -f "$filename" + echo -n "Scanning destination $destination... " + fi + progressSpin + done < <(find "${destinationpath["$destination"]}" -type f) +done +echo -en "\r\033[K" + +closeDatabase