Added usage
This commit is contained in:
parent
c5499167cb
commit
9b3c13c164
@ -101,6 +101,19 @@ log() {
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
arg_required() {
|
||||
echo_rgb "${1}" 255 183 0
|
||||
}
|
||||
|
||||
arg_optional(){
|
||||
echo_rgb "${1}" 117 255 255
|
||||
}
|
||||
|
||||
arg_description(){
|
||||
echo_rgb "${1}" 220 190 255
|
||||
}
|
||||
|
||||
usage() {
|
||||
# Print out usage instructions for the local script
|
||||
#
|
||||
@ -113,14 +126,42 @@ usage() {
|
||||
# POSIX Compliant:
|
||||
# Yes
|
||||
#
|
||||
printf "Usage: %s\n" \
|
||||
"$(basename ${0}) -i \"this is some input\" -t \"this is some more example input\"
|
||||
--input <string> | -i <string>
|
||||
printf "$(echo_rgb "Usage:" 50 220 50) %s\n" \
|
||||
"$(echo_rgb "$(basename ${0})" 180 255 180) $(arg_required "-U") <user: string> $(arg_required "-H") <hostName: string> $(arg_optional "[OPTIONS]")
|
||||
$(arg_required "REQUIRED")
|
||||
$(arg_optional "OPTIONAL")
|
||||
|
||||
$(arg_required "-U") <user: string> | $(arg_required "--user") <user: string>
|
||||
$(arg_description \
|
||||
"Takes in a username that is to be created on the remote host
|
||||
|
||||
Example:
|
||||
--input \"this is an example input\"
|
||||
--test <string> | -t <string>
|
||||
--user User1")
|
||||
$(arg_required "-H") <hostName: string> | $(arg_required "--host-name") <hostName: string>
|
||||
$(arg_description \
|
||||
"The SSH hostname for the given host, MUST exist within your ssh configuration; typically located at ~/.ssh/config
|
||||
|
||||
Example:
|
||||
--test \"this is more example input\""
|
||||
--host-name gitlab.orion-technologies.io")
|
||||
$(arg_optional "-L") <loginUser: string> | $(arg_optional "--login-user") <loginUser: string>
|
||||
$(arg_description \
|
||||
"The user used to login to your host, must be a privileged sudo user. Default user is root.
|
||||
|
||||
Example:
|
||||
--login-user Admin")
|
||||
$(arg_optional "-K") <keyType: string> | $(arg_optional "--key-type") <keyType: string>
|
||||
$(arg_description \
|
||||
"The SSH key type to generate, passed to ssh-keygen's -t flag.
|
||||
|
||||
Example:
|
||||
--key-type rsa")
|
||||
$(arg_optional "-B") <keyBits: int> | $(arg_optional "--bits") <keyBits: int>
|
||||
$(arg_description \
|
||||
"The number of bits used to generate the given key, default is set at 512.
|
||||
|
||||
Example:
|
||||
--bits 2048")"
|
||||
|
||||
}
|
||||
|
||||
ssh_user_to_create=""
|
||||
@ -169,6 +210,9 @@ parse_args() {
|
||||
[[ -z "${ssh_key_bits}" ]] &&
|
||||
log "error" "No argument provided for ${1}s" &&
|
||||
exit 1
|
||||
[[ ! "${ssh_key_bits}" =~ [0-9] ]] &&
|
||||
log "error" "--bits must be a whole number (int), received ${ssh_key_bits}" &&
|
||||
exit 1
|
||||
;;
|
||||
-H | --host-name)
|
||||
ssh_host_name="${2}"
|
||||
@ -216,7 +260,7 @@ SSH_KEY_FILE="${SSH_KEY_DIRECTORY}/${ssh_user_to_create}-${ssh_key_type}"
|
||||
exit 1
|
||||
|
||||
log "info" "Generating SSH key file for ${ssh_user_to_create}@${ssh_host_name} at ${SSH_KEY_FILE}"
|
||||
ssh-keygen -b 512 -t ed25519 -f "${SSH_KEY_FILE}" -N "" > /dev/null 2>&1
|
||||
ssh-keygen -b 512 -t ed25519 -f "${SSH_KEY_FILE}" -N "" > /dev/null || exit "${?}"
|
||||
chmod 600 "${SSH_KEY_FILE}" > /dev/null
|
||||
log "info" "SSH key successfully created"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user