Deprecations in favour of changes in deployment workflow:
[is_selected] Deprecated (and exterminated) [deploy_imageid] Deprecated in favor of deploy_cp, deploy_rm and deploy_meta [deploy_trackid] Deprecated in favor of deploy_cp, deploy_rm and deploy_meta Misc changes and bugfixes for print functions [print_future_path] In the event that TITLE is not set, TITLE will now be ALBUM, for tracks without titles. [print_meta_flac] Track TITLES with colons are now kept [print_present_path] Now needs IMAGEID and TRACKID in argument for TRACKID wasn't unique enough [print_trackids_to_imageids] Prints the IMAGEIDs of all TRACKIDs New functions for new deployment workflow that allows for deletion first, copying later, and smarter metadata adjustments [deploy_rm] Removes all given TRACKIDs (i.e, what FILE_DB defines as false, but target_dir is not null) [deploy_cp] Function copies TRACKIDs on a IMAGEID by IMAGEID basis to TARGET [deploy_meta] Function applies metadata to IMAGEID tracks [cmd_deploy] Rewrote cmd_deploy for use of new deploy functions Bug fixes to db selections and db update [db_set] Now ignores all lines that have LAST_DEPLOY and LAST_UPDATE [db_update] Added function to report a file as removed from git dir. (null in selection column) [cmd_update] LAST_COMMIT is now LAST_UPDATE in favour of LAST_DEPLOY, which is for commit of when last deployment occured [cmd_update] Gawk is now used for inplace editing of database Misc. adjustements [cmd_deploy] Rewrote disk usage check
This commit is contained in:
parent
bff31996f2
commit
72aac8134f
14 changed files with 193 additions and 143 deletions
|
@ -6,32 +6,48 @@
|
||||||
# cmd_deploy - Command that deploys IMAGEIDs using deploy_imageid function
|
# cmd_deploy - Command that deploys IMAGEIDs using deploy_imageid function
|
||||||
#
|
#
|
||||||
# USAGE
|
# USAGE
|
||||||
# cmd_deploy - </path/to/git/dir> </path/to/target> <imageid_1> <imageid_2> <...>
|
# cmd_deploy - </path/to/git/dir> </path/to/target>
|
||||||
#
|
#
|
||||||
# }
|
# }
|
||||||
|
|
||||||
cmd_deploy() {
|
cmd_deploy() {
|
||||||
local GIT_DIR="${1}"
|
local GIT_DIR="${1}"
|
||||||
local TARGET="${2}"; shift 2
|
local TARGET="${2}"; shift 2
|
||||||
local imageidList=(${@})
|
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 1
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
|
||||||
[[ -z "${imageidList[@]}" ]] && local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
if [[ -z "$(grep LAST_DEPLOY ${DB_FILE})" ]]; then
|
||||||
|
echo -e "LAST_DEPLOY\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" >> ${DB_FILE}
|
||||||
|
fi
|
||||||
|
|
||||||
|
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
||||||
|
local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_DEPLOY"){print $2}}' ${DB_FILE})
|
||||||
|
local removableidList=($(awk 'BEGIN{FS="\t"}{if(($1=="false" && $1=="null") && $4!="null"){print $2"--"$3}}' "${DB_FILE}"))
|
||||||
|
local deployableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
|
||||||
|
local changedidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
||||||
|
local updateableidList=($(printf "%s\n" ${deployableidList[@]} ${changedidList[@]} | awk '!seen[$0]++'))
|
||||||
|
|
||||||
# Checks if target has enough space
|
# Checks if target has enough space
|
||||||
local deployableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
local futureidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
||||||
local removableidList=($(awk 'BEGIN{FS="\t"}{if($1=="false" && $4!="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
local presentidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4!="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
||||||
local DU="$(( $(print_imageid_du ${GIT_DIR} ${deployableidList[@]}) - $(print_imageid_du ${GIT_DIR} ${removableidList[@]}) ))"
|
local DU="$(( $(print_imageid_du ${GIT_DIR} ${futureidList[@]}) - $(print_imageid_du "${GIT_DIR}" ${presentidList[@]}) ))"
|
||||||
local DF="$(df ${TARGET} --output=avail | tail -n -1)"
|
local DF="$(df ${TARGET} --output=avail -B1 | tail -n -1)"
|
||||||
[[ ${DU} -ge ${DF} ]] && { _msg ECHO "Target does not have enough space for deployable IMAGEID. Need ${DU}, has ${DF}."; return 2; }
|
[[ ${DU} -ge ${DF} ]] && { _msg ECHO "Target does not have enough space for deployable IMAGEID. Need ${DU}, has ${DF}."; return 2; }
|
||||||
|
|
||||||
|
# Cleans target of removable TRACKID
|
||||||
for imageid in ${imageidList[@]}; do
|
for removableid in ${removableidList[@]}; do
|
||||||
_msg EXEC "Deploying ${imageid} to ${TARGET}"
|
deploy_rm "${TARGET}" "${DB_FILE}" ${removableid}
|
||||||
deploy_imageid ${GIT_DIR} ${TARGET} ${DB_FILE} ${imageid} >${STDERR} 2>&1
|
|
||||||
[[ $? -ne 0 ]] && { _msg WARN; local ERR=true; } || _msg OK
|
|
||||||
done
|
done
|
||||||
[[ ${ERR} ]] && return 2
|
|
||||||
}
|
for imageid in ${updateableidList[@]}; do
|
||||||
|
# Processes deployableids (IMAGEIDs that have TRACKIDs that are not present in target, but are selected)
|
||||||
|
if _if_array_contains ${imageid} ${deployableidList[@]}; then
|
||||||
|
deploy_cp "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Processed metadata changes
|
||||||
|
deploy_meta "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid}
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ ${ERR} ]] && return 1 || { gawk -i inplace -v newcommit=${NEW_COMMIT} 'BEGIN{FS="\t";OFS="\t"}{if($1=="LAST_DEPLOY"){$2=newcommit}{print $0}}' ${DB_FILE}; return 0; }
|
||||||
|
}
|
||||||
|
|
|
@ -17,18 +17,18 @@ cmd_update() {
|
||||||
|
|
||||||
# In the event that LAST_COMMIT OR DB_FILE does not exist, echo out that the LAST_COMMIT
|
# In the event that LAST_COMMIT OR DB_FILE does not exist, echo out that the LAST_COMMIT
|
||||||
# is the first COMMIT of GIT_DIR, thus stating that no database update has ever occured
|
# is the first COMMIT of GIT_DIR, thus stating that no database update has ever occured
|
||||||
if [[ -z "$(grep LAST_COMMIT ${DB_FILE})" ]]; then
|
if [[ -z "$(grep LAST_UPDATE ${DB_FILE})" ]]; then
|
||||||
echo -e "LAST_COMMIT\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" >> ${DB_FILE}
|
echo -e "LAST_UPDATE\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" >> ${DB_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Defines what imageids needs updating by determining what files has changed since last
|
# Defines what imageids needs updating by determining what files has changed since last
|
||||||
# update via git diff --name-only.
|
# update via git diff --name-only.
|
||||||
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
||||||
local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_COMMIT"){print $2}}' ${DB_FILE})
|
local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_UPDATE"){print $2}}' ${DB_FILE})
|
||||||
imageidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
local imageidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
||||||
|
|
||||||
_msg EXEC "Updating database from ${OLD_COMMIT} to ${NEW_COMMIT}"
|
_msg EXEC "Updating database from ${OLD_COMMIT} to ${NEW_COMMIT}"
|
||||||
db_update "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageidList[@]}
|
db_update "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageidList[@]}
|
||||||
[[ $? -ne 0 ]] && { _msg WARN; local ERR=true; } || _msg OK
|
[[ $? -ne 0 ]] && { _msg WARN; local ERR=true; } || _msg OK
|
||||||
[[ ${ERR} ]] && return 1 || { awk -v newcommit=${NEW_COMMIT} 'BEGIN{FS="\t"}{if($1=="LAST_COMMIT"){$2=newcommit}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE}; return 0; }
|
[[ ${ERR} ]] && return 1 || { gawk -i inplace -v newcommit=${NEW_COMMIT} 'BEGIN{FS="\t";OFS="\t"}{if($1=="LAST_UPDATE"){$2=newcommit}{print $0}}' ${DB_FILE}; return 0; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ db_set() {
|
||||||
|
|
||||||
# Determines which IMAGEIDs present in the DB_FILE match the CONDITION
|
# Determines which IMAGEIDs present in the DB_FILE match the CONDITION
|
||||||
local COUNT=1
|
local COUNT=1
|
||||||
local dbimageidList=$(awk 'BEGIN{FS="\t"}{print $2}' ${DB_FILE} | awk '!seen[$0]++')
|
local dbimageidList=$(awk 'BEGIN{FS="\t"}{if($1!="LAST_DEPLOY" && $1!="LAST_UPDATE" && $!="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++')
|
||||||
for dbimageid in ${dbimageidList[@]}; do
|
for dbimageid in ${dbimageidList[@]}; do
|
||||||
local MTAG="$(printf "${GIT_DIR}/%s.tags" ${dbimageid})"
|
local MTAG="$(printf "${GIT_DIR}/%s.tags" ${dbimageid})"
|
||||||
local MATCH="$(grep -i -l "\"${FIELD}\" : \"${VALUE}\"" "${MTAG}")"
|
local MATCH="$(grep -i -l "\"${FIELD}\" : \"${VALUE}\"" "${MTAG}")"
|
||||||
|
|
|
@ -19,6 +19,11 @@ db_update() {
|
||||||
[[ -f "${DB_FILE}" ]] || touch "${DB_FILE}"
|
[[ -f "${DB_FILE}" ]] || touch "${DB_FILE}"
|
||||||
for imageid in ${imageidList[@]}; do
|
for imageid in ${imageidList[@]}; do
|
||||||
trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}' ${GIT_DIR}/${imageid}.tags))
|
trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}' ${GIT_DIR}/${imageid}.tags))
|
||||||
|
if [[ -f ${GIT_DIR}/${imageid}.tags ]]; then
|
||||||
|
_msg ECHO "Removing ${imageid} from database file"
|
||||||
|
gawk -i inplace -v imageid="${imageid}" 'BEGIN{FS="\t";OFS="\t"}{if($2=imageid){$1="null"}{print $0}}' ${DB_FILE}
|
||||||
|
continue
|
||||||
|
fi
|
||||||
for trackid in ${trackidList[@]}; do
|
for trackid in ${trackidList[@]}; do
|
||||||
if [[ -z $(awk -v imageid="${imageid}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then
|
if [[ -z $(awk -v imageid="${imageid}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then
|
||||||
_msg ECHO "Adding ${trackid} of ${imageid} to database file"
|
_msg ECHO "Adding ${trackid} of ${imageid} to database file"
|
||||||
|
|
46
src/deploy_cp
Normal file
46
src/deploy_cp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# doc deploy_cp {
|
||||||
|
#
|
||||||
|
# DESCRIPTION
|
||||||
|
# deploy_cp - Deploys IMAGEIDs to TARGET using files from GITDIR, for when TRACKID has
|
||||||
|
# never been deployed to TARGET before.
|
||||||
|
#
|
||||||
|
# USAGE
|
||||||
|
# deploy_cp </path/to/git/dir> </path/to/target> </path/to/db/file> <IMAGEID>
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
|
||||||
|
deploy_cp() {
|
||||||
|
## Argument parsing
|
||||||
|
local GIT_DIR="${1}"
|
||||||
|
local TARGET="${2}"
|
||||||
|
local DB_FILE="${3}"
|
||||||
|
local IMAGEID="${4}"
|
||||||
|
|
||||||
|
|
||||||
|
## Splits IMAGEID into TRACKIDs
|
||||||
|
_msg EXEC "Splitting ${imageid}"
|
||||||
|
deploy_gen "${GIT_DIR}" ${imageid} >${STDERR} 2>&1
|
||||||
|
[[ $? -ne 0 ]] && _msg WARN
|
||||||
|
deploy_mv "${GIT_DIR}" ${imageid} >${STDERR} 2>&1
|
||||||
|
[[ $? -eq 0 ]] && _msg OK || _msg WARN
|
||||||
|
|
||||||
|
## Transfers selected TRACKIDs to TARGET
|
||||||
|
trackidList=($(awk -v imageid=${imageid} 'BEGIN{FS="\t"}{if($1=="true" && $2==imageid && $4=="null"){print $3}}' "${DB_FILE}"))
|
||||||
|
for trackid in ${trackidList[@]}; do
|
||||||
|
_msg EXEC "Deploying ${trackid}"
|
||||||
|
cp "${GIT_DIR}/${imageid}-${trackid}.flac" "${TARGET}/${imageid}-${trackid}.flac"
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
_msg OK
|
||||||
|
gawk -i inplace -v trackid=${trackid} -v value="${imageid}-${trackid}.flac" 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}
|
||||||
|
else
|
||||||
|
_msg WARN
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
## Cleans GIT_DIR of split IMAGEIDs
|
||||||
|
_msg EXEC "Cleaning ${imageid}"
|
||||||
|
find ${GIT_DIR}/ -name "${imageid}-" -exec rm '{}' \;
|
||||||
|
[[ $? -eq 0 ]] && _msg OK || _msg WARN
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# doc deploy_imageid {
|
|
||||||
#
|
|
||||||
# DESCRIPTION
|
|
||||||
# deploy_imageid - Wraps the deploy_trackid function on a per imageid basis
|
|
||||||
#
|
|
||||||
# USAGE
|
|
||||||
# deploy_imageid <path/to/git/dir> </path/to/target> <IMAGEID>
|
|
||||||
#
|
|
||||||
# }
|
|
||||||
|
|
||||||
deploy_imageid() {
|
|
||||||
## Argument parsing
|
|
||||||
local GIT_DIR="${1}"
|
|
||||||
local TARGET="${2}"
|
|
||||||
local DB_FILE="${3}"
|
|
||||||
local IMAGEID="${4}"
|
|
||||||
|
|
||||||
[[ -n "$(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($1=="true" && $2==imageid && $4=="null"){print NR}}' ${DB_FILE})" ]] && { deploy_gen ${GIT_DIR} ${IMAGEID}; deploy_mv ${GIT_DIR} ${IMAGEID}; }
|
|
||||||
|
|
||||||
local trackidList=($(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($2==imageid){print $3}}' ${DB_FILE}))
|
|
||||||
for trackid in ${trackidList[@]}; do
|
|
||||||
_msg EXEC "Processing ${trackid} of ${IMAGEID}"
|
|
||||||
deploy_trackid ${GIT_DIR} ${TARGET} ${DB_FILE} ${IMAGEID} ${trackid}
|
|
||||||
[[ $? -ne 0 ]] && { _msg WARN; local ERR=true; } || _msg OK
|
|
||||||
done
|
|
||||||
[[ ${ERR} ]] && return 1 || return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
46
src/deploy_meta
Normal file
46
src/deploy_meta
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# doc deploy_meta {
|
||||||
|
#
|
||||||
|
# DESCRIPTION
|
||||||
|
# deploy_meta - Makes the deployment of metadata in TARGET consistent with GIT_DIR
|
||||||
|
#
|
||||||
|
# USAGE
|
||||||
|
# deploy_meta <path/to/git/dir> <path/to/target> <path/to/db/file> <IMAGEID>
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
|
||||||
|
deploy_meta() {
|
||||||
|
## Argument parsing
|
||||||
|
local GIT_DIR="${1}"
|
||||||
|
local TARGET="${2}"
|
||||||
|
local DB_FILE="${3}"
|
||||||
|
local IMAGEID="${4}"
|
||||||
|
|
||||||
|
local trackidList=($(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($1=="true" && $2==imageid){print $3}}' ${DB_FILE}))
|
||||||
|
for trackid in ${trackidList[@]}; do
|
||||||
|
local TRACKNO="$(print_track_no ${GIT_DIR} ${IMAGEID} ${trackid})"
|
||||||
|
_msg ECHO "Checking ${trackid}"
|
||||||
|
## Path and metadata parsing
|
||||||
|
local FUTURE_META="$(print_meta_mtag ${GIT_DIR}/${IMAGEID}.tags ${TRACKNO} | tr '\\' -d)"
|
||||||
|
local FUTURE_PATH="$(print_future_path ${FUTURE_META} | tr '"\:*?|<>' '________' )"
|
||||||
|
local PRESENT_PATH="$(print_present_path "${DB_FILE}" ${IMAGEID} ${trackid})"
|
||||||
|
local PRESENT_META="$(print_meta_flac "${TARGET}/${PRESENT_PATH}")"
|
||||||
|
|
||||||
|
# If the PRESENT_META and FUTURE_META diverge, wipe the old metadata, and reapply
|
||||||
|
if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then
|
||||||
|
_msg ECHO "${trackid} has differing metadata. Updating"
|
||||||
|
[[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}"
|
||||||
|
awk 'BEGIN {RS=";"}{print $0}' <<< ${FUTURE_META} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the PRESENT_PATH and FUTURE_PATH diverge, move to new location
|
||||||
|
if [[ "${PRESENT_PATH}" != "${FUTURE_PATH}" ]]; then
|
||||||
|
_msg ECHO "${trackid} has differing paths. Moving"
|
||||||
|
mkdir -p "$(dirname "${TARGET}/${FUTURE_PATH}")"
|
||||||
|
mv "${TARGET}/${PRESENT_PATH}" "${TARGET}/${FUTURE_PATH}"
|
||||||
|
rmdir -p --ignore-fail-on-non-empty "$(dirname "${TARGET}/${PRESENT_PATH}")" >${STDERR} 2>&1
|
||||||
|
gawk -i inplace -v trackid=${trackid} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
25
src/deploy_rm
Normal file
25
src/deploy_rm
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# doc deploy_rm {
|
||||||
|
#
|
||||||
|
# DESCRIPTION
|
||||||
|
# deploy_rm - Removes TRACKIDs from TARGET
|
||||||
|
#
|
||||||
|
# USAGE
|
||||||
|
# deploy_rm </path/to/target> </path/to/db/file> <TRACKID>
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
|
||||||
|
deploy_rm() {
|
||||||
|
## Argument parsing
|
||||||
|
local TARGET="${1}"
|
||||||
|
local DB_FILE="${2}"
|
||||||
|
local IMAGEID=$(awk 'BEGIN{FS="--"}{print $1"--"$2}' <<< ${3})
|
||||||
|
local TRACKID=$(awk 'BEGIN{FS="--"}{print $3}' <<< ${3})
|
||||||
|
|
||||||
|
## Removes trackids from TARGET
|
||||||
|
_msg EXEC "Removing ${TRACKID} from ${TARGET}"
|
||||||
|
rm "${TARGET}/$(print_present_path "${DB_FILE}" ${IMAGEID} ${TRACKID})" >${STDERR} 2>&1
|
||||||
|
[[ $? -eq 0 ]] && { _msg OK; gawk -i inplace -v trackid=${TRACKID} -v value=null 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}; return 1; } || { _msg WARN; return 1; }
|
||||||
|
}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# doc deploy_trackid {
|
|
||||||
#
|
|
||||||
# DESCRIPTION
|
|
||||||
# deploy_trackid - Deploys TRACKID of IMAGEID to TARGET
|
|
||||||
#
|
|
||||||
# USAGE
|
|
||||||
# deploy_trackid <path/to/git/dir> <path/to/target> <path/to/db/file> <IMAGEID> <TRACKID>
|
|
||||||
#
|
|
||||||
# }
|
|
||||||
|
|
||||||
deploy_trackid() {
|
|
||||||
## Argument parsing
|
|
||||||
local GIT_DIR="${1}"
|
|
||||||
local TARGET="${2}"
|
|
||||||
local DB_FILE="${3}"
|
|
||||||
local IMAGEID="${4}"
|
|
||||||
local TRACKID="${5}"
|
|
||||||
|
|
||||||
local TRACKNO="$(print_track_no ${GIT_DIR} ${IMAGEID} ${TRACKID})"
|
|
||||||
|
|
||||||
## Path and metadata parsing
|
|
||||||
local FUTURE_META="$(print_meta_mtag ${GIT_DIR}/${IMAGEID}.tags ${TRACKNO})"
|
|
||||||
local FUTURE_PATH="$(print_future_path ${FUTURE_META}})"
|
|
||||||
local PRESENT_PATH="$(print_present_path ${DB_FILE} ${IMAGEID} ${TRACKID})"
|
|
||||||
local PRESENT_META="$(print_meta_flac "${TARGET}/${PRESENT_PATH}")"
|
|
||||||
local ROW_NO=$(awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print NR}}' ${DB_FILE})
|
|
||||||
|
|
||||||
# If the track is selected, we will check if the trackid has already been deployed, if not deploy. If the metadata to be
|
|
||||||
# applied is different than what's deployed, apply new metadata. If the path has changed, move file to new path.
|
|
||||||
if is_selected ${DB_FILE} ${IMAGEID} ${TRACKID}; then
|
|
||||||
|
|
||||||
# In the event that PRESENT_PATH is null, that is to say the trackid is not present on target, transfers it there and then defined the PRESENT_PATH as the transfered FLAC
|
|
||||||
if [[ "${PRESENT_PATH}" == "null" ]]; then
|
|
||||||
_msg ECHO "${TRACKID} is not deployed. Deploying"
|
|
||||||
mv "${GIT_DIR}/${IMAGEID}-${TRACKID}.flac" "${TARGET}/${IMAGEID}-${TRACKID}.flac"
|
|
||||||
PRESENT_PATH="${IMAGEID}-${TRACKID}.flac"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If the PRESENT_META and FUTURE_META diverge, wipe the old metadata, and reapply
|
|
||||||
if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then
|
|
||||||
_msg ECHO "${TRACKID} has differing metadata. Updating"
|
|
||||||
[[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}"
|
|
||||||
awk 'BEGIN {RS=";"}{print $0}' <<< ${FUTURE_META} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If the PRESENT_PATH and FUTURE_PATH diverge, move to new location
|
|
||||||
if [[ "${PRESENT_PATH}" != "${FUTURE_PATH}" ]]; then
|
|
||||||
_msg ECHO "${TRACKID} has differing paths. Moving"
|
|
||||||
mkdir -p "$(dirname "${TARGET}/${FUTURE_PATH}")"
|
|
||||||
mv "${TARGET}/${PRESENT_PATH}" "${TARGET}/${FUTURE_PATH}"
|
|
||||||
rmdir -p --ignore-fail-on-non-empty "$(dirname "${TARGET}/${PRESENT_PATH}")"
|
|
||||||
awk -v rowno=${ROW_NO} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if(NR==rowno){$4=value}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE}
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
if [[ ${PRESENT_PATH} != "null" ]]; then
|
|
||||||
_msg ECHO "${TARGETID} was previouslty selected, and is now unselected. Deleting"
|
|
||||||
rm "${TARGET}/${PRESENT_PATH}"
|
|
||||||
awk -v rowno=${ROW_NO} -v value=null 'BEGIN{FS="\t";OFS="\t"}{if(NR==rowno){$4=value}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE}
|
|
||||||
else
|
|
||||||
_msg ECHO "${TARGETID} not selected"
|
|
||||||
rm "${GIT_DIR}/${IMAGEID}-${TRACKID}.flac"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# doc is_selected {
|
|
||||||
#
|
|
||||||
# DESCRIPTION
|
|
||||||
# is selected - Returns true if IMAGEID is defined as selected in DB_FILE.
|
|
||||||
#
|
|
||||||
# USAGE
|
|
||||||
# is_selected </path/to/db/file> <IMAGEID> <TRACKID>
|
|
||||||
#
|
|
||||||
# }
|
|
||||||
|
|
||||||
is_selected() {
|
|
||||||
local DB_FILE="${1}"
|
|
||||||
local IMAGEID="${2}"
|
|
||||||
local TRACKID="${3}"
|
|
||||||
|
|
||||||
[[ "$(awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS"\t"}{if($2==imageid && $3==trackid){print $1}}' ${DB_FILE})" == "true" ]] && return 0 || return 1
|
|
||||||
}
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ print_future_path() {
|
||||||
|
|
||||||
[[ ${TOTALDISCS} -gt 1 ]] && echo -n "${DISCNUMBER}."
|
[[ ${TOTALDISCS} -gt 1 ]] && echo -n "${DISCNUMBER}."
|
||||||
printf "%02d" ${TRACKNUMBER}
|
printf "%02d" ${TRACKNUMBER}
|
||||||
echo -n " - $(sed 's|/|-|g' <<< ${TITLE} | sed 's|?||g').flac"
|
[[ -n "${TITLE}" ]] && echo -n " - $(sed 's|/|_|g' <<< ${TITLE})" || echo -n " - ${ALBUM}"
|
||||||
|
echo -n ".flac"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ print_meta_flac() {
|
||||||
local tagList=(${@})
|
local tagList=(${@})
|
||||||
[[ ! -f ${FILE} ]] && return 1
|
[[ ! -f ${FILE} ]] && return 1
|
||||||
|
|
||||||
local METADATA=$(awk 'BEGIN{FS=": ";ORS=";"}{if($1 ~ /comment\[/){print $2}}' <<< $(metaflac --list --block-type=VORBIS_COMMENT "${FILE}"))
|
local METADATA=$(awk 'BEGIN{FS="]: ";ORS=";"}{if($1 ~ /comment\[/){print $2}}' <<< $(metaflac --list --block-type=VORBIS_COMMENT "${FILE}"))
|
||||||
if [[ -z "${tagList[@]}" ]]; then
|
if [[ -z "${tagList[@]}" ]]; then
|
||||||
echo -n ${METADATA} | sed 's|.$||'
|
echo -n ${METADATA} | sed 's|.$||'
|
||||||
else
|
else
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
|
|
||||||
print_present_path() {
|
print_present_path() {
|
||||||
local DB_FILE="${1}"
|
local DB_FILE="${1}"
|
||||||
local TRACKID="${2}"
|
local IMAGEID="${2}"
|
||||||
|
local TRACKID="${3}"
|
||||||
|
|
||||||
awk -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($3==trackid){print $4}}' ${DB_FILE}
|
awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $4}}' ${DB_FILE}
|
||||||
}
|
}
|
||||||
|
|
28
src/print_trackids_to_imageids
Normal file
28
src/print_trackids_to_imageids
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# doc print_trackids_to_imageids {
|
||||||
|
#
|
||||||
|
# DESCRIPTION
|
||||||
|
# print_trackids_to_imageids - Prints the IMAGEIDs of all TRACKIDs.
|
||||||
|
#
|
||||||
|
# USAGE
|
||||||
|
# print_trackids_to_imageids </path/to/db/file> <TRACKID_1> [<...>]
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
|
||||||
|
print_trackids_to_imageids() {
|
||||||
|
## Argument parsing
|
||||||
|
local DB_FILE="${1}"; shift
|
||||||
|
local trackidList=(${@})
|
||||||
|
|
||||||
|
## Prints imageid of trackid if trackidList has only 1 element
|
||||||
|
[[ ${#imageidList[@]} -eq 1 ]] && { awk -v trackid=${trackid} 'BEGIN{FS="\t"}{if($3==trackid){print $2}}' ${DB_FILE}; return 0; }
|
||||||
|
|
||||||
|
## Generates imageidList
|
||||||
|
for trackid in ${trackidList[@]}; do
|
||||||
|
local imageidList=(${imageidList[@]} $(awk -v trackid=${trackid} 'BEGIN{FS="\t"}{if($3==trackid){print $2}}' ${DB_FILE}))
|
||||||
|
done
|
||||||
|
|
||||||
|
awk '!seen[$0]++' <<<$(printf "%s\n" ${imageidList[@]})
|
||||||
|
return 0
|
||||||
|
}
|
Loading…
Reference in a new issue