AtOM/toys/cleandestinations

80 lines
1.4 KiB
Bash
Executable File

#!/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"
cffile="$HOME/.atom/atom.cfg"
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 -r 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