From ee67afd21ccecbc29f72e763def7dafe6229b31b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 9 Oct 2021 17:19:51 -0400 Subject: improve/shorten help output --- cryptonomic-vpn | 67 +++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/cryptonomic-vpn b/cryptonomic-vpn index bdb8f41..68669da 100755 --- a/cryptonomic-vpn +++ b/cryptonomic-vpn @@ -8,58 +8,36 @@ help() prefix0=" $0 " prefix1=${prefix0//?/ } cat < - -$prefix0 --remote-ip \\ -$prefix1 --remote-name - - Usage: -$prefix0 --remote-ip \\ -$prefix1 --remote-name \\ +$prefix0 [--remote-name] + +$prefix0 --remote-name \\ +$prefix1 --remote-ip \\ $prefix1 [--remote-key-type rsa] \\ $prefix1 [--local-key ] - Options: - --remote-name - - Specify the name that we give to the remote side. - - Remote name is mandatory, except that if a single non-option argument is - given, then it is treated as if it were the argument to --remote-name. + --remote-name Specify the name that we give to the remote side. - --remote-ip + Remote name is mandatory, except that if a single + non-option argument is given, then it is treated as if + it were the argument to --remote-name. - The IP specifies an IP to connect to. + --remote-ip The address of the VPN gateway. - The name specifies a name we give to the remote side. + If not specified, the hostname specified with the + --remote-name option will be resolved to obtain an IP. - If not specified, the hostname specified with the --remote-name option - will be resolved to obtain the IP. + --remote-key-type The type of key to request from the remote IP via the SSH + protocol. If specified, it must be 'rsa'. - --remote-key-type + --local-key The location of the private key file. - The remote key will be fetched via the SSH protocol on port 22 on the - remote IP. This option specifies which server key type to request from - the server. - - If specified, it must be 'rsa'. - - --local-key - - This specifies the location of the private key file. - - The filename is considered relative to /etc/ssh if it has no slashes. - - The default is 'ssh_host_rsa_key'. - - The key must be an RSA key. + The filename is considered relative to /etc/ssh if it + has no slashes. The default is 'ssh_host_rsa_key'. It + must be an RSA key. EOF } @@ -87,6 +65,11 @@ parse_options() -- "$@") eval set -- "$OPTS" unset OPTS + if [ $# = 0 ] + then + help + exit + fi while true do @@ -106,7 +89,7 @@ parse_options() if [ $# = 1 -a -z "$REMOTE_NAME" ] then REMOTE_NAME=$1 - elif [ $# != 0 ] + elif [ $# != 0 -o -z "$REMOTE_NAME" ] then help exit 1 @@ -151,7 +134,7 @@ validate_local_key() */*) ;; *) LOCAL_KEY=/etc/ssh/$LOCAL_KEY ;; esac - [ -f "$LOCAL_KEY" -a -r "$LOCAL_KEY" ] || die "local key ($LOCAL_KEY)" + [ -f "$LOCAL_KEY" -a -r "$LOCAL_KEY" ] || die "could not read local key (filename=$LOCAL_KEY)" } main() @@ -159,8 +142,8 @@ main() parse_options "$@" # The validation functions modify the values to normalize them. + validate_remote_name || die 'invalid remote name' validate_remote_ip || die 'invalid remote ip' - validate_remote_name || die "invalid remote name '$REMOTE_NAME'" validate_remote_key_type || die 'invalid remote key type' validate_local_key || die 'invalid local key' -- cgit v1.2.3