| 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 |
|
| 47 |
AU_ALIAS([AC_NAGIOS_GET_DISTRIB_TYPE], [AX_NAGIOS_GET_DISTRIB_TYPE]) |
| 48 |
AC_DEFUN([AX_NAGIOS_GET_DISTRIB_TYPE], |
| 49 |
[ |
| 50 |
|
| 51 |
AC_SUBST(dist_type) |
| 52 |
AC_SUBST(dist_ver) |
| 53 |
|
| 54 |
# |
| 55 |
# Get user hints for possible cross-compile |
| 56 |
# |
| 57 |
AC_MSG_CHECKING(what the distribution type is ) |
| 58 |
AC_ARG_WITH(dist-type, AC_HELP_STRING([--with-dist-type=type], |
| 59 |
[specify distribution type (suse, rh, debian, etc.)]), |
| 60 |
[ |
| 61 |
# |
| 62 |
# Run this if --with was specified |
| 63 |
# |
| 64 |
if test "x$withval" = x -o x$withval = xno; then |
| 65 |
dist_type_wanted=yes |
| 66 |
else |
| 67 |
dist_type_wanted=no |
| 68 |
dist_type="$withval" |
| 69 |
dist_ver="unknown" |
| 70 |
AC_MSG_RESULT($dist_type) |
| 71 |
fi |
| 72 |
], [ |
| 73 |
# |
| 74 |
# Run this if --with was not specified |
| 75 |
# |
| 76 |
dist_type_wanted=yes |
| 77 |
]) |
| 78 |
|
| 79 |
if test x$dist_type = xno; then |
| 80 |
dist_type_wanted=yes |
| 81 |
elif test x$dist_type = xyes; then |
| 82 |
AC_MSG_ERROR([you must enter a distribution type if '--with-dist-type' is specified]) |
| 83 |
fi |
| 84 |
|
| 85 |
# |
| 86 |
# Determine distribution type if it wasn't supplied |
| 87 |
# |
| 88 |
dist_ver="unknown" |
| 89 |
|
| 90 |
if test $dist_type_wanted=yes; then |
| 91 |
dist_type="unknown" |
| 92 |
|
| 93 |
if test "$opsys" != "linux"; then |
| 94 |
dist_type="$opsys" |
| 95 |
AS_CASE([$opsys], |
| 96 |
[bsd], |
| 97 |
dist_type=`uname -s | tr ["[A-Z]" "[a-z]"]` |
| 98 |
dist_ver=`uname -r`, |
| 99 |
[aix], |
| 100 |
dist_ver="`uname -v`.`uname -r`", |
| 101 |
[hp-ux], |
| 102 |
dist_ver=`uname -r | cut -d'.' -f1-3`, |
| 103 |
[solaris], |
| 104 |
dist_ver=`uname -r | cut -d'.' -f2`, |
| 105 |
[*], |
| 106 |
dist_ver=$OSTYPE |
| 107 |
) |
| 108 |
|
| 109 |
else |
| 110 |
|
| 111 |
if test -r "/etc/gentoo-release"; then |
| 112 |
dist_type="gentoo" |
| 113 |
dist_ver=`cat /etc/gentoo-release` |
| 114 |
|
| 115 |
elif test -r "/etc/os-release"; then |
| 116 |
. /etc/os-release |
| 117 |
if test x"$ID_LIKE" != x; then |
| 118 |
dist_type=`echo $ID_LIKE | cut -d' ' -f1 | tr ["[A-Z]" "[a-z]"]` |
| 119 |
elif test x"$ID" = xol; then |
| 120 |
dist_type=rh |
| 121 |
else |
| 122 |
dist_type=`echo $ID | tr ["[A-Z]" "[a-z]"]` |
| 123 |
fi |
| 124 |
if test x"$dist_type" = sles; then |
| 125 |
dist_type=suse |
| 126 |
fi |
| 127 |
if test x"$VERSION_ID" != x; then |
| 128 |
dist_ver=$VERSION_ID |
| 129 |
elif test x"$VERSION" != x; then |
| 130 |
dist_ver=`echo $VERSION | cut -d'.' -f1 | tr -d [:alpha:][:blank:][:punct:]` |
| 131 |
fi |
| 132 |
|
| 133 |
elif test -r "/etc/redhat-release"; then |
| 134 |
dist_type=rh |
| 135 |
dist_ver=`cat /etc/redhat-release` |
| 136 |
|
| 137 |
elif test -r "/etc/debian_version"; then |
| 138 |
dist_type="debian" |
| 139 |
if test -r "/etc/lsb-release"; then |
| 140 |
. /etc/lsb-release |
| 141 |
dist_ver=`echo "$DISTRIB_RELEASE"` |
| 142 |
else |
| 143 |
dist_ver=`cat /etc/debian_version` |
| 144 |
fi |
| 145 |
|
| 146 |
elif test -r "/etc/SuSE-release"; then |
| 147 |
dist_type=suse |
| 148 |
dist_ver=`grep VERSION /etc/SuSE-release` |
| 149 |
|
| 150 |
fi |
| 151 |
|
| 152 |
fi |
| 153 |
|
| 154 |
if test "$dist_ver" != "unknown"; then |
| 155 |
dist_ver=`echo "$dist_ver" | cut -d'.' -f1 | tr -d [:alpha:][:blank:][:punct:]` |
| 156 |
fi |
| 157 |
fi |
| 158 |
|
| 159 |
AC_MSG_RESULT($dist_type) |
| 160 |
]) |