AtOM/toys/checkmissing
2025-11-08 19:41:35 +01:00

112 lines
2.2 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 'Dr' opt
do
case $opt in
D) (( debug++ )) ;;
r) regen=1 ;;
esac
done
getConfig
sanityCheck
openDatabase
echo '
SELECT
destination_files.id,
destinations.name,
destination_files.filename
FROM destinations
INNER JOIN destination_files
ON destinations.id=destination_files.destination_id
WHERE filename IS NOT NULL;' >&3
echo 'SELECT "AtOM:NoMoreFiles";' >&3
declare -a \
destination_names \
files
read -u4 line
until [[ $line == AtOM:NoMoreFiles ]]
do
id=${line%%::AtOM:SQL:Sep::*}
rest=${line#*::AtOM:SQL:Sep::}
destination_names[id]=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
files[id]=${rest}
read -u4 line
done
echo 'BEGIN TRANSACTION;' >&3
echo -n "Checking for missing files... "
for index in "${!files[@]}"
do
destination=${destination_names[index]}
filename="${destinationpath[$destination]}/${files[index]}"
if ! [ -f "$filename" ]
then
echo -e "\r$filename\033[K"
((regen))&&Update destination_files last_change 0 <<<"id = $index"
echo -n "Checking for missing files... "
(( missing++ ))
fi
progressSpin
done
echo 'COMMIT;' >&3
echo -e "\r${missing:-No} missing files\033[K"
closeDatabase