forked from altairwei/wireguard-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwgserver.sh
73 lines (63 loc) · 2.02 KB
/
wgserver.sh
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
#!/bin/bash
#
# Useful tools for WireGuard VPN server. Manage server or clients config files.
# The following macros are defined by Argbash, see https://github.com/matejak/argbash
# ARG_POSITIONAL_SINGLE([subcommand], [Call sub-command, including <install | show | set> ])
# ARG_OPTIONAL_BOOLEAN([help], [h], [Print help])
# ARG_VERSION_AUTO([0.1.0])
# ARG_LEFTOVERS([Arguments passed to sub-command.])
# ARG_DEFAULTS_POS
# DEFINE_SCRIPT_DIR([SCRIPT_DIR])
# ARGBASH_PREPARE
# [ <-- needed because of Argbash
set -e -o pipefail
export LC_ALL=C
SELF="$(readlink -f "${BASH_SOURCE[0]}")"
ARGS=( "$@" )
source "${SCRIPT_DIR}/wgserver-lib.sh" \
|| { echo "Couldn't find 'wgserver-lib.sh' parsing library in the '$SCRIPT_DIR' directory"; exit 1; }
print_help()
{
printf '%s\n' "Useful tools for WireGuard VPN server."
printf 'Usage: %s [-h|--help] [-v|--version] <subcommand> ... \n' "wgserver"
printf '\t%s\n' "<subcommand>: Call sub-command, including <install | show | set> "
printf '\t%s\n' "... : Arguments passed to sub-command."
printf '\t%s\n' "-h, --help: Prints help. You can also pass '-h|--help' to sub-command to get help message."
printf '\t%s\n' "-v, --version: Prints version"
}
main() {
# Process options
export _PRINT_HELP="yes"
parse_commandline "$@"
assign_positional_args 1 "${_positionals[@]}"
local show_help
if [[ ("${_arg_help}" = "on") && ( -z "${_arg_subcommand}") ]]; then
# Show wgserver help
print_help
exit 0
elif [[ ("${_arg_help}" = "on") && ( -n "${_arg_subcommand}") ]]; then
# Show subcommand help
show_help='-h'
fi
handle_passed_args_count
# Process subcommand
request_administrator_authority
case $_arg_subcommand in
install)
${SCRIPT_DIR}/wgserver-install ${show_help} "${_arg_leftovers[@]}"
;;
show)
${SCRIPT_DIR}/wgserver-show ${show_help} "${_arg_leftovers[@]}"
;;
set)
${SCRIPT_DIR}/wgserver-set ${show_help} "${_arg_leftovers[@]}"
;;
*)
print_help
err "Unknown sub-command: ${_arg_subcommand}"
exit 127
;;
esac
}
main "$@"
# ] <-- needed because of Argbash