check-host-tar.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.35 (1.35 changed devmajor/devminor for files)
  26. # https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00005.html
  27. major_min=1
  28. minor_min=35
  29. if [ $major -lt $major_min ]; then
  30. # echo nothing: no suitable tar found
  31. exit 1
  32. fi
  33. if [ $major -eq $major_min -a $minor -lt $minor_min ]; then
  34. # echo nothing: no suitable tar found
  35. exit 1
  36. fi
  37. # valid
  38. echo $tar