-
-main() {
- processArguments "$@" # Process arguments.
-
- # Determine working directory
- ## Set DIR_TMP_PARENT to user-specified value if specified
- if [[ "$OPTION_TMPDIR" = "true" ]]; then
- if [[ -d "$TMP_DIR_PRIORITY" ]]; then
- DIR_TMP_PARENT="$OPTION_TMPDIR";
+magicParseRecipientDir() {
+ # Desc: Updates recPubKeysValid with pubkeys in dir specified by '-R' option ("recipient directory")
+ # Inputs: vars: OPTION_RECDIR, argRecDir, OPTION_ENCRYPTION
+ # arry: recPubKeysValid
+ # Outputs: arry: recPubKeysValid
+ # Depends: processArguments,
+ local recFileLine updateRecipients recipientDir
+ declare -a candRecPubKeysValid
+
+ # 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";
+ #### Initialize variable indicating outcome of pubkey review
+ unset updateRecipients
+ #### Add existing recipients
+ candRecPubKeysValid=(${recPubKeysValid[@]});
+ #### Parse files in recipientDir
+ for file in "$recipientDir"/*; do
+ ##### Read first line of each file
+ recFileLine="$(cat "$file" | head -n1)";
+ ##### check if first line is a valid pubkey
+ if checkAgePubkey "$recFileLine" && \
+ ( validateInput "$recFileLine" "ssh_pubkey" || validateInput "$recFileLine" "age_pubkey"); then
+ ###### T: add candidate pubkey to candRecPubKeysValid
+ candRecPubKeysValid+=("$recFileLine");
+ else
+ ###### F: throw warning;
+ yell "ERROR:Invalid recipient file detected. Not modifying recipient list."
+ updateRecipients="false";
+ fi;
+ done
+ #### Write updated recPubKeysValid array to recPubKeysValid if no failure detected
+ if ! updateRecipients="false"; then
+ recPubKeysValid=(${candRecPubKeysValid[@]});
+ fi;