sys_info.sh revision 1.6 1 #! /bin/sh
2
3 # $NetBSD: sys_info.sh,v 1.6 2017/08/21 19:36:57 agc Exp $
4
5 # Copyright (c) 2016 Alistair Crooks <agc (at] 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
29 SYS_INFO_VERSION=20170821
30 LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/usr/lib:/usr/X11R7/lib}
31
32 # short script to look for an executable $2, and if found, to place
33 # path in $1
34 # taken from pkgsrc bootstrap
35 which_prog()
36 {
37 _var="$1"; _name="$2"
38
39 eval _tmp=\"\$$_var\"
40 if [ "x$_tmp" != "x" ]; then
41 # Variable is already set (by the user, for example)
42 return 0
43 fi
44
45 for _d in `echo $PATH | tr ':' ' '`; do
46 if [ -f "$_d/$_name" ] && [ -x "$_d/$_name" ]; then
47 # Program found
48 eval $_var=\""$_d/$_name"\"
49 return 0
50 fi
51 done
52
53 return 1
54 }
55
56 # print out the version for the given argument
57 getversion() {
58 case "$1" in
59 awk)
60 awk --version | awk '{ print $1 "-" $3 }'
61 ;;
62 bind|named)
63 named -v | awk '{ gsub("-", "", $2); gsub("P", "pl", $2); print tolower($1) "-" $2 }'
64 ;;
65 bzip2)
66 bzip2 --help 2>&1 | awk '{ sub(",", "", $7); print "bzip2-" $7; exit }'
67 ;;
68 calendar)
69 v=$(calendar -v 2>/dev/null || true)
70 case "${v}" in
71 "") echo "calendar-20150701" ;;
72 *) echo ${v} ;;
73 esac
74 ;;
75 ftpd)
76 strings -a /usr/libexec/ftpd | awk '$1 == "NetBSD-ftpd" { print "ftpd-" $2 }'
77 ;;
78 g++|c++)
79 g++ --version | awk '{ print $1 "-" $4; exit }'
80 ;;
81 gcc|cc)
82 gcc --version | awk '{ print $1 "-" $4; exit }'
83 ;;
84 grep)
85 grep --version | awk '{ print $1 "-" $4 $5; exit }'
86 ;;
87 gzip)
88 gzip --version 2>&1 | awk '{ print $2 "-" $3 }'
89 ;;
90 httpd|bozohttpd)
91 v=$(/usr/libexec/httpd -G 2>/dev/null || true)
92 case "${v}" in
93 "")
94 strings -a /usr/libexec/httpd | awk -F/ '$1 == "bozohttpd" && NF == 2 { print $1 "-" $2; exit }'
95 ;;
96 *)
97 echo bozohttpd-${v##*/}
98 ;;
99 esac
100 ;;
101 lib*)
102 dlist=$(echo ${LD_LIBRARY_PATH} | awk '{ gsub(":", " "); print }')
103 for d in ${dlist}; do
104 if [ -e ${d}/$1.so ]; then
105 ls -al ${d}/$1.so | awk '{ sub(".*/", "", $11); sub("\\.so\\.", "-", $11); print $11 }'
106 break
107 fi
108 done
109 ;;
110 netbsd)
111 uname -sr | awk '{ print $1 "-" $2 }'
112 ;;
113 netpgp)
114 netpgp -V | awk '{ sub("/.*", "", $3); print "netpgp-" $3; exit }'
115 ;;
116 netpgpverify)
117 netpgpverify -v | awk '{ print $1 "-" $3 }'
118 ;;
119 ntp)
120 ntpq --version | awk '{ sub("-.", ""); sub("p", "pl", $2); print "ntp-" $2 }'
121 ;;
122 openssl)
123 openssl version 2>/dev/null | awk '{ print tolower($1) "-" $2 }'
124 ;;
125 sqlite|sqlite3)
126 sqlite3 --version | awk '{ print "sqlite3-" $1 }'
127 ;;
128 ssh|openssh)
129 ssh -V 2>&1 | awk '{ sub("_", "-", $1); print tolower($1) }'
130 ;;
131 sshd)
132 sshd -V 2>&1 | awk '/OpenSSH/ { sub("_", "D-", $1); print tolower($1) }'
133 ;;
134 sys_info)
135 echo sys_info-${SYS_INFO_VERSION}
136 ;;
137 tcsh)
138 if which_prog tcshpath tcsh; then
139 ${tcshpath} --version | awk '{ print $1 "-" $2 }'
140 else
141 echo "tcsh: not found"
142 fi
143 ;;
144 unbound)
145 if which_prog unboundpath unbound-control; then
146 ${unboundpath} -h | awk '/^Version/ { print "unbound-" $2 }'
147 else
148 echo "unbound: not found"
149 fi
150 ;;
151 xz)
152 xz --version | awk '{ print $1 "-" $4; exit }'
153 ;;
154 esac
155 }
156
157 # check if we have our only option
158 while [ $# -gt 0 ]; do
159 case "$1" in
160 -v) set -x ;;
161 *) break ;;
162 esac
163 shift
164 done
165
166 all=false
167 # if no arg specified, we want them all
168 if [ $# -eq 0 ]; then
169 all=true
170 fi
171
172 # if we want to do every one, then let's get the arguments
173 # not really scalable
174 if ${all}; then
175 args='awk bind bzip2 calendar ftpd g++ gcc grep gzip httpd netbsd netpgp'
176 args="${args} netpgpverify ntp openssl sqlite ssh sshd sys_info tcsh"
177 args="${args} unbound xz"
178 else
179 args=$(echo $@ | tr ' ' '\n' | sort | uniq)
180 fi
181 set -- ${args}
182
183 while [ $# -gt 0 ]; do
184 getversion $1
185 shift
186 done
187