#!/bin/bash # doc deploy_trackid { # # DESCRIPTION # deploy_trackid - Deploys TRACKID of IMAGEID to TARGET # # USAGE # deploy_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_future_meta ${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_present_meta "${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 }