From bb5ea43041bae1d03b8e01bcc8a54dad694c21aa Mon Sep 17 00:00:00 2001 From: Claudio Maradonna Date: Sun, 1 Aug 2021 12:57:29 +0200 Subject: [PATCH] feature: now rest of pass result is treated as note; check for awk executable before start script --- README.md | 4 ++++ convert_to_csv.sh | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50a076d..8f6fd9d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ This repository contains some scripts that aims to convert a gpg password wallet ### convert_to_csv.sh Simply execute the script. You need `pass` executable installed and ENV var PASSWORD_STORE_DIR set-up. A CSV file will be created in this folder containing key-password fields separated by TAB delimiter. +#### Dependencies + +* Awk + ```bash # Clone this repository $ git clone https://gitlab.com/unitoo/pass-exporter.git diff --git a/convert_to_csv.sh b/convert_to_csv.sh index 6575415..957ecfe 100755 --- a/convert_to_csv.sh +++ b/convert_to_csv.sh @@ -7,6 +7,11 @@ if ! hash $PASS_EXECUTABLE 2> /dev/null; then exit fi +if ! hash awk 2> /dev/null; then + echo "Awk executable not found. Exiting." + exit +fi + if [ -z "$PASSWORD_STORE_DIR" ]; then echo "PASSWORD_STORE_DIR is empty or invalid. Please follow pass documentation to understand how configure it." exit @@ -22,7 +27,7 @@ if [[ -f "$FINAL_FILE_NAME" ]]; then exit else touch $FINAL_FILE_NAME - echo "Account${DELIMITER}Password${DELIMITER}Login" >> $FINAL_FILE_NAME + echo "Account${DELIMITER}Password${DELIMITER}Login${DELIMITER}Rest" >> $FINAL_FILE_NAME fi if [[ -f "$FINAL_FILE_NAME" ]]; then @@ -33,10 +38,11 @@ if [[ -f "$FINAL_FILE_NAME" ]]; then PASSWORD=$($PASS_EXECUTABLE show "$GPG_FILE_NAME" | head -n1) LOGIN_KEY=$($PASS_EXECUTABLE show "$GPG_FILE_NAME" | awk 'BEGIN{IGNORECASE=1} /^login:|ID:|email:|user:/ {ORS=" ";for(i=2; i<=NF; i++) print $i; exit;}') + REST=$($PASS_EXECUTABLE show "$GPG_FILE_NAME" | awk '(NR>1)') GPG_FILE_NAME=${GPG_FILE_NAME//\// > } echo "Processing $GPG_FILE_NAME"; - echo "$GPG_FILE_NAME$DELIMITER$PASSWORD$DELIMITER$LOGIN_KEY" >> $FINAL_FILE_NAME + echo "$GPG_FILE_NAME$DELIMITER$PASSWORD$DELIMITER$LOGIN_KEY$DELIMITER\"$REST\"" >> $FINAL_FILE_NAME }; done; unset f;