From a0ce3925a84c97d1f0c7983aeaed2fbdf557cfed Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 29 May 2013 01:47:01 +0200 Subject: [PATCH] Sanity checks --- README | 1 + atom | 136 +++++++++++++++++++++++++++++++- lib/config/getConfigDestination | 3 + lib/database/openDatabase | 11 --- lib/decode/decodeFile | 3 + lib/tags/getTags | 7 +- 6 files changed, 147 insertions(+), 14 deletions(-) diff --git a/README b/README index b87cabe..be1e3e4 100644 --- a/README +++ b/README @@ -25,6 +25,7 @@ Optional: http://opus-codec.org/ * opusinfo (Opus metadata) * opusenc (Opus encoding) + * opusdec (Opus decoding) * LAME MP3 Encoder http://lame.sourceforge.net/ * lame (MP3 encoding) diff --git a/atom b/atom index a3f86b7..ed283b9 100755 --- a/atom +++ b/atom @@ -96,8 +96,6 @@ do esac done -#FIXME: check sanity - if [ ! -f "$cffile" ] then if [ ! -d ~/.atom ] @@ -120,6 +118,135 @@ set +H (( debug || cfgdump )) && printConfig (( 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 + Vorbis metadata disabled" >&2 + disableogginfo=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 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 (( 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 + 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 + openDatabase createDestinations @@ -312,6 +439,11 @@ do rest=${rest#*::AtOM:SQL:Sep::} performer=${rest%%::AtOM:SQL:Sep::*} unset rest + case ${destinationformat["$destination"]} in + vorbis) (( disableoggenc )) && continue ;; + opus) (( disableopusenc )) && continue ;; + mp3) (( disablelame )) && continue ;; + esac decodeFile getDestDir getDestFile diff --git a/lib/config/getConfigDestination b/lib/config/getConfigDestination index a6fa6a8..8fa63c6 100644 --- a/lib/config/getConfigDestination +++ b/lib/config/getConfigDestination @@ -8,12 +8,15 @@ getConfigDestination() { case "$value" in 'mp3') destinationformat["$destination"]=mp3 + lameneeded=1 ;; 'opus') destinationformat["$destination"]=opus + opusencneeded=1 ;; 'vorbis') destinationformat["$destination"]=vorbis + oggencneeded=1 ;; *) echo "Unsupported destination format: $value" >2& diff --git a/lib/database/openDatabase b/lib/database/openDatabase index b75cef4..ff829fe 100644 --- a/lib/database/openDatabase +++ b/lib/database/openDatabase @@ -1,18 +1,7 @@ #!/bin/bash openDatabase() { - if [ ! -d "$tempdir" ] - then - mkdir -p "$tempdir" - fi rm -f "$tempdir"/sqlite.{in,out} mkfifo "$tempdir"/sqlite.{in,out} - if [ ! -f "$database" ] - then - if [ ! -d "${database%/*}" ] - then - mkdir -p "${database%/*}" - fi - fi sqlite3 -bail "$database" \ < "$tempdir/sqlite.in" \ > "$tempdir/sqlite.out" & diff --git a/lib/decode/decodeFile b/lib/decode/decodeFile index 09c2dc3..1571222 100644 --- a/lib/decode/decodeFile +++ b/lib/decode/decodeFile @@ -2,6 +2,7 @@ decodeFile() { case "$mimetype" in 'video/'*) + (( disablevideo )) && continue extractAudio if (( ${destinationnormalize["$destination"]}))\ || ( @@ -30,6 +31,7 @@ decodeFile() { then copied=1 else + (( disableopusdec )) && continue decodeOpusdec if (( ${destinationnormalize["$destination"]}))\ || ( @@ -60,6 +62,7 @@ decodeFile() { extendedtype=$(file -b "$sourcepath/$filename") case "$extendedtype" in *'Musepack '*) + (( disablempcdec )) && continue decodeMpcdec if (( ${destinationnormalize["$destination"]}))\ || ( diff --git a/lib/tags/getTags b/lib/tags/getTags index 3f6d9e1..ecd996c 100644 --- a/lib/tags/getTags +++ b/lib/tags/getTags @@ -1,26 +1,31 @@ #!/bin/bash getTags_version='unknown-4' -tagreaders+=( "$getTags_version" ) getTags() { unset type case "$mimetype" in audio/mpeg) type=ffmpeg + (( disableffprobe )) && unset type ;; 'application/ogg opus') type=Opus + (( disableopusinfo )) && unset type ;; application/ogg*) type=Ogg + (( disableogginfo )) && unset type ;; audio/x-flac) type=FLAC + (( disableflac )) && unset type ;; video/*) type=ffmpeg + (( disableffprobe )) && unset type ;; *) type=ffmpeg + (( disableffprobe )) && unset type ;; esac if [ -n "$type" ]