NetBSD/usr.bin/sys_info/sys_info.sh
agc 3f81b60716 Following positive feedback on tech-userlevel, move the sys_info
script from othersrc to usr.bin/sys_info

	The sys_info script is a small script which will show the version
	information for installed utilities.  It also works on the kernel, and
	on most libraries.

	Its use is as follow:

		[19:41:13] agc@netbsd-002 ...external/bsd/sys_info [4568] > ./sys_info -a
		awk-20121220
		bind-9.10.3pl3
		bzip2-1.0.6
		calendar-20160601
		ftpd-20110904
		g++-4.8.5
		gcc-4.8.5
		grep-2.5.1anb1
		gzip-20150113
		bozohttpd-20151231
		NetBSD-7.99.26
		netpgp-3.99.17
		netpgpverify-20160214
		ntp-4.2.8pl5
		openssl-1.0.1r
		sqlite3-3.12.2
		openssh-7.1
		opensshd-7.1
		tcsh-6.19.00
		xz-5.2.1
		[19:41:20] agc@netbsd-002 ...external/bsd/sys_info [4569] > ./sys_info ntp ssh netpgp
		ntp-4.2.8pl5
		openssh-7.1
		netpgp-3.99.17
		[19:41:31] agc@netbsd-002 ...external/bsd/sys_info [4570] > ./sys_info ntp ssh netbsd
		ntp-4.2.8pl5
		openssh-7.1
		NetBSD-7.99.26
		[19:41:38] agc@netbsd-002 ...external/bsd/sys_info [4571] >

	The -a option can be given to the script to print out the information
	on all known components.

	The sys_info script also works on libraries, returning their
	"versions" as given by the shared object version numbers.

		[19:45:06] agc@netbsd-002 ...external/bsd/sys_info [4572] > ./sys_info libevent libXfont libc netbsd
		libevent-4.0
		libXfont-3.0
		libc-12.200
		NetBSD-7.99.26
		[19:45:27] agc@netbsd-002 ...external/bsd/sys_info [4573] >

	Alistair Crooks
	Wed Jun  1 19:44:01 PDT 2016
2016-06-04 15:27:11 +00:00

147 lines
4.0 KiB
Bash

#! /bin/sh
# $NetBSD: sys_info.sh,v 1.1 2016/06/04 15:27:11 agc Exp $
# Copyright (c) 2016 Alistair Crooks <agc@NetBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/usr/lib:/usr/X11R7/lib}
# print out the version for the given argument
getversion() {
case "$1" in
awk)
awk --version | awk '{ print $1 "-" $3 }'
;;
bind|named)
named -v | awk '{ gsub("-", "", $2); gsub("P", "pl", $2); print tolower($1) "-" $2 }'
;;
bzip2)
bzip2 --help 2>&1 | awk '{ sub(",", "", $7); print "bzip2-" $7; exit }'
;;
calendar)
v=$(calendar -v 2>/dev/null || true)
case "${v}" in
"") echo "calendar-20150701" ;;
*) echo ${v} ;;
esac
;;
ftpd)
strings -a /usr/libexec/ftpd | awk '$1 == "NetBSD-ftpd" { print "ftpd-" $2 }'
;;
g++|c++)
g++ --version | awk '{ print $1 "-" $4; exit }'
;;
gcc|cc)
gcc --version | awk '{ print $1 "-" $4; exit }'
;;
grep)
grep --version | awk '{ print $1 "-" $4 $5; exit }'
;;
gzip)
gzip --version 2>&1 | awk '{ print $2 "-" $3 }'
;;
httpd|bozohttpd)
v=$(/usr/libexec/httpd -G 2>/dev/null || true)
case "${v}" in
"")
strings -a /usr/libexec/httpd | awk -F/ '$1 == "bozohttpd" && NF == 2 { print $1 "-" $2; exit }'
;;
*)
echo bozohttpd-${v##*/}
;;
esac
;;
lib*)
dlist=$(echo ${LD_LIBRARY_PATH} | awk '{ gsub(":", " "); print }')
for d in ${dlist}; do
if [ -e ${d}/$1.so ]; then
ls -al ${d}/$1.so | awk '{ sub(".*/", "", $11); sub("\\.so\\.", "-", $11); print $11 }'
break
fi
done
;;
netbsd)
uname -sr | awk '{ print $1 "-" $2 }'
;;
netpgp)
netpgp -V | awk '{ sub("/.*", "", $3); print "netpgp-" $3; exit }'
;;
netpgpverify)
netpgpverify -v | awk '{ print $1 "-" $3 }'
;;
ntp)
ntpq --version | awk '{ sub("-.", ""); sub("p", "pl", $2); print "ntp-" $2 }'
;;
openssl)
openssl version 2>/dev/null | awk '{ print tolower($1) "-" $2 }'
;;
sqlite|sqlite3)
sqlite3 --version | awk '{ print "sqlite3-" $1 }'
;;
ssh|openssh)
ssh -V 2>&1 | awk '{ sub("_", "-", $1); print tolower($1) }'
;;
sshd)
sshd -V 2>&1 | awk '/OpenSSH/ { sub("_", "D-", $1); print tolower($1) }'
;;
tcsh)
tcsh -c 'echo $version' | awk '{ print $1 "-" $2 }'
;;
unbound)
case $(uname -s) in
FreeBSD)
unbound-control -h | awk '/^Version/ { print "unbound-" $2 }'
;;
esac
;;
xz)
xz --version | awk '{ print $1 "-" $4; exit }'
;;
esac
}
all=false
while [ $# -gt 0 ]; do
case "$1" in
-a) all=true ;;
-v) set -x ;;
*) break ;;
esac
shift
done
# if we want to do every one, then let's get the arguments
# not really scalable
if ${all}; then
args='awk bind bzip2 calendar ftpd g++ gcc grep gzip httpd netbsd netpgp'
args="${args} netpgpverify ntp openssl sqlite ssh sshd tcsh unbound xz"
set -- ${args}
fi
while [ $# -gt 0 ]; do
getversion $1
shift
done