
[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
53 lines
2.5 KiB
Bash
53 lines
2.5 KiB
Bash
#! /bin/bash
|
|
|
|
# doc cmd_deploy {
|
|
#
|
|
# DESCRIPTION
|
|
# cmd_deploy - Command that deploys IMAGEIDs using deploy_imageid function
|
|
#
|
|
# USAGE
|
|
# cmd_deploy - </path/to/git/dir> </path/to/target>
|
|
#
|
|
# }
|
|
|
|
cmd_deploy() {
|
|
local GIT_DIR="${1}"
|
|
local TARGET="${2}"; shift 2
|
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
|
|
|
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
|
|
local futureidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){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} ${futureidList[@]}) - $(print_imageid_du "${GIT_DIR}" ${presentidList[@]}) ))"
|
|
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; }
|
|
|
|
# Cleans target of removable TRACKID
|
|
for removableid in ${removableidList[@]}; do
|
|
deploy_rm "${TARGET}" "${DB_FILE}" ${removableid}
|
|
done
|
|
|
|
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; }
|
|
}
|