summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2021-10-09 17:19:51 -0400
committerAndrew Cady <d@cryptonomic.net>2021-10-09 17:19:51 -0400
commitee67afd21ccecbc29f72e763def7dafe6229b31b (patch)
tree5cc0cd57e3ddd08cff51c6072085d7f3663dafb8
parente9fed06432ebe404e8e43a6e0abf3a1ec5161dfb (diff)
improve/shorten help output
-rwxr-xr-xcryptonomic-vpn67
1 files 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()
8 prefix0=" $0 " 8 prefix0=" $0 "
9 prefix1=${prefix0//?/ } 9 prefix1=${prefix0//?/ }
10 cat <<EOF 10 cat <<EOF
11
12Synopsis:
13
14$prefix0 <hostname>
15
16$prefix0 --remote-ip <IP address> \\
17$prefix1 --remote-name <hostname>
18
19
20Usage: 11Usage:
21 12
22$prefix0 --remote-ip <IP address> \\ 13$prefix0 [--remote-name] <hostname>
23$prefix1 --remote-name <hostname> \\ 14
15$prefix0 --remote-name <hostname> \\
16$prefix1 --remote-ip <IP address> \\
24$prefix1 [--remote-key-type rsa] \\ 17$prefix1 [--remote-key-type rsa] \\
25$prefix1 [--local-key <filename>] 18$prefix1 [--local-key <filename>]
26 19
27
28Options: 20Options:
29 21
30 --remote-name 22 --remote-name Specify the name that we give to the remote side.
31
32 Specify the name that we give to the remote side.
33
34 Remote name is mandatory, except that if a single non-option argument is
35 given, then it is treated as if it were the argument to --remote-name.
36 23
37 --remote-ip 24 Remote name is mandatory, except that if a single
25 non-option argument is given, then it is treated as if
26 it were the argument to --remote-name.
38 27
39 The IP specifies an IP to connect to. 28 --remote-ip The address of the VPN gateway.
40 29
41 The name specifies a name we give to the remote side. 30 If not specified, the hostname specified with the
31 --remote-name option will be resolved to obtain an IP.
42 32
43 If not specified, the hostname specified with the --remote-name option 33 --remote-key-type The type of key to request from the remote IP via the SSH
44 will be resolved to obtain the IP. 34 protocol. If specified, it must be 'rsa'.
45 35
46 --remote-key-type 36 --local-key The location of the private key file.
47 37
48 The remote key will be fetched via the SSH protocol on port 22 on the 38 The filename is considered relative to /etc/ssh if it
49 remote IP. This option specifies which server key type to request from 39 has no slashes. The default is 'ssh_host_rsa_key'. It
50 the server. 40 must be an RSA key.
51
52 If specified, it must be 'rsa'.
53
54 --local-key
55
56 This specifies the location of the private key file.
57
58 The filename is considered relative to /etc/ssh if it has no slashes.
59
60 The default is 'ssh_host_rsa_key'.
61
62 The key must be an RSA key.
63 41
64EOF 42EOF
65} 43}
@@ -87,6 +65,11 @@ parse_options()
87 -- "$@") 65 -- "$@")
88 eval set -- "$OPTS" 66 eval set -- "$OPTS"
89 unset OPTS 67 unset OPTS
68 if [ $# = 0 ]
69 then
70 help
71 exit
72 fi
90 73
91 while true 74 while true
92 do 75 do
@@ -106,7 +89,7 @@ parse_options()
106 if [ $# = 1 -a -z "$REMOTE_NAME" ] 89 if [ $# = 1 -a -z "$REMOTE_NAME" ]
107 then 90 then
108 REMOTE_NAME=$1 91 REMOTE_NAME=$1
109 elif [ $# != 0 ] 92 elif [ $# != 0 -o -z "$REMOTE_NAME" ]
110 then 93 then
111 help 94 help
112 exit 1 95 exit 1
@@ -151,7 +134,7 @@ validate_local_key()
151 */*) ;; 134 */*) ;;
152 *) LOCAL_KEY=/etc/ssh/$LOCAL_KEY ;; 135 *) LOCAL_KEY=/etc/ssh/$LOCAL_KEY ;;
153 esac 136 esac
154 [ -f "$LOCAL_KEY" -a -r "$LOCAL_KEY" ] || die "local key ($LOCAL_KEY)" 137 [ -f "$LOCAL_KEY" -a -r "$LOCAL_KEY" ] || die "could not read local key (filename=$LOCAL_KEY)"
155} 138}
156 139
157main() 140main()
@@ -159,8 +142,8 @@ main()
159 parse_options "$@" 142 parse_options "$@"
160 143
161 # The validation functions modify the values to normalize them. 144 # The validation functions modify the values to normalize them.
145 validate_remote_name || die 'invalid remote name'
162 validate_remote_ip || die 'invalid remote ip' 146 validate_remote_ip || die 'invalid remote ip'
163 validate_remote_name || die "invalid remote name '$REMOTE_NAME'"
164 validate_remote_key_type || die 'invalid remote key type' 147 validate_remote_key_type || die 'invalid remote key type'
165 validate_local_key || die 'invalid local key' 148 validate_local_key || die 'invalid local key'
166 149