check-host-tar.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # Maximal version = 1.29 (1.30 changed --numeric-owner output for
  31. # filenames > 100 characters). This is really a fix for a bug in
  32. # earlier tar versions regarding deterministic output so it is
  33. # unlikely to be reverted in later versions.
  34. major_max=1
  35. minor_max=29
  36. if [ $major -lt $major_min -o $major -gt $major_max ]; then
  37. # echo nothing: no suitable tar found
  38. exit 1
  39. fi
  40. if [ $major -eq $major_min -a $minor -lt $minor_min ]; then
  41. # echo nothing: no suitable tar found
  42. exit 1
  43. fi
  44. if [ $major -eq $major_max -a $minor -gt $minor_max ]; then
  45. # echo nothing: no suitable tar found
  46. exit 1
  47. fi
  48. # valid
  49. echo $tar