X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/blobdiff_plain/320ac29c93864f2d5f3229bbc8b628ddac5371f9..6a2cd888e8ae624ddd3e885f4de2b40581adf387:/exec/bkgpslog?ds=inline diff --git a/exec/bkgpslog b/exec/bkgpslog index 6daa541..f48818d 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" && argTmpDirPriority="$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 @@ -1001,7 +1000,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 +1015,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 +1024,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