Skip to content

Instantly share code, notes, and snippets.

@nod0n
Created October 13, 2015 11:09
Show Gist options
  • Save nod0n/bdece268f2bb3bcd4c04 to your computer and use it in GitHub Desktop.
Save nod0n/bdece268f2bb3bcd4c04 to your computer and use it in GitHub Desktop.
#!/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