--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
# 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";
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";
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