#!/bin/bash # doc cmd_include { # # DESCRIPTION # cmd_include - Include track that matches CONDITION in DB_FILE # # USAGE # cmd_include <...> # # CONDITIONS # CONDITIONS are defined using the following format: # = # The metadata field can be anything that can be injected as metadata in a Vorbis or id3tag. # # } cmd_include() { local GIT_DIR="${1}" local TARGET="${2}" local DB_FILE="${TARGET}/${_OPT_DB_FILE}"; shift 2 local conditionList=("${@}") [[ ! -f "${DB_FILE}" ]] && return 3 [[ ! -d "${GIT_DIR}/.git" ]] && return 2 [[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2 for condition in ${conditionList[@]}; do _msg EXEC "Including all tracks that match the following condition: ${condition}" local MATCHES=$(db_set ${GIT_DIR} ${DB_FILE} true "${condition}" | wc -l) _msg ECHO "${MATCHES} matches" [[ $? -ne 0 ]] && { _msg WARN 1; } || { _msg OK 1; } done local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++')) local DU="$(print_imageid_du ${GIT_DIR} ${imageidList[@]})" _msg ECHO "Current estimated disk usage: ${DU} bytes" }