[chk_deployed_ids] [chk_metadata] [chk_nonexistent_ids] Made interface prettier
This commit is contained in:
parent
6cae40f84d
commit
1fc797418e
3 changed files with 31 additions and 10 deletions
|
@ -14,19 +14,31 @@ chk_deployed_ids() {
|
|||
local TARGET="${1}"
|
||||
local DB_FILE="${2}"
|
||||
|
||||
for flac in $(find "${TARGET}" -name '*.flac' -not -path '*/\.*' -printf "%P\n"); do
|
||||
_msg ECHO "Checking ${flac}"
|
||||
local flacList=($(find "${TARGET}" -name '*.flac' -not -path '*/\.*' -printf "%P\n"))
|
||||
|
||||
local COUNT=0
|
||||
for flac in ${flacList[@]}; do
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
local ERR=false
|
||||
echo "[ ${COUNT} / ${#flacList[@]} ] Checking ${flac}"
|
||||
local metadataList=($(awk 'BEGIN{RS=";";FS="="}{print $2}' <<< $(print_meta_flac "${TARGET}/${flac}" IMAGEID TRACKID)))
|
||||
local IMAGEID=${metadataList[0]}
|
||||
local TRACKID=${metadataList[1]}
|
||||
|
||||
if [[ -z "${IMAGEID}" ]] || [[ -z "${TRACKID}" ]]; then echo "${flac} does not contain IMAGEID or TRACKID metadata" > ${STDERR}; local ERR=true; fi
|
||||
[[ "${ERR}" == "true" ]] && { cat ${STDERR}; continue; }
|
||||
|
||||
|
||||
if [[ -z "$(awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE})" ]]; then
|
||||
_msg ECHO "Fixing accounting for ${flac}"
|
||||
local ERR=true
|
||||
echo "Fixing accounting for ${flac}" > ${STDERR}
|
||||
echo -e "true\t${IMAGEID}\t${TRACKID}\t${flac}" >> ${DB_FILE}
|
||||
elif [[ "$(awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $4}}' ${DB_FILE})" != "${flac}" ]]; then
|
||||
_msg ECHO "Fixing path for ${flac}"
|
||||
awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){$4=path}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE}
|
||||
local ERR=true
|
||||
echo "Fixing path for ${flac}" > ${STDERR}
|
||||
gawk -i inplace -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){$4=path}{print $0}}' ${DB_FILE}
|
||||
fi
|
||||
[[ "${ERR}" == "true" ]] && cat ${STDERR} || { _ansi up 2; echo -en '\033[K'; }
|
||||
done
|
||||
|
||||
}
|
||||
|
|
|
@ -25,4 +25,5 @@ chk_metadata() {
|
|||
[[ $? -eq 0 ]] && { _ansi up 2; echo -en '\033[K'; } || { echo "[>>>>>>] Error reported"; cat ${STDERR}; local ERR=true; }
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
[[ "${ERR}" == "true" ]] && { _msg EXEC "Metadata check completed with errors"; _msg WARN; } || { _msg EXEC "Metadata check completed succesfully"; _msg OK; }
|
||||
}
|
||||
|
|
|
@ -14,17 +14,25 @@ chk_nonexistent_ids() {
|
|||
local TARGET="${1}"
|
||||
local DB_FILE="${2}"
|
||||
|
||||
for row in $(awk 'BEGIN{RS="\n";FS="\t";OFS="="}{print $2,$3,$4}' ${DB_FILE}); do
|
||||
local ERR=false
|
||||
local rowList=($(awk 'BEGIN{RS="\n";FS="\t";OFS="="}{print $2,$3,$4}' "${DB_FILE}"))
|
||||
|
||||
local COUNT=1
|
||||
for row in ${rowList[@]}; do
|
||||
local IMAGEID="$(cut -d"=" -f1 <<< ${row})"
|
||||
local TRACKID="$(cut -d"=" -f2 <<< ${row})"
|
||||
local FILE="$(cut -d"=" -f3 <<< ${row})"
|
||||
_msg ECHO "Checking track id ${TRACKID}"
|
||||
|
||||
|
||||
echo "[ ${COUNT} / ${#rowList[@]} ] Checking path of ${TRACKID}"
|
||||
|
||||
if [[ ! -f "${TARGET}/${FILE}" ]] && [[ ${FILE} != "null" ]]; then
|
||||
_msg ECHO "${TRACKID} points to non-existent file"
|
||||
sed -i "/${IMAGEID} ${TRACKID}/d" ${DB_FILE}
|
||||
gawk -i inplace -v imageid=${IMAGEID} trackid=${TRACKID} 'BEGIN{FS="\t";OFS="\t"}{if($2==imageid && $3==trackid){$4="null"}{print $0}}' ${DB_FILE}
|
||||
local $?=1
|
||||
fi
|
||||
[[ $? -eq 0 ]] && { _ansi up 2; echo -en '\033[K'; } || { echo "[>>>>>>] Error reported"; echo "${TRACKID} of ${IMAGEID} points to non-existent file"}; local ERR=true; }
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
[[ "${ERR}" == "true" ]] && { _msg EXEC "Nonexistent files check completed with errors"; _msg WARN; } || { _msg EXEC "Nonexistent files check completed succesfully"; _msg OK; }
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue