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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
#! /bin/sh
# distro.in: print distribution information
# $Id$
# Copyright (C) 2001-2002 Matthew R. MacIntyre <matt@pipfield.ca>
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
PN=`basename $0`
VER="0.8.1+inkscape"
#
# Fatal($msg,$retval)
#
# Display an error message to stderr and exit
#
Fatal () {
echo -e "${PN}: $1\nTerminating...." 1>&2
test -n "$2" && exit $2
exit 1
}
#
# Help()
#
# Display help information and exit
#
Help () {
cat <<EOF
Usage: ${PN} [OPTION]...
Print certain distribution information. With no OPTION, same as -f.
Options:
-a, --all print all information
-c, --codename print the distribution code name
-f, --ftp-name print the ftp name of the distribution
-n, --name print the distribution name
-r, --release print the distribution release
-h, --help display this help and exit
-v, --version output version information and exit
Report bugs to <matt@pipfield.ca>.
EOF
exit 0
}
#
# Version()
#
# Display version information and exit
#
Version () {
cat <<EOF
${PN} v${VER}
Written by Matthew R. MacIntyre.
Copyright (c) 2001-2002 Matthew R. MacIntyre.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit 0
}
#######################
# Program starts here #
#######################
#
# Set initial values for our configuration variables
#
ALL=0
CODENAME=0
FTPNAME=0
NAME=0
RELEASE=0
#
# Parse the command-line arguments
#
OPTERR=0
while getopts "\-:acfhnrv" opt; do
case $opt in
h) Help; shift ;;
v) Version; shift ;;
a) ALL=1 ; shift; break;;
c) CODENAME=1; shift; break;;
f) FTPNAME=1; shift; break;;
n) NAME=1; shift; break;;
r) RELEASE=1; shift; break;;
-) # long options
case "$OPTARG" in
help) Help; shift ;;
version) Version; shift ;;
all) ALL=1 ; shift ; break ;;
codename) CODENAME=1 ; shift ; break ;;
ftp-name) FTPNAME=1 ; shift ; break ;;
name) NAME=1; shift ; break ;;
release) RELEASE=1; shift ; break ;;
*) Fatal "Illegal option -- \"--$OPTARG\"\nTry ${PN} --help for more information." 1 ;;
esac ;;
*) Fatal "Illegal option -- \"-$OPTARG\"\nTry ${PN} --help for more information." 1 ;;
esac
done
#
# Find the contents from the appropriate file, and store it in
# $contents. Store the filename in $filename.
#
contents=""
filename=""
case "`uname`" in
OpenBSD|FreeBSD|NetBSD|CYGWIN*) contents="`uname -a`" ;;
Linux)
files="/etc/mandrake-release /etc/SuSE-release \
/usr/share/doc/ubuntu-base/changelog.gz \
/etc/redhat-release /etc/debian_version \
/etc/slackware-version /etc/.issue \
/etc/ROCK-LINUX /etc/gentoo-release"
for file in $files; do
if test -f "$file"; then
filename="$file"
if test -n "`echo $filename | grep ubuntu`"; then
contents="`cat /etc/issue`"
else
contents="`cat $file`"
fi
break
fi
done
if test -z "$filename"; then
Fatal "Cannot find distribution information"
fi
;;
SunOS)
contents="`cat /etc/release`"
filename='/etc/release'
;;
*) Fatal "Cannot find distribution information" ;;
esac
#
# Output the appropriate information
#
sum="`expr $ALL + $CODENAME + $FTPNAME + $NAME + $RELEASE`"
if test $sum -eq 0 || test $FTPNAME -eq 1; then
# FIXME: incorporate this bit into the case statement
if ! test -n "`echo $filename | grep ubuntu`"; then
name="`echo $filename | sed -e 's|/etc/||' -e 's|-*release$||' -e 's|[-_]version$||' -e 's|\.issue||' | tr '[A-Z]' '[a-z]' | tr -d '-'`"
fi
# If that didn't work, then we likely have Solaris, Debian,
# FreeBSD, or maybe even ROCK LINUX
if test -z "$name"; then
case "`uname`" in
CYGWIN*) name="cygwin" ;;
OpenBSD|FreeBSD|NetBSD) name="`uname | tr '[A-Z]' '[a-z]'`" ;;
Linux)
if test -n "`grep debian $filename`"; then
name="debian"
elif test -n "`echo $filename | grep ubuntu`"; then
name="ubuntu"
elif test -n "`grep -i caldera $filename`"; then
name="openlinux"
fi
;;
SunOS) name="solaris" ;;
*) Fatal "Cannot determine ftp-name for this system: `uname`" 1 ;;
esac
fi
# Get the version number
case $name in
cygwin) version="`uname -r | sed -e 's!\.!!g' -e 's!^\([0-9][0-9]*\).*$!\1!'`" ;;
debian) version="`sed -e 's!\.!!'g -e 's!^testing/!-!' $filename`" ;;
ubuntu) version="`echo $contents | awk '{print $2}'`" ;;
freebsd) version="`uname -r | sed -e 's!\([0-9][0-9]*\)\.\([0-9][0-9]*\).*!\1\2!'`" ;;
openbsd|netbsd) version="`uname -r | sed -e 's!\.!!g'`" ;;
rocklinux) version="`sed -e 's!^.*Linux \([0-9]\.[0-9]\.*[0-9]*\).*$!\1!' $filename | tr -d '.' | sed -e 's!0$!!'`" ;;
slackware) version="`sed -e 's!\.!!g' -e 's!\([0-9]*\).*$!\1!' -e 's!\([0-9][0-9]*\)0$!\1!' $filename`" ;;
solaris) version="`echo $contents | sed -e 's!^European !!' -e 's!^Solaris \([0-9]\.*[0-9]*\) .*$!\1!' -e 's!\.!!g'`" ;;
*)
# This is just a reasonable guess
version="`echo $contents | sed -n '1,1'p | sed -e 's!.*\([0-9][0-9]*\.[0-9][0-9]*[a-z]*\).*!\1!' -e 's!\([0-9][0-9]*\)\.\([0-9][0-9]*[a-z]*\)!\1\2!'`" ;;
esac
echo "$name$version"
elif test $CODENAME -eq 1 ; then
# Certain systems (Solaris) don't have codenames. This checks to see
# if there is one before figuring out what it is
codename=""
# check for a codename, but strip out the *BSD stuff, a misleading entry in ROCK-Linux,
# and an ix86 bit in the various SuSE releases.
if test -n "`echo $contents | sed -e 's!(GENERIC)!!' -e 's!(native, .*)!!' -e 's!(i[3456]86)!!' | egrep "^.* \(.*\).*$"`"; then
codename="`echo $contents | sed -e 's!.*(\(.*\)).*$!\1!'`"
elif test -n "`echo $filename | grep ubuntu`"; then
# For ubuntu, steal it out of the contents report
codename="`echo $contents | awk -F\\\" '{print $2}'`"
elif test -n "`echo $filename | grep debian`"; then
# For debian, we have to determine them manually
case "`cat $filename`" in
testing/unstable) codename='etch/sid' ;;
3.1) codename='sarge' ;;
3.0) codename='woody' ;;
2.2) codename='potato' ;;
2.1) codename='slink' ;;
2.0) codename='hamm' ;;
1.3*) codename='bo' ;;
1.2) codename='rex' ;;
1.1) codename='buzz' ;;
esac
fi
if test -n "$codename"; then
echo "$codename"
fi
elif test $ALL -eq 1 ; then
# Call the script recursively to get the desired string, since the
# Solaris format isn't the same. It is done through sh as a hack
# to help when developing the script, and it isn't executable
string=`sh "$0" --name`
if test x"`uname`" = x"Linux"; then
# We only want to add the word "release" for Linux
# distributions. It's not a convention to use the word
# "release" for any other type of system.
# Don't add the word 'release' if we're on debian testing
if test x"`sh $0 --release`" != x"testing/unstable"; then
string="$string release"
fi
fi
string="$string `sh $0 --release`"
codename=`sh "$0" --codename`
if test -n "$codename"; then
string="$string ($codename)"
fi
# Strip out instances of too many spaces
string="`echo $string | tr -s ' '`"
echo "$string"
elif test $NAME -eq 1 ; then
case "`uname`" in
Linux|SunOS)
# It is done this way because the string for Solaris is a
# little different than the various versions of Linux
name="`echo $contents | sed -e 's![0-9].*$!!' -e 's![\ ]*release[\ ]*!!' -e 's![\ ][\ ]*$!!g'`"
# Hmmmm .... some are a little different
if test -n "`echo $filename | grep debian`"; then
name="Debian GNU/Linux"
elif test -n "`echo $filename | grep ubuntu`"; then
name="Ubuntu Linux"
elif test -n "`echo $filename | grep slackware`"; then
name="Slackware Linux"
fi
;;
CYGWIN*) name="Cygwin" ;; # FIXME: not sure if we have to differentiate between NT and others
*) name="`uname`" ;;
esac
echo "$name"
elif test $RELEASE -eq 1 ; then
case "`uname`" in
OpenBSD|FreeBSD|NetBSD|CYGWIN*) release="`uname -r | sed -e 's!(.*$!!'`" ;;
*)
# Cut letters and spaces out up to the first number
release="`echo $contents | sed -e 's!^[A-Za-z\ ]*\([0-9]\.*[0-9]*\.*[0-9]*[a-z]*\).*$!\1!'`"
;;
esac
echo "$release"
else
Fatal "Something unexpected has happened!"
fi
# All done.
|