check-host-tar.sh 1.1 KB

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