dist_information.sh
4.24 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
##
# \file
# To each interface a set of caller functions exist, that take an instance
# of an object and then in turn call the implementation for the class of
# this object. If there is none within the class it looks into its
# parent class and so forth.
#
# This is somewhat similar to late binding in real OOP languages, but
# by far not so elaborated. This is not a real object oriented language
# and will surely never ever provide all features these have.
#
# That said it has proven very usefull for me to orgnize code and prevent
# code duplication.
#
# \author Georg Hopp
#
# \copyright
# Copyright © 2014 Georg Hopp
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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/>.
#
##
# if we are on a linux try to figure out wich distribution we are
# running.
# First look what kind of realease file we have:
#
# 00 01 - Novell SuSE ---> /etc/SuSE-release
# 00 02 - Red Hat ---> /etc/redhat-release, /etc/redhat_version
# 00 04 - Fedora ---> /etc/fedora-release
# 00 08 - Slackware ---> /etc/slackware-release, /etc/slackware-version
# 00 10 - Debian ---> /etc/debian_release, /etc/debian_version
# 00 20 - Mandrake ---> /etc/mandrake-release
# 00 40 - Yellow dog ---> /etc/yellowdog-release
# 00 80 - Sun JDS ---> /etc/sun-release
# 01 00 - Solaris/Sparc ---> /etc/release
# 02 00 - Gentoo ---> /etc/gentoo-release
#
# Here I follow a pessimistic way because I prefere to have no
# identification at all over a wrong one...so I check for all these files.
# If I can't find any or find multiple of them I assume this system
# as unidentified. Anyway when I found one I still check the content...
# Here I need some help as I don't know the valid content of these files.
# For now I assume that at least the name of the distribution is in
# the file.
#
gather_dist_info() {
[ -z "${DIST}" ] || return
case "${OS}" in
*Linux*)
local SUSE=1
local REDHAT=2
local FEDORA=4
local SLACKWARE=8
local DEBIAN=16
local MANDRAKE=32
local YELLOWDOG=64
local SUNJDS=128
local GENTOO=256
local SOLARIS=512
local LAST=${SOLARIS}
local CHK=$((SUSE|REDHAT|FEDORA|SLACKWARE|DEBIAN|MANDRAKE|\
YELLOWDOG|SUNJDS|GENTOO|SOLARIS))
eval local FILES_${SUSE}=\'/etc/SuSE-release\'
eval local FILES_${REDHAT}=\'/etc/redhat-release /etc/redhat_version\'
eval local FILES_${FEDORA}=\'/etc/fedora-release\'
eval local FILES_${SLACKWARE}=\'/etc/slackware-release /etc/slackware-version\'
eval local FILES_${DEBIAN}=\'/etc/debian_release /etc/debian_version\'
eval local FILES_${MANDRAKE}=\'/etc/mandrake-release\'
eval local FILES_${YELLOWDOG}=\'/etc/yellowdog-release\'
eval local FILES_${SUNJDS}=\'/etc/sun-release\'
eval local FILES_${GENTOO}=\'/etc/gentoo-release\'
eval local FILES_${SOLARIS}=\'/etc/release\'
local CUR=1
while [ ${CUR} -le ${LAST} ]
do
local DIR
eval local FILES=\"\${FILES_${CUR}}\"
for DIR in ${FILES}
do
[ -f ${DIR} ] || CHK=$((CHK&~CUR))
done
CUR=$((CUR*2))
done
DIST="Unknown"
[ ${CHK} -eq ${SUSE} ] && DIST="Suse"
[ ${CHK} -eq ${REDHAT} ] && DIST="Redhat"
[ ${CHK} -eq ${FEDORA} ] && DIST="Fedora"
[ ${CHK} -eq ${SLACKWARE} ] && DIST="Slakware"
[ ${CHK} -eq ${DEBIAN} ] && DIST="Debian"
[ ${CHK} -eq ${MANDRAKE} ] && DIST="Mandrake"
[ ${CHK} -eq ${YELLOWDOG} ] && DIST="Yellowdog"
[ ${CHK} -eq ${SUNJDS} ] && DIST="Sun"
[ ${CHK} -eq ${GENTOO} ] && DIST="Gentoo"
[ ${CHK} -eq ${SOLARIS} ] && DIST="Solaris"
if [ 'Unknown' != "${DIST}" ]
then
eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
fi
set_class ${DIST};;
*)
DIST="${OS}"
esac
export DIST
}
# vim: set ts=4 sw=4: