# distro.in: print distribution information
# $Id$
# Copyright (C) 2001-2002 Matthew R. MacIntyre <matt@pipfield.ca>
#
# 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.
#
VER="0.8.1+inkscape"
#
# Fatal($msg,$retval)
#
# Display an error message to stderr and exit
#
echo -e "${PN}: $1\nTerminating...." 1>&2
test -n "$2" && exit $2
exit 1
}
#
# Help()
#
# Display help information and exit
#
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
#
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
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
esac ;;
esac
done
#
# Find the contents from the appropriate file, and store it in
# $contents. Store the filename in $filename.
#
contents=""
filename=""
/etc/slackware-version /etc/.issue \
if test -f "$file"; then
else
fi
break
fi
done
if test -z "$filename"; then
Fatal "Cannot find distribution information"
fi
;;
;;
*) Fatal "Cannot find distribution information" ;;
esac
#
# Output the appropriate information
#
# FIXME: incorporate this bit into the case statement
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
name="debian"
name="ubuntu"
name="openlinux"
fi
;;
esac
fi
# Get the version number
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
# 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
# For ubuntu, steal it out of the contents report
# For debian, we have to determine them manually
esac
fi
if test -n "$codename"; then
echo "$codename"
fi
# 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
# 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
fi
fi
if test -n "$codename"; then
fi
# Strip out instances of too many spaces
echo "$string"
# It is done this way because the string for Solaris is a
# little different than the various versions of Linux
# Hmmmm .... some are a little different
name="Ubuntu Linux"
name="Slackware Linux"
fi
;;
esac
echo "$name"
*)
# Cut letters and spaces out up to the first number
;;
esac
echo "$release"
else
Fatal "Something unexpected has happened!"
fi
# All done.