From dd72a6b0ba625fd633bf517fe0d6e2a3ae3ab9d9 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 13 Mar 2025 23:24:59 +0000 Subject: [PATCH] Resolve "Temp directory not created for toys" --- atom | 158 +-------------------------------------- lib/tools/sanityChecks | 164 +++++++++++++++++++++++++++++++++++++++++ toys/checkextensions | 1 + toys/checkgenre | 2 +- toys/checkmissing | 2 +- toys/cleandestinations | 2 +- toys/createindex | 2 +- toys/lowquality | 2 +- toys/missingtags | 2 +- 9 files changed, 172 insertions(+), 163 deletions(-) create mode 100644 lib/tools/sanityChecks diff --git a/atom b/atom index de9b69a..cc401a7 100755 --- a/atom +++ b/atom @@ -183,163 +183,7 @@ set +H (( cfgdump )) && exit # check sanity -if [ ! -d "$tempdir" ] && ! mkdir -p "$tempdir" -then - echo "[FATAL] Could not create temp directory $tempdir" >&2 - (( sanityfail++ )) -fi -if [ ! -f "$database" ] && [ ! -d "${database%/*}" ] && ! mkdir -p "${database%/*}" -then - echo "[FATAL] Directory holding database file does not exist and could" \ - "not be created" >&2 - (( sanityfail++ )) -fi -if [ ! -d "$sourcepath" ] -then - echo "[FATAL] Source path $sourcepath does not exist or is not a directory" >&2 - (( sanityfail++ )) -fi -if ! which sed >/dev/null -then - echo "[FATAL] Required tool sed is not installed or not in PATH - I never thought this would actually hit someone..." >&2 - (( sanityfail++ )) -fi -if ! which sox >/dev/null -then - echo "[FATAL] Required tool sox is not installed or not in PATH" >&2 - (( sanityfail++ )) -fi -if ! which ogginfo >/dev/null -then - echo "[WARNING] Tool ogginfo (from vorbis-tools) is not" \ - "installed or not in PATH - WebM metadata disabled" >&2 - disableogginfo=1 - (( sanitywarn++ )) -fi -if ! which soxi >/dev/null -then - echo "[WARNING] Tool soxi (from sox) is not" \ - "installed or not in PATH - Vorbis metadata disabled" >&2 - disablesoxi=1 - (( sanitywarn++ )) -fi -if (( oggencneeded )) && ! which oggenc >/dev/null -then - echo "[WARNING] Tool oggenc (from vorbis-tools) is not" \ - "installed or not in PATH - Vorbis targets disabled" >&2 - disableoggenc=1 - (( sanitywarn++ )) -fi -if ! which opusinfo >/dev/null -then - echo "[WARNING] Tool opusinfo (from opus-tools) is not" \ - "installed or not in PATH - Opus metadata disabled" >&2 - disableopusinfo=1 - (( sanitywarn++ )) -fi -if (( opusencneeded )) && ! which opusenc >/dev/null -then - echo "[WARNING] Tool opusenc (from opus-tools) is not" \ - "installed or not in PATH - Opus targets disabled" >&2 - disableopusenc=1 - (( sanitywarn++ )) -fi -if ! which opusdec >/dev/null -then - echo "[WARNING] Tool opusdec (from opus-tools) is not" \ - "installed or not in PATH - Opus support disabled" >&2 - disableopusdec=1 - (( sanitywarn++ )) -fi -if (( lameneeded )) && ! which lame >/dev/null -then - echo "[WARNING] Tool lame is not installed or not in PATH - MP3 targets disabled" >&2 - disablelame=1 - (( sanitywarn++ )) -fi -if ! which metaflac >/dev/null -then - echo "[WARNING] Tool metaflac (from FLAC) is not installed" \ - "or not in PATH - FLAC metadata disabled" >&2 - disableflac=1 - (( sanitywarn++ )) -fi -if ! which mpcdec >/dev/null -then - echo "[WARNING] Tool mpcdec (from Musepack) is not" \ - "installed or not in PATH - Musepack support disabled" >&2 - disablempcdec=1 - (( sanitywarn++ )) -fi -if ! which mkvextract >/dev/null -then - echo "[WARNING] Tool mkvextract (from MKVToolNix) is not" \ - "installed or not in PATH - WebM metadata disabled - WebM support disabled" >&2 - disablemkvextract=1 - (( sanitywarn++ )) -fi -if ! which ffprobe >/dev/null -then - echo "[WARNING] Tool ffprobe (from FFmpeg) is not installed or not in PATH - Video metadata disabled - MPEG metadata disabled - MusePack metadata disabled - Unknown format metadata disabled" >&2 - disableffprobe=1 - (( sanitywarn++ )) -fi -if ! which ffmpeg >/dev/null -then - echo "[WARNING] Tool ffmpeg is not installed or not in PATH - Video support disabled" >&2 - disablevideo=1 - (( sanitywarn++ )) -fi -if (( textunidecodeneeded )) && ! perl -MText::Unidecode -e 'exit;' 2>/dev/null -then - echo "[WARNING] Perl module Text::Unidecode is not available - Renaming to ASCII-only disabled" >&2 - unset destinationascii - destinationascii=0 - textunidecodeneeded=0 - (( sanitywarn++ )) -fi -if (( sanityfail )) -then - echo " -Sanity checks raised ${sanitywarn:-0} warnings, $sanityfail failures. Dying now." >&2 - exit $ESANITY -elif (( sanitywarn )) -then - echo " -Sanity checks raised $sanitywarn warnings... Hit Control-C to abort." >&2 - if ! (( cron )) - then - timeout=$(( sanitywarn * 10 )) - echo -n "Starting in $(printf %3i $timeout)" \ - $'seconds...\b\b\b\b\b\b\b\b\b\b\b' >&2 - while (( timeout )) - do - echo -n $'\b\b\b'"$(printf %3i $timeout)" >&2 - sleep 1 - (( timeout-- )) - done - echo -en "\r\033[K" - fi -fi - +sanityCheck openDatabase for destination in "${destinations[@]}" diff --git a/lib/tools/sanityChecks b/lib/tools/sanityChecks new file mode 100644 index 0000000..e0d089b --- /dev/null +++ b/lib/tools/sanityChecks @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +sanityCheck() { + if [ ! -d "$tempdir" ] && ! mkdir -p "$tempdir" + then + echo "[FATAL] Could not create temp directory $tempdir" >&2 + (( sanityfail++ )) + fi + if [ ! -f "$database" ] && [ ! -d "${database%/*}" ] \ + && ! mkdir -p "${database%/*}" + then + echo "[FATAL] Directory holding database file does not exist"\ + "and could not be created" >&2 + (( sanityfail++ )) + fi + if [ ! -d "$sourcepath" ] + then + echo "[FATAL] Source path $sourcepath does not exist or is"\ + "not a directory" >&2 + (( sanityfail++ )) + fi + if ! which sed >/dev/null + then + echo "[FATAL] Required tool sed is not installed or not in PATH + I never thought this would actually hit someone..." >&2 + (( sanityfail++ )) + fi + if ! which sox >/dev/null + then + echo "[FATAL] Required tool sox is not installed or not in"\ + "PATH" >&2 + (( sanityfail++ )) + fi + if ! which ogginfo >/dev/null + then + echo "[WARNING] Tool ogginfo (from vorbis-tools) is not"\ + "installed or not in PATH + WebM metadata disabled" >&2 + disableogginfo=1 + (( sanitywarn++ )) + fi + if ! which soxi >/dev/null + then + echo "[WARNING] Tool soxi (from sox) is not" \ + "installed or not in PATH + Vorbis metadata disabled" >&2 + disablesoxi=1 + (( sanitywarn++ )) + fi + if (( oggencneeded )) && ! which oggenc >/dev/null + then + echo "[WARNING] Tool oggenc (from vorbis-tools) is not" \ + "installed or not in PATH + Vorbis targets disabled" >&2 + disableoggenc=1 + (( sanitywarn++ )) + fi + if ! which opusinfo >/dev/null + then + echo "[WARNING] Tool opusinfo (from opus-tools) is not" \ + "installed or not in PATH + Opus metadata disabled" >&2 + disableopusinfo=1 + (( sanitywarn++ )) + fi + if (( opusencneeded )) && ! which opusenc >/dev/null + then + echo "[WARNING] Tool opusenc (from opus-tools) is not" \ + "installed or not in PATH + Opus targets disabled" >&2 + disableopusenc=1 + (( sanitywarn++ )) + fi + if ! which opusdec >/dev/null + then + echo "[WARNING] Tool opusdec (from opus-tools) is not" \ + "installed or not in PATH + Opus support disabled" >&2 + disableopusdec=1 + (( sanitywarn++ )) + fi + if (( lameneeded )) && ! which lame >/dev/null + then + echo "[WARNING] Tool lame is not installed or not in PATH + MP3 targets disabled" >&2 + disablelame=1 + (( sanitywarn++ )) + fi + if ! which metaflac >/dev/null + then + echo "[WARNING] Tool metaflac (from FLAC) is not installed"\ + "or not in PATH + FLAC metadata disabled" >&2 + disableflac=1 + (( sanitywarn++ )) + fi + if ! which mpcdec >/dev/null + then + echo "[WARNING] Tool mpcdec (from Musepack) is not" \ + "installed or not in PATH + Musepack support disabled" >&2 + disablempcdec=1 + (( sanitywarn++ )) + fi + if ! which mkvextract >/dev/null + then + echo "[WARNING] Tool mkvextract (from MKVToolNix) is not"\ + "installed or not in PATH + WebM metadata disabled + WebM support disabled" >&2 + disablemkvextract=1 + (( sanitywarn++ )) + fi + if ! which ffprobe >/dev/null + then + echo "[WARNING] Tool ffprobe (from FFmpeg) is not installed"\ + "or not in PATH + Video metadata disabled + MPEG metadata disabled + MusePack metadata disabled + Unknown format metadata disabled" >&2 + disableffprobe=1 + (( sanitywarn++ )) + fi + if ! which ffmpeg >/dev/null + then + echo "[WARNING] Tool ffmpeg is not installed or not in PATH + Video support disabled" >&2 + disablevideo=1 + (( sanitywarn++ )) + fi + if (( textunidecodeneeded )) && ! perl -MText::Unidecode -e 'exit;' 2>/dev/null + then + echo "[WARNING] Perl module Text::Unidecode is not available + Renaming to ASCII-only disabled" >&2 + unset destinationascii + destinationascii=0 + textunidecodeneeded=0 + (( sanitywarn++ )) + fi + if (( sanityfail )) + then + echo " +Sanity checks raised ${sanitywarn:-0} warnings, $sanityfail failures. Dying now." >&2 + exit $ESANITY + elif (( sanitywarn )) + then + echo " +Sanity checks raised $sanitywarn warnings... Hit Control-C to abort." >&2 + if ! (( cron )) + then + timeout=$(( sanitywarn * 10 )) + echo -n "Starting in $(printf %3i $timeout)" \ + $'seconds...\b\b\b\b\b\b\b\b\b\b\b' >&2 + while (( timeout )) + do + echo -n $'\b\b\b'"$(printf %3i $timeout)" >&2 + sleep 1 + (( timeout-- )) + done + echo -en "\r\033[K" + fi + fi +} \ No newline at end of file diff --git a/toys/checkextensions b/toys/checkextensions index 6d69a12..1abdd78 100755 --- a/toys/checkextensions +++ b/toys/checkextensions @@ -62,6 +62,7 @@ done getConfig +sanityCheck openDatabase (( update )) && getFiles diff --git a/toys/checkgenre b/toys/checkgenre index 2cf7977..d3b4f85 100755 --- a/toys/checkgenre +++ b/toys/checkgenre @@ -58,7 +58,7 @@ do done getConfig - +sanityCheck openDatabase sourcepath='' diff --git a/toys/checkmissing b/toys/checkmissing index 14a35e9..eabef5f 100755 --- a/toys/checkmissing +++ b/toys/checkmissing @@ -59,7 +59,7 @@ do done getConfig - +sanityCheck openDatabase echo 'SELECT id,filename FROM destination_files WHERE filename IS NOT NULL;' >&3 diff --git a/toys/cleandestinations b/toys/cleandestinations index 5bdf8a6..dc49966 100755 --- a/toys/cleandestinations +++ b/toys/cleandestinations @@ -59,7 +59,7 @@ do done getConfig - +sanityCheck openDatabase checkwanted() { diff --git a/toys/createindex b/toys/createindex index 3f9a3d5..3959755 100755 --- a/toys/createindex +++ b/toys/createindex @@ -139,7 +139,7 @@ done } getConfig - +sanityCheck openDatabase columns="${show[@]//*/-}" diff --git a/toys/lowquality b/toys/lowquality index c3cfa8f..5bc291c 100755 --- a/toys/lowquality +++ b/toys/lowquality @@ -75,7 +75,7 @@ do done getConfig - +sanityCheck openDatabase if (( update )) diff --git a/toys/missingtags b/toys/missingtags index a1999cc..9baa389 100755 --- a/toys/missingtags +++ b/toys/missingtags @@ -94,7 +94,7 @@ done } getConfig - +sanityCheck openDatabase if (( update ))