#============================================================================== # Stage 1: Read Configuration / Verify Integrity #============================================================================== if [ -r "$CONFIG_FILE" ]; then source "$CONFIG_FILE" verify_store elif [ "$1" != "-i" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Configuration not found. Please run sns -i." exit 5 #ERR_NO_STORE fi cd "$NOTES_DIR" if [ "$ENCRYPTION" == "TRUE" ]; then # If the user chose not to decrypt notes before, clear that preference. if [ -r "$NOTES_DIR"/.do_not_decrypt ]; then rm "$NOTES_DIR"/.do_not_decrypt; fi # Check if GPG is installed. if [ ! -r "$(which gpg)" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "Encryption was specified, but GPG is not installed." exit 100 # Check if we have a GPG recipient elif [ -z "$PUBKEY" ]; then >&2 printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\ "No GPG recipient was provided in $CONFIG_FILE. " exit 110 # All is good. If any previously unencrypted notes exist, encrypt them. # No harm in extra security. else find . -type f -name "*.$EXT" | grep -v "gpg" | while read TMP_NOTE; do NOTE="${TMP_NOTE%.$EXT}.gpg.$EXT" encrypt if [ -r "$NOTE" ]; then printf " $YELLOW_COLOR!$RESET_COLOR %s\n" "Encrypted ${NOTE%.$EXT}" rm "$TMP_NOTE" fi done fi # If encryption isn't enabled, make sure either all notes are decrypted or the user # does not wish to decrypt all notes. else if [ ! -r "$NOTES_DIR"/.do_not_decrypt ]; then if [ -n "$(find "$NOTES_DIR" -type f -name "*.gpg.$EXT" > /dev/null)" ]; then while true; do read -p "Would you like to de-encrypt previously encrypted notes? " YN case $YN in [Yy]* ) read -s -p "Please enter your passphrase: " PASSPHRASE cd "$NOTES_DIR" find . -type f -name "*.gpg.$EXT" | while read -r NOTE; do gpg\ --passphrase "$PASSPHRASE"\ -o "${NOTE%.gpg.note}.note"\ --decrypt "$NOTE" if [ -r "${NOTE%.gpg.note}.note" ]; then printf " $YELLOW_COLOR!$RESET_COLOR %s\n"\ "De-encrypted ${NOTE%.gpg.$EXT}" rm "$NOTE"; fi done break;; [Nn]* ) # Remember the user's preference. touch "$NOTES_DIR/.do_not_decrypt" break;; *) printf " $RED_COLOR!$RESET_COLOR %s\n" "Please enter Y or N" ;; esac done fi fi fi