1#! /bin/sh 2 3# $NetBSD: sys_info.sh,v 1.1 2016/06/04 15:27:11 agc Exp $ 4 5# Copyright (c) 2016 Alistair Crooks <agc@NetBSD.org> 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28 29LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/usr/lib:/usr/X11R7/lib} 30 31# print out the version for the given argument 32getversion() { 33 case "$1" in 34 awk) 35 awk --version | awk '{ print $1 "-" $3 }' 36 ;; 37 bind|named) 38 named -v | awk '{ gsub("-", "", $2); gsub("P", "pl", $2); print tolower($1) "-" $2 }' 39 ;; 40 bzip2) 41 bzip2 --help 2>&1 | awk '{ sub(",", "", $7); print "bzip2-" $7; exit }' 42 ;; 43 calendar) 44 v=$(calendar -v 2>/dev/null || true) 45 case "${v}" in 46 "") echo "calendar-20150701" ;; 47 *) echo ${v} ;; 48 esac 49 ;; 50 ftpd) 51 strings -a /usr/libexec/ftpd | awk '$1 == "NetBSD-ftpd" { print "ftpd-" $2 }' 52 ;; 53 g++|c++) 54 g++ --version | awk '{ print $1 "-" $4; exit }' 55 ;; 56 gcc|cc) 57 gcc --version | awk '{ print $1 "-" $4; exit }' 58 ;; 59 grep) 60 grep --version | awk '{ print $1 "-" $4 $5; exit }' 61 ;; 62 gzip) 63 gzip --version 2>&1 | awk '{ print $2 "-" $3 }' 64 ;; 65 httpd|bozohttpd) 66 v=$(/usr/libexec/httpd -G 2>/dev/null || true) 67 case "${v}" in 68 "") 69 strings -a /usr/libexec/httpd | awk -F/ '$1 == "bozohttpd" && NF == 2 { print $1 "-" $2; exit }' 70 ;; 71 *) 72 echo bozohttpd-${v##*/} 73 ;; 74 esac 75 ;; 76 lib*) 77 dlist=$(echo ${LD_LIBRARY_PATH} | awk '{ gsub(":", " "); print }') 78 for d in ${dlist}; do 79 if [ -e ${d}/$1.so ]; then 80 ls -al ${d}/$1.so | awk '{ sub(".*/", "", $11); sub("\\.so\\.", "-", $11); print $11 }' 81 break 82 fi 83 done 84 ;; 85 netbsd) 86 uname -sr | awk '{ print $1 "-" $2 }' 87 ;; 88 netpgp) 89 netpgp -V | awk '{ sub("/.*", "", $3); print "netpgp-" $3; exit }' 90 ;; 91 netpgpverify) 92 netpgpverify -v | awk '{ print $1 "-" $3 }' 93 ;; 94 ntp) 95 ntpq --version | awk '{ sub("-.", ""); sub("p", "pl", $2); print "ntp-" $2 }' 96 ;; 97 openssl) 98 openssl version 2>/dev/null | awk '{ print tolower($1) "-" $2 }' 99 ;; 100 sqlite|sqlite3) 101 sqlite3 --version | awk '{ print "sqlite3-" $1 }' 102 ;; 103 ssh|openssh) 104 ssh -V 2>&1 | awk '{ sub("_", "-", $1); print tolower($1) }' 105 ;; 106 sshd) 107 sshd -V 2>&1 | awk '/OpenSSH/ { sub("_", "D-", $1); print tolower($1) }' 108 ;; 109 tcsh) 110 tcsh -c 'echo $version' | awk '{ print $1 "-" $2 }' 111 ;; 112 unbound) 113 case $(uname -s) in 114 FreeBSD) 115 unbound-control -h | awk '/^Version/ { print "unbound-" $2 }' 116 ;; 117 esac 118 ;; 119 xz) 120 xz --version | awk '{ print $1 "-" $4; exit }' 121 ;; 122 esac 123} 124 125all=false 126while [ $# -gt 0 ]; do 127 case "$1" in 128 -a) all=true ;; 129 -v) set -x ;; 130 *) break ;; 131 esac 132 shift 133done 134 135# if we want to do every one, then let's get the arguments 136# not really scalable 137if ${all}; then 138 args='awk bind bzip2 calendar ftpd g++ gcc grep gzip httpd netbsd netpgp' 139 args="${args} netpgpverify ntp openssl sqlite ssh sshd tcsh unbound xz" 140 set -- ${args} 141fi 142 143while [ $# -gt 0 ]; do 144 getversion $1 145 shift 146done 147