AtOM/toys/cleandestinations
2025-02-09 02:25:15 +00:00

88 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env 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=%DOCDIR% \
LIBDIR=%LIBDIR% \
SHAREDIR=%SHAREDIR%
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
if ! [[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/AtOM/atom.cfg" ]] \
&& [[ -f "$HOME/.atom/atom.cfg" ]]
then
echo "Configuration found in legacy location $HOME/.atom/atom.cfg."\
"Migrating configuration and data to XDG standard"
xdgMigrate
fi
cffile="${XDG_CONFIG_HOME:-$HOME/.config}/AtOM/atom.cfg"
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