Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ypserv/ypinit Switch from getopt to getopts - and a...



details:   https://anonhg.NetBSD.org/src/rev/0d111a95681b
branches:  trunk
changeset: 433590:0d111a95681b
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Sep 23 02:15:25 2018 +0000

description:
Switch from getopt to getopts - and as part of that, update the usage,
and the man page, to reflect modern usage rather than some ancient style
that getopt[s] does not support (options, and their args when they exist)
always come before non-option agrs.

While here, update uses of test(1) to avoid obsolescent forms (and
even when still defined, prefer sh structures over test when possible).

diffstat:

 usr.sbin/ypserv/ypinit/ypinit.8  |   8 +-
 usr.sbin/ypserv/ypinit/ypinit.sh |  93 ++++++++++++++++++---------------------
 2 files changed, 47 insertions(+), 54 deletions(-)

diffs (189 lines):

diff -r 9384dc6a1b27 -r 0d111a95681b usr.sbin/ypserv/ypinit/ypinit.8
--- a/usr.sbin/ypserv/ypinit/ypinit.8   Sun Sep 23 00:59:59 2018 +0000
+++ b/usr.sbin/ypserv/ypinit/ypinit.8   Sun Sep 23 02:15:25 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ypinit.8,v 1.17 2017/07/03 21:35:33 wiz Exp $
+.\"    $NetBSD: ypinit.8,v 1.18 2018/09/23 02:15:25 kre Exp $
 .\"
 .\" Copyright (c) 1997 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -36,17 +36,17 @@
 .Sh SYNOPSIS
 .Nm
 .Fl c
+.Op Fl l Ar server1,...,serverN
 .Op Ar domainname
-.Op Fl l Ar server1,...,serverN
 .Nm
 .Fl m
+.Op Fl l Ar server1,...,serverN
 .Op Ar domainname
-.Op Fl l Ar server1,...,serverN
 .Nm
 .Fl s
 .Ar master_server
+.Op Fl l Ar server1,...,serverN
 .Op Ar domainname
-.Op Fl l Ar server1,...,serverN
 .Sh DESCRIPTION
 .Nm
 initializes the files and directories that are required for a
diff -r 9384dc6a1b27 -r 0d111a95681b usr.sbin/ypserv/ypinit/ypinit.sh
--- a/usr.sbin/ypserv/ypinit/ypinit.sh  Sun Sep 23 00:59:59 2018 +0000
+++ b/usr.sbin/ypserv/ypinit/ypinit.sh  Sun Sep 23 02:15:25 2018 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-#      $NetBSD: ypinit.sh,v 1.13 2018/07/20 13:11:01 kre Exp $
+#      $NetBSD: ypinit.sh,v 1.14 2018/09/23 02:15:25 kre Exp $
 #
 # ypinit.sh - setup a master or slave YP server
 #
@@ -30,51 +30,44 @@
        exit 1
 fi
 
-args=$(getopt cl:ms: $*)               # XXX should switch to getopts
-if [ $? -eq 0 ]; then
-       set -- $args
-       for i; do
-               case $i in
-               "-c")
-                       servertype=client
-                       shift
-                       ;;
-               "-m")
-                       servertype=master
-                       shift
-                       ;;
-               "-s")
-                       servertype=slave
-                       master=${2}
-                       shift
-                       shift
-                       ;;
-               "-l")
-                       noninteractive=yes
-                       serverlist=${2}
-                       shift
-                       shift
-                       ;;
-               "--")
-                       shift
-                       break
-                       ;;
-               esac
-       done
+while getopts cl:ms: i
+do
+       case $i in
+       c)
+               servertype=client
+               ;;
+       l)
+               noninteractive=yes
+               serverlist=${OPTARG}
+               ;;
+       m)
+               servertype=master
+               ;;
+       s)
+               servertype=slave
+               master=${OPTARG}
+               ;;
+       \?)
+               echo >&2        # "Illegal option" message issued by getopts
+               servertype=     # force usage message just below
+               break
+               ;;
+       esac
+done
+shift $((OPTIND - 1))
 
-       if [ $# -eq 1 ]; then
-               domain=${1}
-               shift;
-       else
-               domain=$( ${BIN_DOMAINNAME} )
-       fi
+if [ $# -eq 1 ]; then
+       domain=${1}
+       shift;
+else
+       domain=$( ${BIN_DOMAINNAME} )
 fi
 
 if [ -z ${servertype} ]; then
        cat 1>&2 << __usage
-usage:         ${progname} -c [domainname] [-l server1,...,serverN]
-       ${progname} -m [domainname] [-l server1,...,serverN]
-       ${progname} -s master_server [domainname] [-l server1,...,serverN]
+usage:         ${progname} -c [-l server1,...,serverN] [domainname]
+       ${progname} -m [-l server1,...,serverN] [domainname]
+       ${progname} -s master_server [-l server1,...,serverN] [domainname]
 
 The \`-c' flag sets up a YP client, the \`-m' flag builds a master YP
 server, and the \`-s' flag builds a slave YP server.  When building a
@@ -104,14 +97,14 @@
 
        exit 1
 fi
-if [ "${servertype}" = "slave" -a "${host}" = "${master}" ]; then
+if [ "${servertype}" = slave ] && [ "${host}" = "${master}" ]; then
        echo 1>&2 \
            "$progname: cannot setup a YP slave server off the local host."
        exit 1
 fi
 
 # Check if the YP directory exists.
-if [ ! -d ${yp_dir} -o -f ${yp_dir} ]; then
+if ! [ -d "${yp_dir}" ]; then
        cat 1>&2 << __no_dir
 $progname: The directory ${yp_dir} does not exist.
        Restore it from the distribution.
@@ -128,7 +121,7 @@
 echo ""
 
 binding_dir=${yp_dir}/binding
-if [ ! -d ${binding_dir} ]; then
+if ! [ -d ${binding_dir} ]; then
        cat 1>&2 << __no_dir
 $progname: The directory ${binding_dir} does not exist.
        Restore it from the distribution.
@@ -152,13 +145,13 @@
 
 __list_of_servers
 
-               if [ "${servertype}" != "client" ]; then
-                       echo ${host} >> ${tmpfile}
+               if [ "${servertype}" != client ]; then
+                       echo "${host}" >> ${tmpfile}
                        echo "  next host: ${host}";
                fi
                echo -n "       next host: ";
 
-               while read nextserver ; test -n "${nextserver}"
+               while read nextserver && test -n "${nextserver}"
                do
                        echo ${nextserver} >> ${tmpfile}
                        echo -n "       next host: ";
@@ -249,8 +242,8 @@
 
 case ${servertype} in
 master)
-       if [ ! -f ${yp_dir}/Makefile ]; then
-               if [ ! -f ${yp_dir}/Makefile.main ]; then
+       if ! [ -f ${yp_dir}/Makefile ]; then
+               if ! [ -f ${yp_dir}/Makefile.main ]; then
                        echo 1>&2 \
                            "$progname: Can't find ${yp_dir}/Makefile.main"
                        exit 1
@@ -283,7 +276,7 @@
            ${yp_dir}/Makefile
        rm ${yp_dir}/Makefile.tmp
 
-       if [ ! -f ${yp_dir}/Makefile.yp ]; then
+       if ! [ -f ${yp_dir}/Makefile.yp ]; then
                echo 1>&2 "$progname: Can't find ${yp_dir}/Makefile.yp"
                exit 1
        fi



Home | Main Index | Thread Index | Old Index