diff options
author | kate.ward <kate.ward@forestent.com> | 2008-06-17 16:38:35 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2008-06-17 16:38:35 +0000 |
commit | f51c61688f665b31f26c658cf389a9cd7843d4a9 (patch) | |
tree | 03db2704dfd65ad68896ecf95ab89fdea9dfeb25 /source/1.0/bin | |
download | shflags-f51c61688f665b31f26c658cf389a9cd7843d4a9.tar.gz |
initial check-in
Diffstat (limited to 'source/1.0/bin')
-rwxr-xr-x | source/1.0/bin/shell_versions.sh | 147 | ||||
-rwxr-xr-x | source/1.0/bin/version_info.sh | 146 |
2 files changed, 293 insertions, 0 deletions
diff --git a/source/1.0/bin/shell_versions.sh b/source/1.0/bin/shell_versions.sh new file mode 100755 index 0000000..ded0cb2 --- /dev/null +++ b/source/1.0/bin/shell_versions.sh @@ -0,0 +1,147 @@ +#! /bin/sh +# $Id: version_info.sh 165 2008-05-13 09:40:15Z sfsetse $ +# vim:et:ft=sh:sts=2:sw=2 +# +# Copyright (c) 2008 Forest Enterprises +# All Rights Reserved +# +# Author: Kate Ward (kate.ward@forestent.com) +# +# Released under the LGPL (GNU Lesser General Public License) + +# treat unset variables as an error +set -u + +#----------------------------------------------------------------------------- +# functions +# + +shellBash() +{ + _shell=$1 + + ${_shell} --version 2>&1 \ + |grep 'GNU bash' \ + |sed 's/.*version \([^ ]*\).*/\1/' +} + +shellDash() +{ + dpkg -l |grep ' dash ' |awk '{print $3}' +} + +shellKsh() +{ + _shell=$1 + + _version=`strings ${_shell} 2>&1 \ + |grep Version \ + |sed 's/^.*Version \(.*\)$/\1/;s/ s+ \$$//;s/ /-/g'` + [ -z "${_version}" ] && _version=`shellPdksh ${_shell}` + echo ${_version} +} + +shellPdksh() +{ + _shell=$1 + + strings ${_shell} 2>&1 \ + |grep 'PD KSH' \ + |sed -e 's/.*PD KSH \(.*\)/\1/;s/ /-/g' +} + +shellZsh() +{ + _shell=$1 + + echo 'echo ${ZSH_VERSION}' |${_shell} +} + +reportVersion() +{ + _shell=$1 + _version=$2 + + echo "shell:${_shell} version:${_version}" +} + +#----------------------------------------------------------------------------- +# main +# + +version='' + +os_system=`uname -s` +os_release=`uname -r` +case ${os_system} in + Cygwin) + version='unknown' + ;; + Darwin) + majorRelease='10' + subRelease=`echo ${os_release} |sed 's/^[0-9]*\.\([0-9]*\)\.[0-9]*$/\1/'` + case ${os_release} in + 8.*) minorRelease='4' ;; + 9.*) minorRelease='5' ;; + *) minorRelease='X'; subRelease='X' ;; + esac + os='Mac OS X' + version="${majorRelease}.${minorRelease}.${subRelease}" + ;; + Linux) + os='Linux' + if [ -r '/etc/lsb-release' ]; then + . /etc/lsb-release + version="${DISTRIB_ID}-${DISTRIB_RELEASE}" + fi + ;; + SunOS) + os='Solaris' + version=`echo ${os_release} |sed 's/[0-9]*\.\([0-9]*\)/\1/'` + ;; + *) + os='unknown' + version='unknown' + ;; +esac +echo "os:${os} version:${version}" + +# note: /bin/sh not included as it is nearly always a sym-link, and if it isn't +# it is too much trouble to figure out what it is. +SHELLS='/bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh' +for shell in ${SHELLS}; do + version='' + + if [ ! -x "${shell}" ]; then + reportVersion ${shell} 'not_installed' + continue + fi + + case ${shell} in + */sh) + # this could be one of any number of shells. try until one fits. + + version=`shellBash ${shell}` + # dash cannot be self determined yet + [ -z "${version}" ] && version=`shellKsh ${shell}` + # pdksh is covered in shellKsh() + [ -z "${version}" ] && version=`shellZsh ${shell}` + ;; + + */bash) version=`shellBash ${shell}` ;; + + */dash) + # simply assuming Ubuntu Linux until somebody comes up with a better + # test. the following test will return an empty string if dash is not + # installed. + version=`shellDash` + ;; + + */ksh) version=`shellKsh ${shell}` ;; + */pdksh) version=`shellPdksh ${shell}` ;; + */zsh) version=`shellZsh ${shell}` ;; + esac + + [ -z "${version}" ] && version='unknown' + reportVersion ${shell} "${version}" +done diff --git a/source/1.0/bin/version_info.sh b/source/1.0/bin/version_info.sh new file mode 100755 index 0000000..f88546e --- /dev/null +++ b/source/1.0/bin/version_info.sh @@ -0,0 +1,146 @@ +#! /bin/sh +# vim:et:ft=sh:sts=2:sw=2 +# +# Copyright (c) 2008 Kate Ward. All Rights Reserved +# Released under the LGPL (GNU Lesser General Public License) +# +# Author: Kate Ward (kate.ward@forestent.com) +# +# script to determine version info of various installed shells + +# treat unset variables as an error +set -u + +#----------------------------------------------------------------------------- +# functions +# + +shellBash() +{ + _shell=$1 + + ${_shell} --version 2>&1 \ + |grep 'GNU bash' \ + |sed 's/.*version \([^ ]*\).*/\1/' +} + +shellDash() +{ + dpkg -l |grep ' dash ' |awk '{print $3}' +} + +shellKsh() +{ + _shell=$1 + + _version=`strings ${_shell} 2>&1 \ + |grep Version \ + |sed 's/^.*Version \(.*\)$/\1/;s/ s+ \$$//;s/ /-/g'` + [ -z "${_version}" ] && _version=`shellPdksh ${_shell}` + echo ${_version} +} + +shellPdksh() +{ + _shell=$1 + + strings ${_shell} 2>&1 \ + |grep 'PD KSH' \ + |sed -e 's/.*PD KSH \(.*\)/\1/;s/ /-/g' +} + +shellZsh() +{ + _shell=$1 + + echo 'echo ${ZSH_VERSION}' |${_shell} +} + +reportVersion() +{ + _shell=$1 + _version=$2 + + echo "shell:${_shell} version:${_version}" +} + +#----------------------------------------------------------------------------- +# main +# + +version='' + +os_system=`uname -s` +os_release=`uname -r` +case ${os_system} in + Cygwin) + version='unknown' + ;; + Darwin) + majorRelease='10' + subRelease=`echo ${os_release} |sed 's/^[0-9]*\.\([0-9]*\)\.[0-9]*$/\1/'` + case ${os_release} in + 8.*) minorRelease='4' ;; + 9.*) minorRelease='5' ;; + *) minorRelease='X'; subRelease='X' ;; + esac + os='Mac OS X' + version="${majorRelease}.${minorRelease}.${subRelease}" + ;; + Linux) + os='Linux' + if [ -r '/etc/lsb-release' ]; then + . /etc/lsb-release + version="${DISTRIB_ID}-${DISTRIB_RELEASE}" + fi + ;; + SunOS) + os='Solaris' + version=`echo ${os_release} |sed 's/[0-9]*\.\([0-9]*\)/\1/'` + ;; + *) + os='unknown' + version='unknown' + ;; +esac +echo "os:${os} version:${version}" + +# note: /bin/sh not included as it is nearly always a sym-link, and if it isn't +# it is too much trouble to figure out what it is. +SHELLS='/bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh' +for shell in ${SHELLS}; do + version='' + + if [ ! -x "${shell}" ]; then + reportVersion ${shell} 'not_installed' + continue + fi + + case ${shell} in + */sh) + # this could be one of any number of shells. try until one fits. + + version=`shellBash ${shell}` + # dash cannot be self determined yet + [ -z "${version}" ] && version=`shellKsh ${shell}` + # pdksh is covered in shellKsh() + [ -z "${version}" ] && version=`shellZsh ${shell}` + ;; + + */bash) version=`shellBash ${shell}` ;; + + */dash) + # simply assuming Ubuntu Linux until somebody comes up with a better + # test. the following test will return an empty string if dash is not + # installed. + version=`shellDash` + ;; + + */ksh) version=`shellKsh ${shell}` ;; + */pdksh) version=`shellPdksh ${shell}` ;; + */zsh) version=`shellZsh ${shell}` ;; + esac + + [ -z "${version}" ] && version='unknown' + reportVersion ${shell} "${version}" +done |