X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/0cef41dde7ed3fc3df48a8fb84e824faa405ce49..2feb5df8cfd56437119d3dbbc55174b5ee31d005:/unitproc/bktemp-checkMakeTar diff --git a/unitproc/bktemp-checkMakeTar b/unitproc/bktemp-checkMakeTar index 147d21e..07cec78 100644 --- a/unitproc/bktemp-checkMakeTar +++ b/unitproc/bktemp-checkMakeTar @@ -1,43 +1,40 @@ #!/bin/bash - # Desc: Checks that a valid tar archive exists, creates one otherwise - +#===BEGIN Declare local script functions=== yell() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique die() { yell "$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370 try() { "$@" || die "cannot $*"; } #o - -#===BEGIN Declare local script functions=== checkMakeTar() { # Desc: Checks that a valid tar archive exists, creates one otherwise # Usage: checkMakeTar [ path ] - # Version: 1.0.0 + # Version: 1.0.2 # Input: arg1: path of tar archive # Output: exit code 0 : tar readable # exit code 1 : tar missing; created # exit code 2 : tar not readable; moved; replaced - # Depends: try, tar, date - local PATH_TAR returnFlag0 returnFlag1 returnFlag2 - PATH_TAR="$1" + # Depends: bash 5, date 8, tar 1, try() + local pathTar returnFlag0 returnFlag1 returnFlag2 + pathTar="$1"; # Check if file is a valid tar archive - if tar --list --file="$PATH_TAR" 1>/dev/null 2>&1; then + if tar --list --file="$pathTar" 1>/dev/null 2>&1; then ## T1: return success returnFlag0="tar valid"; else ## F1: Check if file exists - if [[ -f "$PATH_TAR" ]]; then + if [[ -f "$pathTar" ]]; then ### T: Rename file - try mv "$PATH_TAR" "$PATH_TAR""--broken--""$(date +%Y%m%dT%H%M%S)" && \ + try mv "$pathTar" "$pathTar""--broken--""$(date +%Y%m%dT%H%M%S)" && \ returnFlag1="tar moved"; else ### F: - : - fi + fi; ## F2: Create tar archive, return 0 - try tar --create --file="$PATH_TAR" --files-from=/dev/null && \ + try tar --create --file="$pathTar" --files-from=/dev/null && \ returnFlag2="tar created"; - fi + fi; # Determine function return code if [[ "$returnFlag0" = "tar valid" ]]; then @@ -46,7 +43,7 @@ checkMakeTar() { return 1; # tar missing so created elif [[ "$returnFlag2" = "tar created" ]] && [[ "$returnFlag1" = "tar moved" ]]; then return 2; # tar not readable so moved; replaced - fi + fi; } # checks if arg1 is tar; creates one otherwise #===END Declare local script functions===