-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiguana-vpn
executable file
·142 lines (127 loc) · 5.66 KB
/
iguana-vpn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# version="0.2"
#
# This is a rather minimal example Argbash potential
# Example taken from http://argbash.readthedocs.io/en/stable/example.html
#
# ARG_OPTIONAL_BOOLEAN([config],[c],[configure a vpn connection for openconnect with vpn-slice])
# ARG_OPTIONAL_BOOLEAN([run],[r],[run a vpn connection for openconnect])
# ARG_OPTIONAL_BOOLEAN([slice],[s],[enable vpn-slice])
# ARG_VERSION([echo v$version])
# ARG_HELP([The general script's help msg])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.9.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
begins_with_short_option()
{
local first_option all_short_options='crsvh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_config="off"
_arg_run="off"
_arg_slice="off"
print_help()
{
printf '%s\n' "The general script's help msg"
printf 'Usage: %s [-c|--(no-)config] [-r|--(no-)run] [-s|--(no-)slice] [-v|--version] [-h|--help]\n' "$0"
printf '\t%s\n' "-c, --config, --no-config: configure a vpn connection for openconnect with vpn-slice (off by default)"
printf '\t%s\n' "-r, --run, --no-run: run a vpn connection for openconnect (off by default)"
printf '\t%s\n' "-s, --slice, --no-slice: enable vpn-slice (off by default)"
printf '\t%s\n' "-v, --version: Prints version"
printf '\t%s\n' "-h, --help: Prints help"
}
parse_commandline()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
-c|--no-config|--config)
_arg_config="on"
test "${1:0:5}" = "--no-" && _arg_config="off"
;;
-c*)
_arg_config="on"
_next="${_key##-c}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-c" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-r|--no-run|--run)
_arg_run="on"
test "${1:0:5}" = "--no-" && _arg_run="off"
;;
-r*)
_arg_run="on"
_next="${_key##-r}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-r" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-s|--no-slice|--slice)
_arg_slice="on"
test "${1:0:5}" = "--no-" && _arg_slice="off"
;;
-s*)
_arg_slice="on"
_next="${_key##-s}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-s" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-v|--version)
echo v$version
exit 0
;;
-v*)
echo v$version
exit 0
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ "$_arg_config" = "on" ]; then
bash $DIR/lib/config.sh
elif [ "$_arg_run" = "on" ]; then
sudo -- sh -c 'exit' # prewarm sudo
if [[ "$_arg_slice" == "on" ]]; then
echo ">>> enabling vpn slice"
export WITH_VPNSLICE=true
fi
$DIR/lib/run.sh
else
print_help
fi
# ] <-- needed because of Argbash