dam/src/export_cp

50 lines
1.6 KiB
Bash

#!/bin/bash
# doc export_cp {
#
# DESCRIPTION
# export_cp - Deploys IMAGEIDs to TARGET using files from GITDIR, for when TRACKID has
# never been deployed to TARGET before.
#
# USAGE
# export_cp </path/to/git/dir> </path/to/target> </path/to/db/file> <IMAGEID>
#
# DEPENDENCIES bunc/src/* src/gen_tracks src/export_mv
#
# }
export_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}"
gen_tracks "${GIT_DIR}" "${GIT_DIR}/${IMAGEID}.flac" "${GIT_DIR}/${IMAGEID}.cue" >${STDERR} 2>&1
local EXIT=$?
[[ ${EXIT} -ne 0 ]] && return 1
export_mv "${GIT_DIR}" ${IMAGEID} >${STDERR} 2>&1
## 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"
local EXIT=$?
if [[ ${EXIT} -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
return 3
fi
done
## Cleans GIT_DIR of split IMAGEIDs
_msg EXEC "Cleaning ${IMAGEID}"
find ${GIT_DIR}/ \( -name "${IMAGEID}-*" -or -name "split-track*" \) -exec rm '{}' \;
[[ $? -eq 0 ]] && _msg OK || _msg WARN
}