Module Name: src Committed By: agc Date: Mon Aug 21 19:22:31 UTC 2017
Modified Files: src/usr.bin/sys_info: sys_info.1 sys_info.sh Log Message: Changes to sys_info (20170821) + get rid of -a argument, which was superfluous since no arguments means provide information on everything known + add the shell function to check for the path of a program. Taken from pkgsrc bootstrap script, modified for return values, and "not found" action + use this shell function for tcsh and unbound, both of which may not exist on systems + go back to using standard shell construct for parsing options now, since there is only 1 option with no optargs + from a suggestion from Paul Goyette, run the provided arguments through sort | uniq + add sys_info itself to the list of programs to report To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.bin/sys_info/sys_info.1 cvs rdiff -u -r1.4 -r1.5 src/usr.bin/sys_info/sys_info.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/sys_info/sys_info.1 diff -u src/usr.bin/sys_info/sys_info.1:1.1 src/usr.bin/sys_info/sys_info.1:1.2 --- src/usr.bin/sys_info/sys_info.1:1.1 Sat Jun 4 15:27:11 2016 +++ src/usr.bin/sys_info/sys_info.1 Mon Aug 21 19:22:31 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: sys_info.1,v 1.1 2016/06/04 15:27:11 agc Exp $ +.\" $NetBSD: sys_info.1,v 1.2 2017/08/21 19:22:31 agc Exp $ .\" .\" Copyright (c) 2016 Alistair Crooks <a...@netbsd.org> .\" All rights reserved. @@ -23,7 +23,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd June 1, 2016 +.Dd August 21, 2017 .Dt SYS_INFO 1 .Os .Sh NAME @@ -31,7 +31,7 @@ .Nd script to show versioning information .Sh SYNOPSIS .Nm -.Op Fl av +.Op Fl v .Op Ar .Sh DESCRIPTION The @@ -44,13 +44,23 @@ The utility uses a combination of ways to retrieve version information from the installed utilities. .Sh OPTIONS -The following options are available: +The following option is available: .Bl -tag -width inits -.It Fl a -Show the version numbers of all components. .It Fl v -Perform the operations in a verbose manner. +Perform operations in a verbose manner. .El +.Pp +Arguments may be given to sys_info. +If any arguments are specified, they are assumed +to be names of programs, or shared libraries, +installed on the system. +If no arguments are provided, then all of the +items that are known to +.Nm +are reported. +.Pp +If arguments are provided, the output is displayed in +alphabetical order, and duplicates are removed. .Sh SEE ALSO .Xr awk 1 , .Xr strings 1 Index: src/usr.bin/sys_info/sys_info.sh diff -u src/usr.bin/sys_info/sys_info.sh:1.4 src/usr.bin/sys_info/sys_info.sh:1.5 --- src/usr.bin/sys_info/sys_info.sh:1.4 Sun Aug 20 10:17:55 2017 +++ src/usr.bin/sys_info/sys_info.sh Mon Aug 21 19:22:31 2017 @@ -1,6 +1,6 @@ #! /bin/sh -# $NetBSD: sys_info.sh,v 1.4 2017/08/20 10:17:55 martin Exp $ +# $NetBSD: sys_info.sh,v 1.5 2017/08/21 19:22:31 agc Exp $ # Copyright (c) 2016 Alistair Crooks <a...@netbsd.org> # All rights reserved. @@ -26,8 +26,33 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # +SYS_INFO_VERSION=20170821 LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/usr/lib:/usr/X11R7/lib} +# short script to look for an executable $2, and if found, to place +# path in $1 +# taken from pkgsrc bootstrap +which_prog() +{ + _var="$1"; _name="$2" + + eval _tmp=\"\$$_var\" + if [ "x$_tmp" != "x" ]; then + # Variable is already set (by the user, for example) + return 0 + fi + + for _d in `echo $PATH | tr ':' ' '`; do + if [ -f "$_d/$_name" ] && [ -x "$_d/$_name" ]; then + # Program found + eval $_var=\""$_d/$_name"\" + return 0 + fi + done + + return 1 +} + # print out the version for the given argument getversion() { case "$1" in @@ -106,15 +131,22 @@ getversion() { sshd) sshd -V 2>&1 | awk '/OpenSSH/ { sub("_", "D-", $1); print tolower($1) }' ;; + sys_info) + echo sys_info-${SYS_INFO_VERSION} + ;; tcsh) - grep '/tcsh' /etc/shells > /dev/null 2>&1 && tcsh --version | awk '{ print $1 "-" $2 }' + if which_prog tcshpath tcsh; then + ${tcshpath} -c 'echo $version' | awk '{ print $1 "-" $2 }' + else + echo "tcsh: not found" + fi ;; unbound) - case $(uname -s) in - FreeBSD) - unbound-control -h | awk '/^Version/ { print "unbound-" $2 }' - ;; - esac + if which_prog unboundpath unbound-control; then + ${unboundpath} -h | awk '/^Version/ { print "unbound-" $2 }' + else + echo "unbound: not found" + fi ;; xz) xz --version | awk '{ print $1 "-" $4; exit }' @@ -122,16 +154,16 @@ getversion() { esac } -all=false -while getopts "av" a; do - case "${a}" in - a) all=true ;; - v) set -x ;; +# check if we have our only option +while [ $# -gt 0 ]; do + case "$1" in + -v) set -x ;; *) break ;; esac shift done +all=false # if no arg specified, we want them all if [ $# -eq 0 ]; then all=true @@ -141,9 +173,12 @@ fi # 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} + args="${args} netpgpverify ntp openssl sqlite ssh sshd sys_info tcsh" + args="${args} unbound xz" +else + args=$(echo $@ | tr ' ' '\n' | sort | uniq) fi +set -- ${args} while [ $# -gt 0 ]; do getversion $1