Code

Use subdirectories with icon sizes.
[inkscape.git] / distro
1 #! /bin/sh
2 # distro.in: print distribution information
3 # $Id$
5 # Copyright (C) 2001-2002 Matthew R. MacIntyre <matt@pipfield.ca>
6 #  
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #  
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #  
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #  
22 PN=`basename $0`
23 VER="0.8.1+inkscape"
25 #
26 # Fatal($msg,$retval)
27
28 # Display an error message to stderr and exit
29 #
30 Fatal () {
31     echo -e "${PN}: $1\nTerminating...." 1>&2
32     test -n "$2" && exit $2
33     exit 1
34 }
37 #
38 # Help()
39 #
40 # Display help information and exit
41 #
42 Help () {
43     cat <<EOF
44 Usage: ${PN} [OPTION]...
45 Print certain distribution information.  With no OPTION, same as -f.
47 Options:
48   -a, --all        print all information
49   -c, --codename   print the distribution code name
50   -f, --ftp-name   print the ftp name of the distribution
51   -n, --name       print the distribution name
52   -r, --release    print the distribution release
53   -h, --help       display this help and exit
54   -v, --version    output version information and exit
56 Report bugs to <matt@pipfield.ca>.
57 EOF
58     exit 0
59 }
61 #
62 # Version()
63 #
64 # Display version information and exit
65 #
66 Version () {
67     cat <<EOF
68 ${PN} v${VER}
70 Written by Matthew R. MacIntyre.
72 Copyright (c) 2001-2002 Matthew R. MacIntyre.
73 This is free software; see the source for copying conditions. There is NO
74 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75 EOF
76     exit 0
77 }
80 #######################
81 # Program starts here #
82 #######################
84 #
85 # Set initial values for our configuration variables
86 #
87 ALL=0
88 CODENAME=0
89 FTPNAME=0
90 NAME=0
91 RELEASE=0
94
95 # Parse the command-line arguments
96 #
98 OPTERR=0
99 while getopts "\-:acfhnrv" opt; do
100     case $opt in
101         h) Help; shift ;;
102         v) Version; shift ;;
103         a) ALL=1 ; shift; break;;
104         c) CODENAME=1; shift; break;;
105         f) FTPNAME=1; shift; break;;
106         n) NAME=1; shift; break;;
107         r) RELEASE=1; shift; break;;
108         -) # long options
109            case "$OPTARG" in
110                 help) Help; shift ;;
111                 version) Version; shift ;;
112                 all) ALL=1 ; shift ; break ;;
113                 codename) CODENAME=1 ; shift ; break ;;
114                 ftp-name) FTPNAME=1 ; shift ; break ;;
115                 name) NAME=1; shift ; break ;;
116                 release) RELEASE=1; shift ; break ;;
117                 *) Fatal "Illegal option -- \"--$OPTARG\"\nTry ${PN} --help for more information." 1 ;;
118            esac ;;
119         *) Fatal "Illegal option -- \"-$OPTARG\"\nTry ${PN} --help for more information." 1 ;;
120     esac
121 done
124 # Find the contents from the appropriate file, and store it in
125 # $contents.  Store the filename in $filename.
127 contents=""
128 filename=""
130 case "`uname`" in
131     OpenBSD|FreeBSD|NetBSD|CYGWIN*) contents="`uname -a`" ;;
132     Linux)
133         files="/etc/mandrake-release /etc/SuSE-release \
134                 /usr/share/doc/ubuntu-base/changelog.gz \
135                 /etc/redhat-release /etc/debian_version \
136                 /etc/slackware-version /etc/.issue \
137                 /etc/ROCK-LINUX /etc/gentoo-release"
138         for file in $files; do
139             if test -f "$file"; then
140                 filename="$file"
141                 if test -n "`echo $filename | grep ubuntu`"; then
142                     contents="`cat /etc/issue`"
143                 else
144                     contents="`cat $file`"
145                 fi
146                 break
147             fi
148         done
149         if test -z "$filename"; then
150             Fatal "Cannot find distribution information"
151         fi
152         ;; 
153     SunOS)
154         contents="`cat /etc/release`"
155         filename='/etc/release'
156         ;;
157     *) Fatal "Cannot find distribution information" ;;
158 esac
162 # Output the appropriate information
164 sum="`expr $ALL + $CODENAME + $FTPNAME + $NAME + $RELEASE`"
165 if test $sum -eq 0 || test $FTPNAME -eq 1; then
166     # FIXME: incorporate this bit into the case statement
167     if ! test -n "`echo $filename | grep ubuntu`"; then
168       name="`echo $filename | sed -e 's|/etc/||' -e 's|-*release$||' -e 's|[-_]version$||' -e 's|\.issue||' |  tr '[A-Z]' '[a-z]' | tr -d '-'`"
169     fi
170     # If that didn't work, then we likely have Solaris, Debian,
171     # FreeBSD, or maybe even ROCK LINUX
172     
173     if test -z "$name"; then
174         case "`uname`" in
175             CYGWIN*) name="cygwin" ;;
176             OpenBSD|FreeBSD|NetBSD) name="`uname | tr '[A-Z]' '[a-z]'`" ;;
177             Linux)
178                 if test -n "`grep debian $filename`"; then
179                     name="debian"
180                 elif test -n "`echo $filename | grep ubuntu`"; then
181                     name="ubuntu"
182                 elif test -n "`grep -i caldera $filename`"; then
183                      name="openlinux"
184                 fi   
185                 ;;
186             SunOS) name="solaris" ;;
187             *)  Fatal "Cannot determine ftp-name for this system: `uname`" 1 ;;
188         esac
189     fi    
191     # Get the version number
192     case $name in
193         cygwin) version="`uname -r | sed -e 's!\.!!g' -e 's!^\([0-9][0-9]*\).*$!\1!'`" ;;
194         debian) version="`sed -e 's!\.!!'g -e 's!^testing/!-!' $filename`" ;;
195         ubuntu) version="`echo $contents | awk '{print $2}'`" ;;
196         freebsd) version="`uname -r | sed -e 's!\([0-9][0-9]*\)\.\([0-9][0-9]*\).*!\1\2!'`" ;;
197         openbsd|netbsd) version="`uname -r | sed -e 's!\.!!g'`" ;;
198         rocklinux)  version="`sed -e 's!^.*Linux \([0-9]\.[0-9]\.*[0-9]*\).*$!\1!' $filename | tr -d '.' | sed -e 's!0$!!'`" ;;
199         slackware) version="`sed -e 's!\.!!g' -e 's!\([0-9]*\).*$!\1!' -e 's!\([0-9][0-9]*\)0$!\1!' $filename`" ;;
200         solaris) version="`echo $contents | sed -e 's!^European !!' -e 's!^Solaris \([0-9]\.*[0-9]*\) .*$!\1!' -e 's!\.!!g'`" ;;
201         *)
202           # This is just a reasonable guess
203           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!'`" ;;
204     esac
205     echo "$name$version"
206 elif test $CODENAME -eq 1 ; then
207     # Certain systems (Solaris) don't have codenames.  This checks to see 
208     # if there is one before figuring out what it is
209     codename=""
210     # check for a codename, but strip out the *BSD stuff, a misleading entry in ROCK-Linux,
211     # and an ix86 bit in the various SuSE releases.
212     if test -n "`echo $contents | sed -e 's!(GENERIC)!!' -e 's!(native, .*)!!' -e 's!(i[3456]86)!!' | egrep "^.* \(.*\).*$"`"; then
213         codename="`echo $contents | sed -e 's!.*(\(.*\)).*$!\1!'`"
214     elif test -n "`echo $filename | grep ubuntu`"; then
215         # For ubuntu, steal it out of the contents report
216         codename="`echo $contents | awk -F\\\" '{print $2}'`"
217     elif test -n "`echo $filename | grep debian`"; then
218         # For debian, we have to determine them manually
219         case "`cat $filename`" in
220                     testing/unstable) codename='etch/sid' ;;
221                     3.1) codename='sarge' ;;
222                     3.0) codename='woody' ;;
223                     2.2) codename='potato' ;;
224                     2.1) codename='slink' ;;
225                     2.0) codename='hamm' ;;
226                     1.3*) codename='bo' ;;
227                     1.2) codename='rex' ;;
228                     1.1) codename='buzz' ;;
229         esac
230     fi
231     if test -n "$codename"; then
232         echo "$codename"
233     fi
234 elif test $ALL -eq 1 ; then
235     # Call the script recursively to get the desired string, since the
236     # Solaris format isn't the same.  It is done through sh as a hack
237     # to help when developing the script, and it isn't executable
238     string=`sh "$0" --name`
239     if test x"`uname`" = x"Linux"; then
240         # We only want to add the word "release" for Linux
241         # distributions.  It's  not a convention to use the word
242         # "release" for any other type of system.
244         # Don't add the word 'release' if we're on debian testing
245         if test x"`sh $0 --release`" != x"testing/unstable"; then
246             string="$string release"
247         fi
248     fi
249     string="$string `sh $0 --release`"
250     codename=`sh "$0" --codename`
251     if test -n "$codename"; then
252         string="$string ($codename)"
253     fi
254     # Strip out instances of too many spaces
255     string="`echo $string | tr -s ' '`"
256     echo "$string"
257 elif test $NAME -eq 1 ; then
258     case "`uname`" in
259         Linux|SunOS)
260             # It is done this way because the string for Solaris is a
261             # little different than the various versions of Linux
262             name="`echo $contents | sed -e 's![0-9].*$!!' -e 's![\ ]*release[\ ]*!!' -e 's![\ ][\ ]*$!!g'`" 
263             # Hmmmm .... some are a little different
264             if test -n "`echo $filename | grep debian`"; then
265                 name="Debian GNU/Linux"
266             elif test -n "`echo $filename | grep ubuntu`"; then
267                 name="Ubuntu Linux"
268             elif test -n "`echo $filename | grep slackware`"; then
269                 name="Slackware Linux"
270             fi
271             ;;
272         CYGWIN*) name="Cygwin" ;; # FIXME: not sure if we have to differentiate between NT and others
273         *) name="`uname`" ;;
274     esac
275     echo "$name"
276 elif test $RELEASE -eq 1 ; then
277     case "`uname`" in
278         OpenBSD|FreeBSD|NetBSD|CYGWIN*) release="`uname -r | sed -e 's!(.*$!!'`" ;;
279         *)
280             # Cut letters and spaces out up to the first number
281             release="`echo $contents | sed -e 's!^[A-Za-z\ ]*\([0-9]\.*[0-9]*\.*[0-9]*[a-z]*\).*$!\1!'`"
282             ;;
283     esac
284     echo "$release"
285 else
286     Fatal "Something unexpected has happened!"
287 fi
289 # All done.