3 # Desc: Checks that a valid tar archive exists, creates one otherwise
5 # Yell, Die, Try Three-Fingered Claw technique
6 # Ref/Attrib: https://stackoverflow.com/a/25515370
7 yell
() { echo "$0: $*" >&2; }
8 die
() { yell
"$*"; exit 111; }
9 try
() { "$@" || die
"cannot $*"; }
12 # Desc: Checks that a valid tar archive exists, creates one otherwise
13 # Usage: checkTar [ path ]
14 # Input: arg1: path of tar archive
15 # Output: exit code 0: tar exists and is valid
16 # Depends: try, tar, date
19 # Check if file is a valid tar archive
20 if tar --list --file="$PATH_TAR" 1>/dev
/null
2>&1; then
24 ## F1: Check if file exists
25 if [[ -f "$PATH_TAR" ]]; then
27 try
mv "$PATH_TAR" "$PATH_TAR""--broken--""$(date +%Y%m%dT%H%M%S)";
32 ## F2: Create tar archive
33 try
tar --create --file="$PATH_TAR" --files-from=/dev
/null
;
35 } # checks if arg1 is tar; creates one otherwise