From 16b733b568019f46bc806556e32cbaebaf70d434 Mon Sep 17 00:00:00 2001 From: ayakael Date: Thu, 29 Mar 2018 12:45:53 -0400 Subject: [PATCH] [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 --- src/cmd_deploy | 8 ++++++++ src/print_imageid_du | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/print_imageid_du diff --git a/src/cmd_deploy b/src/cmd_deploy index 37ab9f2..a236481 100644 --- a/src/cmd_deploy +++ b/src/cmd_deploy @@ -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 diff --git a/src/print_imageid_du b/src/print_imageid_du new file mode 100644 index 0000000..6e9e042 --- /dev/null +++ b/src/print_imageid_du @@ -0,0 +1,19 @@ +#!/bin/bash + +# doc print_imageid_du +# +# DESCRIPTION +# print_imageid_du - Prints disk usage of IMAGEIds +# +# USAGE +# print_imageid_du [ <...>] +# +# } + +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" +}