Sat Aug 19 18:36:31 2017 UTC ()
Parse the arguments to sys_info(1) a bit differently, using getopts(1)

Thanks to Paul Goyette for the nudge


(agc)
diff -r1.2 -r1.3 src/usr.bin/sys_info/sys_info.sh

cvs diff -r1.2 -r1.3 src/usr.bin/sys_info/sys_info.sh (expand / switch to unified diff)

--- src/usr.bin/sys_info/sys_info.sh 2017/08/19 03:06:50 1.2
+++ src/usr.bin/sys_info/sys_info.sh 2017/08/19 18:36:31 1.3
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1#! /bin/sh 1#! /bin/sh
2 2
3# $NetBSD: sys_info.sh,v 1.2 2017/08/19 03:06:50 agc Exp $ 3# $NetBSD: sys_info.sh,v 1.3 2017/08/19 18:36:31 agc Exp $
4 4
5# Copyright (c) 2016 Alistair Crooks <agc@NetBSD.org> 5# Copyright (c) 2016 Alistair Crooks <agc@NetBSD.org>
6# All rights reserved. 6# All rights reserved.
7# 7#
8# Redistribution and use in source and binary forms, with or without 8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions 9# modification, are permitted provided that the following conditions
10# are met: 10# are met:
11# 1. Redistributions of source code must retain the above copyright 11# 1. Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer. 12# notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright 13# 2. Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the 14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution. 15# documentation and/or other materials provided with the distribution.
16# 16#
@@ -112,39 +112,40 @@ getversion() { @@ -112,39 +112,40 @@ getversion() {
112 unbound) 112 unbound)
113 case $(uname -s) in 113 case $(uname -s) in
114 FreeBSD) 114 FreeBSD)
115 unbound-control -h | awk '/^Version/ { print "unbound-" $2 }' 115 unbound-control -h | awk '/^Version/ { print "unbound-" $2 }'
116 ;; 116 ;;
117 esac 117 esac
118 ;; 118 ;;
119 xz) 119 xz)
120 xz --version | awk '{ print $1 "-" $4; exit }' 120 xz --version | awk '{ print $1 "-" $4; exit }'
121 ;; 121 ;;
122 esac 122 esac
123} 123}
124 124
125case $# in 125all=false
1260) all=true ;; 126while getopts "av" a; do
127*) all=false ;; 127 case "${a}" in
128esac 128 a) all=true ;;
129 129 v) set -x ;;
130while [ $# -gt 0 ]; do 
131 case "$1" in 
132 -a) all=true ;; 
133 -v) set -x ;; 
134 *) break ;; 130 *) break ;;
135 esac 131 esac
136 shift 132 shift
137done 133done
138 134
 135# if no arg specified, we want them all
 136if [ $# -eq 0 ]; then
 137 all=true
 138fi
 139
139# if we want to do every one, then let's get the arguments 140# if we want to do every one, then let's get the arguments
140# not really scalable 141# not really scalable
141if ${all}; then 142if ${all}; then
142 args='awk bind bzip2 calendar ftpd g++ gcc grep gzip httpd netbsd netpgp' 143 args='awk bind bzip2 calendar ftpd g++ gcc grep gzip httpd netbsd netpgp'
143 args="${args} netpgpverify ntp openssl sqlite ssh sshd tcsh unbound xz" 144 args="${args} netpgpverify ntp openssl sqlite ssh sshd tcsh unbound xz"
144 set -- ${args} 145 set -- ${args}
145fi 146fi
146 147
147while [ $# -gt 0 ]; do 148while [ $# -gt 0 ]; do
148 getversion $1 149 getversion $1
149 shift 150 shift
150done 151done