forked from Normation/rudder-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_os.sh
67 lines (65 loc) · 2.51 KB
/
detect_os.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#####################################################################################
# Copyright 2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################
set -e
# Default values are empty
export OS=""
export OSVERSION=""
export OSSP=""
# Detect OS with this logic:
# RHEL has /etc/redhat-release
# SLES has /etc/SuSE-release
# Debian and Ubuntu have /etc/debian_version
# Ubuntu have /etc/lsb-release with a DISTRIB_ID equal to 'Ubuntu'
if [ "z$(uname -s)" = "zAIX" ]; then
export OS="AIX"
# Format: Major.Minor (Ex: 5.3)
export OSVERSION="$(uname -v).$(uname -r)"
# No Service Pack
export OSSP=""
elif [ -f /etc/SuSE-release ]; then
export OS="SLES"
export OSVERSION=$(cat /etc/SuSE-release | grep VERSION | cut -f2 -d '=' | sed 's/ //')
export OSSP=$(/etc/SuSE-release | grep PATCHLEVEL | cut -f2 -d '=' | sed 's/ //')
elif [ -f /etc/fedora-release ]; then
export OS="FEDORA"
export OSVERSION=$(cat /etc/fedora-release | sed 's/^.* release \([^\.][^\.]\).*$/\1/')
# No Service Pack
export OSSP=""
elif [ -f /etc/redhat-release ]; then
export OS="RHEL"
export OSVERSION=$(cat /etc/redhat-release | sed 's/^.* release \([^\.]\).*$/\1/')
# No Service Pack
export OSSP=""
elif [ -f /etc/debian_version ]; then
if [ -f /etc/lsb-release -a "z$(grep DISTRIB_ID /etc/lsb-release | cut -f2 -d '=' | sed 's/ //')" = "zUbuntu" ]; then
export OS="UBUNTU"
# Ubuntu version is always formatted like X.Y
export OSVERSION=$(cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f2 -d '=' | sed 's/ //')
# No Service Pack
export OSSP=""
else
export OS="DEBIAN"
# Debian version is always formatted like X.Y.Z except for testing and unstable
# but it does not concern us.
export OSVERSION=$(cat /etc/debian_version | cut -f1 -d '.')
# No Service Pack
export OSSP=""
fi
else
export OS="unknown"
fi