X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/blobdiff_plain/320ac29c93864f2d5f3229bbc8b628ddac5371f9..c9c573da200aef5273d6d55ef03bb6da7e0eb150:/exec/bkgpslog?ds=sidebyside diff --git a/exec/bkgpslog b/exec/bkgpslog index 6daa541..3a7bae8 100755 --- a/exec/bkgpslog +++ b/exec/bkgpslog @@ -209,13 +209,12 @@ processArguments() { --version) showVersion; exit 1;; # Show version -v | --verbose) OPTION_VERBOSE="true"; vbm "DEBUG:Verbose mode enabled.";; # Enable verbose mode. -o | --output) if [ -d "$2" ]; then DIR_OUT="$2"; vbm "DEBUG:DIR_OUT:$DIR_OUT"; shift; fi ;; # Define output directory. - -e | --encrypt) OPTION_ENCRYPT="true"; vbm "DEBUG:Encrypted output mode enabled.";; - -r | --recipient) # Add 'age' recipient via public key string - argRecPubKeys+=("$2"); vbm "STATUS:pubkey added:""$2"; shift;; - -c | --compress) OPTION_COMPRESS="true"; vbm "DEBUG:Compressed output mode enabled.";; - -z | --time-zone) try setTimeZoneEV "$2"; shift;; - -t | --temp-dir) OPTION_TMPDIR="true" && argTmpDirPriority="$2"; shift;; - -R | --recipient-dir) OPTION_RECDIR="true" && argRecDir="$2"; shift;; + -e | --encrypt) OPTION_ENCRYPT="true"; vbm "DEBUG:Encrypted output mode enabled.";; # Enable encryption + -r | --recipient) OPTION_RECIPIENTS="true"; argRecPubKeys+=("$2"); vbm "STATUS:pubkey added:""$2"; shift;; # Add recipients + -c | --compress) OPTION_COMPRESS="true"; vbm "DEBUG:Compressed output mode enabled.";; # Enable compression + -z | --time-zone) try setTimeZoneEV "$2"; shift;; # Set timestamp timezone + -t | --temp-dir) OPTION_TMPDIR="true" && argTempDirPriority="$2"; shift;; # Set time zone + -R | --recipient-dir) OPTION_RECIPIENTS="true"; OPTION_RECDIR="true" && argRecDir="$2"; shift;; # Add recipient watch dir *) echoerr "ERROR: Unrecognized argument: $1"; echoerr "STATUS:All arguments:$*"; exit 1;; # Handle unrecognized options. esac shift @@ -953,14 +952,15 @@ magicGatherWriteBuffer() { } # write buffer to disk magicParseRecipientDir() { # Desc: Updates recPubKeysValid with pubkeys in dir specified by '-R' option ("recipient directory") - # Inputs: vars: OPTION_RECDIR, argRecDir, - # arry: recPubKeysValid - # Outputs: arry: recPubKeysValid (modified with pubkeys in argRecDir if pubkeys valid) + # Inputs: vars: OPTION_RECDIR, argRecDir, OPTION_ENCRYPTION + # arry: recPubKeysValid + # Outputs: arry: recPubKeysValid # Depends: processArguments, local recFileLine updateRecipients recipientDir declare -a candRecPubKeysValid - - if [[ "$OPTION_RECDIR" = "true" ]]; then + + # Check that '-e' and '-R' set + if [[ "$OPTION_ENCRYPTION" = "true" ]] && [[ "$OPTION_RECDIR" = "true" ]]; then ### Check that argRecDir is a directory. if [[ -d "$argRecDir" ]]; then recipientDir="$argRecDir"; @@ -991,6 +991,12 @@ magicParseRecipientDir() { yell "ERROR:$0:Recipient directory $argRecDir does not exist. Exiting."; exit 1; fi; fi; + # Handle case if '-e' set but '-R' not set + if [[ "$OPTION_ENCRYPTION" = "true" ]] && [[ ! "$OPTION_RECDIR" = "true" ]]; then + yell "ERROR: \'-e\' set but \'-R\' is not set."; fi; + # Handle case if '-R' set but '-e' not set + if [[ ! "$OPTION_ENCRYPTION" = "true" ]] && [[ "$OPTION_RECDIR" = "true" ]]; then + yell "ERROR: \'-R\' is set but \'-e\' is not set."; fi; } # Update recPubKeysValid with argRecDir magicParseRecipientArgs() { # Desc: Parses recipient arguments specified by '-r' option @@ -1001,7 +1007,8 @@ magicParseRecipientArgs() { # Depends: checkapp(), checkAgePubkey(), validateInput(), processArguments() local recipients - if [[ "$OPTION_ENCRYPT" = "true" ]]; then # Check if encryption option active. + # Check if encryption option active. + if [[ "$OPTION_ENCRYPT" = "true" ]] && [[ "$OPTION_RECIPIENTS" = "true" ]]; then if checkapp age; then # Check that age is available. for pubkey in "${argRecPubKeys[@]}"; do # Validate recipient pubkey strings by forming test message vbm "DEBUG:Testing pubkey string:$pubkey"; @@ -1015,7 +1022,7 @@ magicParseRecipientArgs() { recPubKeysValid+=("$pubkey") && vbm "DEBUG:recPubkeysValid:pubkey added:$pubkey"; else yell "ERROR:Exit code ""$?"". Invalid recipient pubkey string. Exiting."; exit 1; - fi + fi; done vbm "DEBUG:Finished processing argRecPubKeys array"; @@ -1024,12 +1031,18 @@ magicParseRecipientArgs() { CMD_ENCRYPT_SUFFIX=".age" && vbm "CMD_ENCRYPT_SUFFIX:$CMD_ENCRYPT_SUFFIX"; else yell "ERROR:Encryption enabled but \"age\" not found. Exiting."; exit 1; - fi + fi; else CMD_ENCRYPT="tee /dev/null " && vbm "CMD_ENCRYPT:$CMD_ENCRYPT"; CMD_ENCRYPT_SUFFIX="" && vbm "CMD_ENCRYPT_SUFFIX:$CMD_ENCRYPT_SUFFIX"; vbm "DEBUG:Encryption not enabled." - fi + fi; + # Catch case if '-e' is set but '-r' or '-R' is not + if [[ "$OPTION_ENCRYPT" = "true" ]] && [[ ! "$OPTION_RECIPIENTS" = "true" ]]; then + yell "ERROR:\'-e\' set but no \'-r\' or \'-R\' set."; exit 1; fi; + # Catch case if '-r' or '-R' set but '-e' is not + if [[ ! "$OPTION_ENCRYPT" = "true" ]] && [[ "$OPTION_RECIPIENTS" = "true" ]]; then + yell "ERROR:\'-r\' or \'-R\' set but \'-e\' is not set."; exit 1; fi; } # Populate recPubKeysValid with argRecPubKeys; form encryption cmd string and filename suffix magicParseCompressionArg() { # Desc: Parses compression arguments specified by '-c' option @@ -1051,7 +1064,8 @@ magicParseCompressionArg() { } # Form compression cmd string and filename suffix magicInitWorkingDir() { # Desc: Determine temporary working directory from defaults or user input - # Input: vars: OPTION_TEMPDIR, argTmpDirPriority, DIR_TMP_DEFAULT + # Usage: magicInitWorkignDir + # Input: vars: OPTION_TEMPDIR, argTempDirPriority, DIR_TMP_DEFAULT # Input: vars: SCRIPT_TIME_START # Output: vars: DIR_TMP # Depends: processArguments(), vbm(), yell() @@ -1063,7 +1077,7 @@ magicInitWorkingDir() { if [[ -d "$argTempDirPriority" ]]; then DIR_TMP_PARENT="$argTempDirPriority"; else - yell "WARNING:Specified temporary working directory not valid:$OPTION_TMPDIR"; + yell "WARNING:Specified temporary working directory not valid:$argTempDirPriority"; exit 1; # Exit since user requires a specific temp dir and it is not available. fi; else @@ -1087,14 +1101,14 @@ main() { processArguments "$@"; ## Act upon arguments ### Determine working directory - magicInitWorkingDir; + magicInitWorkingDir; # Sets DIR_TMP from argTempDirPriority ### Set output encryption and compression option strings #### React to "-r" ("encryption recipients") option - magicParseRecipientArgs; + magicParseRecipientArgs; # Updates recPubKeysValid, CMD_ENCRYPT[_SUFFIX] #### React to "-c" ("compression") option - magicParseCompressionArg; + magicParseCompressionArg; # Updates CMD_COMPRESS[_SUFFIX] #### React to "-R" ("recipient directory") option - magicParseRecipientDir; + magicParseRecipientDir; # Updates recPubKeysValid # Check that critical apps and dirs are available, display missing ones. if ! checkapp gpspipe tar && ! checkdir "$DIR_OUT" "DIR_TMP"; then