check-host-tar.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.34 (1.35 changed devmajor/devminor for files)
  31. # https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00005.html
  32. major_max=1
  33. minor_max=34
  34. if [ $major -lt $major_min -o $major -gt $major_max ]; then
  35. # echo nothing: no suitable tar found
  36. exit 1
  37. fi
  38. if [ $major -eq $major_min -a $minor -lt $minor_min ]; then
  39. # echo nothing: no suitable tar found
  40. exit 1
  41. fi
  42. if [ $major -eq $major_max -a $minor -gt $minor_max ]; then
  43. # echo nothing: no suitable tar found
  44. exit 1
  45. fi
  46. # valid
  47. echo $tar