mirror of
https://github.com/deadcxap/init_scripts.git
synced 2026-07-02 05:43:40 +03:00
Merge pull request #18 from deadcxap/codex/review-setup.sh-for-improvements
Use getopt for argument parsing
This commit is contained in:
@@ -103,22 +103,35 @@ ROLE=""
|
||||
NETBIRD_KEY=""
|
||||
NETBIRD_IP=""
|
||||
NETBIRD_PORT=""
|
||||
parse_args() {
|
||||
local opts
|
||||
if ! opts=$(getopt \
|
||||
-o u:k:s:m:v:r:n:i:p:h \
|
||||
--long user:,sshkey:,ssh-ip:,monitor-ip:,vector:,role:,netbird-key:,netbird-ip:,netbird-port:,help \
|
||||
-n "$0" -- "$@"); then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
eval set -- "$opts"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-u|--user) USERNAME="$2"; shift 2 ;;
|
||||
-k|--sshkey) SSH_KEY="$2"; shift 2 ;;
|
||||
-s|--ssh-ip) SSH_ALLOWED_IP="$2"; shift 2 ;;
|
||||
-m|--monitor-ip) MONITOR_IP="$2"; shift 2 ;;
|
||||
-v|--vector) VECTOR_ENDPOINT="$2"; shift 2 ;;
|
||||
-r|--role) ROLE="$2"; shift 2 ;;
|
||||
-n|--netbird-key) NETBIRD_KEY="$2"; shift 2 ;;
|
||||
-i|--netbird-ip) NETBIRD_IP="$2"; shift 2 ;;
|
||||
-p|--netbird-port) NETBIRD_PORT="$2"; shift 2 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
--) shift; break ;;
|
||||
*) log "Unknown parameter: $1"; usage; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-u|--user) USERNAME="$2"; shift 2;;
|
||||
-k|--sshkey) SSH_KEY="$2"; shift 2;;
|
||||
-s|--ssh-ip) SSH_ALLOWED_IP="$2"; shift 2;;
|
||||
-m|--monitor-ip) MONITOR_IP="$2"; shift 2;;
|
||||
-v|--vector) VECTOR_ENDPOINT="$2"; shift 2;;
|
||||
-r|--role) ROLE="$2"; shift 2;;
|
||||
-n|--netbird-key) NETBIRD_KEY="$2"; shift 2;;
|
||||
-i|--netbird-ip) NETBIRD_IP="$2"; shift 2;;
|
||||
-p|--netbird-port) NETBIRD_PORT="$2"; shift 2;;
|
||||
-h|--help) usage; exit 0;;
|
||||
*) log "Unknown parameter: $1"; usage; exit 1;;
|
||||
esac
|
||||
done
|
||||
parse_args "$@"
|
||||
|
||||
if [[ -z "$USERNAME" || -z "$SSH_KEY" ]]; then
|
||||
usage
|
||||
|
||||
Reference in New Issue
Block a user