[print_imageid_du] Added to calculate disk usage of provided IMAGEIDs

[cmd_deploy] Now warns when target does not have sufficient space for deployable IDs
This commit is contained in:
ayakael 2018-03-29 12:45:53 -04:00
parent badc5c28c9
commit 16b733b568
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026
2 changed files with 27 additions and 0 deletions

View file

@ -18,7 +18,15 @@ cmd_deploy() {
[[ ! -f "${DB_FILE}" ]] && return 1
[[ -z "${imageidList[@]}" ]] && local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
# 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 removableidList=($(awk 'BEGIN{FS="\t"}{if($1=="false" && $4!="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
local DU="$(( $(print_imageid_du ${GIT_DIR} ${deployableidList[@]}) - $(print_imageid_du ${GIT_DIR} ${removableidList[@]}) ))"
local DF="$(df ${TARGET} --output=avail | tail -n -1)"
[[ ${DU} -ge ${DF} ]] && { _msg ECHO "Target does not have enough space for deployable IMAGEID. Need ${DU}, has ${DF}."; return 2; }
for imageid in ${imageidList[@]}; do
_msg EXEC "Deploying ${imageid} to ${TARGET}"
deploy_imageid ${GIT_DIR} ${TARGET} ${DB_FILE} ${imageid} >${STDERR} 2>&1

19
src/print_imageid_du Normal file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# doc print_imageid_du
#
# DESCRIPTION
# print_imageid_du - Prints disk usage of IMAGEIds
#
# USAGE
# print_imageid_du </path/to/git/dir> <IMAGEID_1> [<IMAGEID_2> <...>]
#
# }
print_imageid_du() {
local GIT_DIR="${1}"; shift
local imageidList=(${@})
[[ -z "${imageidList[@]}" ]] && echo 0
local bytesList=($(awk 'BEGIN{RS=",";FS=":"}{if($1=="\"size\""){print $2}}' <<<$(git -C "${GIT_DIR}" annex info --bytes --json $(printf "%s.flac\t" ${imageidList[@]}))))
dc <<< '[+]sa[z2!>az2!>b]sb'"$(sed 's/"//g' <<< "${bytesList[@]}")lbxp"
}