Created
October 13, 2015 11:09
-
-
Save nod0n/bdece268f2bb3bcd4c04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -A data | |
data[host]='' | |
data[port]='' | |
data[user]='' | |
data[pw]='' | |
data[domain]='' | |
function usage { | |
printf -- "options:\n" | |
printf -- "-H Host " | |
printf -- "[-P port] " | |
printf -- "[-u user] " | |
printf -- "-p password " | |
printf -- "[-D domain]" | |
printf -- "\n\n" | |
} | |
while getopts H:P:u:p:D:h option | |
do | |
case "$option" in | |
H) | |
data[host]=$OPTARG | |
;; | |
P) | |
data[port]=$OPTARG | |
;; | |
u) | |
data[user]=$OPTARG | |
;; | |
p) | |
data[pw]=$OPTARG | |
;; | |
D) | |
data[domain]=$OPTARG | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
*) | |
usage >&2 | |
exit 1 | |
;; | |
esac | |
done | |
for key in "${!data[@]}" | |
do | |
if [ "$key" = 'host' ] || [ "$key" = 'pw' ] | |
then | |
if [ "${data[$key]}" = '' ] | |
then | |
echo "$key must be given!" >&2 | |
usage >&2 | |
exit 1 | |
fi | |
fi | |
if [ "$key" = 'user' ] && [ "${data[$key]}" = '' ] | |
then | |
data["$key"]="$USER" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment