From 05b8a51e6ef6ee7e2db8af0fecfc8840bcb58652 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Tue, 31 Mar 2015 09:18:06 +0200 Subject: argument parsing piff-up --- scripts/mkreq | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/scripts/mkreq b/scripts/mkreq index 4493867..c5e8e9f 100755 --- a/scripts/mkreq +++ b/scripts/mkreq @@ -1,6 +1,5 @@ #!/bin/sh -host="$1"; shift ca_host="ca.sunet.se" ca_name="infra" type="" @@ -22,14 +21,21 @@ Usage: mkreq [-v] [-s*] [-c] [-C ] [-N ] [--] " 1>&2 } +if [ "x$1" = "x" ]; then + usage + exit 1 +fi + { while test $# -gt 0; do case "$1" in -s) type="server" + shift ;; -c) type="client" + shift ;; -C) ca_host="$2" @@ -46,11 +52,25 @@ Usage: mkreq [-v] [-s*] [-c] [-C ] [-N ] [--] --) break ;; + *) + echo $1 | grep -q '^-' || break # found the fqdn + echo "$0: Unknown option $1" + echo "" + usage + exit 1 esac - shift done } +host="$1" + +if [ "x$host" = "x" ]; then + echo "$0: No fqdn supplied" + echo "" + usage + exit 1 +fi + if [ -d $host -a -z $type ]; then type="server" fi -- cgit v1.1