X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/blobdiff_plain/79bb6c16db0def5cb43b07e9a923b883eeb0737c..61b243e02e1f931475cee6af954b2969f6276e42:/exec/bklog diff --git a/exec/bklog b/exec/bklog index f3722df..52f6eb1 100644 --- a/exec/bklog +++ b/exec/bklog @@ -11,7 +11,7 @@ dirTmpDefault="/dev/shm"; # Default parent of working directory # Script Metadata scriptName="bklog"; # Define basename of script file. -scriptVersion="0.1.5"; # Define version of script. +scriptVersion="0.1.8"; # Define version of script. scriptURL="https://gitlab.com/baltakatei/ninfacyzga-01"; # Define wesite hosting this script. scriptTimeStart="$(date +%Y%m%dT%H%M%S.%N)"; # YYYYmmddTHHMMSS.NNNNNNNNN scriptHostname=$(hostname); # Save hostname of system running this script. @@ -624,6 +624,60 @@ timeDuration(){ fi } # Get duration (ex: PT10M4S ) +validateInput() { + # Desc: Validates Input + # Usage: validateInput [str input] [str input type] + # Version: 0.3.1 + # Input: arg1: string to validate + # arg2: string specifying input type (ex:"ssh_pubkey") + # Output: return code 0: if input string matched specified string type + # Depends: bash 5, yell() + + local fn argInput argType + + # Save function name + fn="${FUNCNAME[0]}"; + + # Process arguments + argInput="$1"; + argType="$2"; + if [[ $# -gt 2 ]]; then yell "ERROR:$0:$fn:Too many arguments."; exit 1; fi; + + # Check for blank + if [[ -z "$argInput" ]]; then return 1; fi + + # Define input types + ## ssh_pubkey + ### Check for alnum/dash base64 (ex: "ssh-rsa AAAAB3NzaC1yc2EAAA") + if [[ "$argType" = "ssh_pubkey" ]]; then + if [[ "$argInput" =~ ^[[:alnum:]-]*[\ ]*[[:alnum:]+/=]*$ ]]; then + return 0; fi; fi; + + ## age_pubkey + ### Check for age1[:bech32:] + if [[ "$argType" = "age_pubkey" ]]; then + if [[ "$argInput" =~ ^age1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*$ ]]; then + return 0; fi; fi + + ## integer + if [[ "$argType" = "integer" ]]; then + if [[ "$argInput" =~ ^[[:digit:]]*$ ]]; then + return 0; fi; fi; + + ## time element (year, month, week, day, hour, minute, second) + if [[ "$argType" = "time_element" ]]; then + if [[ "$argInput" = "year" ]] || \ + [[ "$argInput" = "month" ]] || \ + [[ "$argInput" = "week" ]] || \ + [[ "$argInput" = "day" ]] || \ + [[ "$argInput" = "hour" ]] || \ + [[ "$argInput" = "minute" ]] || \ + [[ "$argInput" = "second" ]]; then + return 0; fi; fi; + + # Return error if no condition matched. + return 1; +} # Validates strings magicInitWorkingDir() { # Desc: Determine temporary working directory from defaults or user input @@ -756,6 +810,12 @@ magicParseProcessStrings() { local rawFileExt vbm "STATUS:Starting magicParseProcessStrings() function."; + vbm "var:optionProcString:$optionProcString"; + vbm "var:optionNoStoreRaw:$optionNoStoreRaw"; + vbm "var:optionStoreRaw:$optionStoreRaw"; + vbm "var:argRawFileExt:$argRawFileExt"; + vbm "ary:argProcStrings:${argProcStrings[*]}"; + vbm "ary:argProcFileExts:${argProcFileExts[*]}" # Validate input ## Validate argRawFileExt if [[ "$argRawFileExt" =~ ^[.][[:alnum:]]*$ ]]; then @@ -799,8 +859,8 @@ magicParseProcessStrings() { if [[ -z "$element" ]]; then yell "ERROR:Empty output file extension specified. Exiting."; exit 1; fi; done ## Make sure that no process string starts with '-' (ex: if only one arg supplied after '-p' option) for element in "${argProcStrings[@]}"; do - if [[ ! "$element" =~ ^[-][[:print:]]*$ ]] && [[ "$element" =~ ^[[:print:]]*$ ]]; then - yell "ERROR:Illegal character '-' at start of process string element. Option syntax error?"; + if [[ "$element" =~ ^[-][[:print:]]*$ ]] && [[ ! "$element" =~ ^[[:print:]]*$ ]]; then + yell "ERROR:Illegal character '-' at start of process string element:\"$element\""; exit 1; fi; done; vbm "STATUS:Quick check shows argProcStrings and argProcFileExts appear to have valid contents."; procStrings=("${argProcStrings[@]}"); # Export process command strings