1#!/bin/sh 2 3candidate="$1" 4 5tar=`which $candidate` 6if [ ! -x "$tar" ]; then 7 tar=`which tar` 8 if [ ! -x "$tar" ]; then 9 # echo nothing: no suitable tar found 10 exit 1 11 fi 12fi 13 14# Output of 'tar --version' examples: 15# tar (GNU tar) 1.15.1 16# tar (GNU tar) 1.25 17# bsdtar 2.8.3 - libarchive 2.8.3 18version=`$tar --version | head -n 1 | sed 's/^.*\s\([0-9]\+\.\S\+\).*$/\1/'` 19major=`echo "$version" | cut -d. -f1` 20minor=`echo "$version" | cut -d. -f2` 21bugfix=`echo "$version" | cut -d. -f3` 22version_bsd=`$tar --version | grep 'bsdtar'` 23 24# BSD tar does not have all the command-line options 25if [ -n "${version_bsd}" ] ; then 26 # echo nothing: no suitable tar found 27 exit 1 28fi 29 30# Minimal version = 1.27 (previous versions do not correctly unpack archives 31# containing hard-links if the --strip-components option is used or create 32# different gnu long link headers for path elements > 100 characters). 33major_min=1 34minor_min=27 35 36if [ $major -lt $major_min ]; then 37 # echo nothing: no suitable tar found 38 exit 1 39fi 40 41if [ $major -eq $major_min -a $minor -lt $minor_min ]; then 42 # echo nothing: no suitable tar found 43 exit 1 44fi 45 46# valid 47echo $tar 48