From 9b3c13c164d6f8019e77b363c2a0963ef7017bf4 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Wed, 6 Oct 2021 00:10:21 -0500 Subject: [PATCH] Added usage --- SSH/Create-SSH-User.bash | 58 +++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/SSH/Create-SSH-User.bash b/SSH/Create-SSH-User.bash index fbf4549..16f98e1 100755 --- a/SSH/Create-SSH-User.bash +++ b/SSH/Create-SSH-User.bash @@ -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 | -i + printf "$(echo_rgb "Usage:" 50 220 50) %s\n" \ +"$(echo_rgb "$(basename ${0})" 180 255 180) $(arg_required "-U") $(arg_required "-H") $(arg_optional "[OPTIONS]") + $(arg_required "REQUIRED") + $(arg_optional "OPTIONAL") + + $(arg_required "-U") | $(arg_required "--user") + $(arg_description \ + "Takes in a username that is to be created on the remote host + Example: - --input \"this is an example input\" - --test | -t + --user User1") + $(arg_required "-H") | $(arg_required "--host-name") + $(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") | $(arg_optional "--login-user") + $(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") | $(arg_optional "--key-type") + $(arg_description \ + "The SSH key type to generate, passed to ssh-keygen's -t flag. + + Example: + --key-type rsa") + $(arg_optional "-B") | $(arg_optional "--bits") + $(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"