ax_nagios_get_distrib 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # ===========================================================================
  2. # SYNOPSIS
  3. #
  4. # AX_NAGIOS_GET_DISTRIB_TYPE
  5. #
  6. # DESCRIPTION
  7. #
  8. # This macro determines the O/S distribution of the computer it is run on.
  9. # $dist_type will be set and will be one of:
  10. # unknown (could not be determined)
  11. # freebsd, netbsd, openbsd, dragonfly, etc (The BSDs)
  12. # suse, rh, debian, gentoo (and possibly their descendants)
  13. # Other major Linux distributions (and possibly their descendants)
  14. # The O/S name for the rest
  15. #
  16. # LICENSE
  17. #
  18. # Copyright (c) 2016 Nagios Core Development Team
  19. #
  20. # This program is free software; you can redistribute it and/or modify it
  21. # under the terms of the GNU General Public License as published by the
  22. # Free Software Foundation; either version 2 of the License, or (at your
  23. # option) any later version.
  24. #
  25. # This program is distributed in the hope that it will be useful, but
  26. # WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  28. # Public License for more details.
  29. #
  30. # You should have received a copy of the GNU General Public License along
  31. # with this program. If not, see <http://www.gnu.org/licenses/>.
  32. #
  33. # As a special exception, the respective Autoconf Macro's copyright owner
  34. # gives unlimited permission to copy, distribute and modify the configure
  35. # scripts that are the output of Autoconf when processing the Macro. You
  36. # need not follow the terms of the GNU General Public License when using
  37. # or distributing such scripts, even though portions of the text of the
  38. # Macro appear in them. The GNU General Public License (GPL) does govern
  39. # all other use of the material that constitutes the Autoconf Macro.
  40. #
  41. # This special exception to the GPL applies to versions of the Autoconf
  42. # Macro released by the Autoconf Archive. When you make and distribute a
  43. # modified version of the Autoconf Macro, you may extend this special
  44. # exception to the GPL to apply to your modified version as well.
  45. # ===========================================================================
  46. AU_ALIAS([AC_NAGIOS_GET_DISTRIB_TYPE], [AX_NAGIOS_GET_DISTRIB_TYPE])
  47. AC_DEFUN([AX_NAGIOS_GET_DISTRIB_TYPE],
  48. [
  49. AC_SUBST(dist_type)
  50. AC_SUBST(dist_ver)
  51. #
  52. # Get user hints for possible cross-compile
  53. #
  54. AC_MSG_CHECKING(what the distribution type is )
  55. AC_ARG_WITH(dist-type, AC_HELP_STRING([--with-dist-type=type],
  56. [specify distribution type (suse, rh, debian, etc.)]),
  57. [
  58. #
  59. # Run this if --with was specified
  60. #
  61. if test "x$withval" = x -o x$withval = xno; then
  62. dist_type_wanted=yes
  63. else
  64. dist_type_wanted=no
  65. dist_type="$withval"
  66. dist_ver="unknown"
  67. AC_MSG_RESULT($dist_type)
  68. fi
  69. ], [
  70. #
  71. # Run this if --with was not specified
  72. #
  73. dist_type_wanted=yes
  74. ])
  75. if test x$dist_type = xno; then
  76. dist_type_wanted=yes
  77. elif test x$dist_type = xyes; then
  78. AC_MSG_ERROR([you must enter a distribution type if '--with-dist-type' is specified])
  79. fi
  80. #
  81. # Determine distribution type if it wasn't supplied
  82. #
  83. dist_ver="unknown"
  84. if test $dist_type_wanted=yes; then
  85. dist_type="unknown"
  86. if test "$opsys" != "linux"; then
  87. dist_type="$opsys"
  88. AS_CASE([$opsys],
  89. [bsd],
  90. dist_type=`uname -s | tr ["[A-Z]" "[a-z]"]`
  91. dist_ver=`uname -r`,
  92. [aix],
  93. dist_ver="`uname -v`.`uname -r`",
  94. [hp-ux],
  95. dist_ver=`uname -r | cut -d'.' -f1-3`,
  96. [solaris],
  97. dist_ver=`uname -r | cut -d'.' -f2`,
  98. [*],
  99. dist_ver=$OSTYPE
  100. )
  101. else
  102. if test -r "/etc/gentoo-release"; then
  103. dist_type="gentoo"
  104. dist_ver=`cat /etc/gentoo-release`
  105. elif test -r "/etc/os-release"; then
  106. . /etc/os-release
  107. if test x"$ID_LIKE" != x; then
  108. dist_type=`echo $ID_LIKE | cut -d' ' -f1 | tr ["[A-Z]" "[a-z]"]`
  109. elif test x"$ID" = xol; then
  110. dist_type=rh
  111. else
  112. dist_type=`echo $ID | tr ["[A-Z]" "[a-z]"]`
  113. fi
  114. if test x"$dist_type" = sles; then
  115. dist_type=suse
  116. fi
  117. if test x"$VERSION_ID" != x; then
  118. dist_ver=$VERSION_ID
  119. elif test x"$VERSION" != x; then
  120. dist_ver=`echo $VERSION | cut -d'.' -f1 | tr -d [:alpha:][:blank:][:punct:]`
  121. fi
  122. elif test -r "/etc/redhat-release"; then
  123. dist_type=rh
  124. dist_ver=`cat /etc/redhat-release`
  125. elif test -r "/etc/debian_version"; then
  126. dist_type="debian"
  127. if test -r "/etc/lsb-release"; then
  128. . /etc/lsb-release
  129. dist_ver=`echo "$DISTRIB_RELEASE"`
  130. else
  131. dist_ver=`cat /etc/debian_version`
  132. fi
  133. elif test -r "/etc/SuSE-release"; then
  134. dist_type=suse
  135. dist_ver=`grep VERSION /etc/SuSE-release`
  136. fi
  137. fi
  138. if test "$dist_ver" != "unknown"; then
  139. dist_ver=`echo "$dist_ver" | cut -d'.' -f1 | tr -d [:alpha:][:blank:][:punct:]`
  140. fi
  141. fi
  142. AC_MSG_RESULT($dist_type)
  143. ])