pass-exporter/convert_to_csv.sh
Claudio Maradonna 8b8e560eaa
CSV script
2021-02-19 12:08:47 +01:00

45 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
PASS_EXECUTABLE=pass
if ! hash pass 2> /dev/null; then
echo "Pass executable not found. This script use pass to convert gpg password wallet. 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
fi
BASE_NAME=passwords
CURRENT_DATE=$(date "+%Y-%m-%d")
FINAL_FILE_NAME=${BASE_NAME}_${CURRENT_DATE}.csv
if [[ -f "$FINAL_FILE_NAME" ]]; then
echo "A file with name $FINAL_FILE_NAME already exists! Please rename or delete and re-execute this script."
exit
else
touch $FINAL_FILE_NAME
echo "\"Account\";\"Password\"" >> $FINAL_FILE_NAME
fi
if [[ -f "$FINAL_FILE_NAME" ]]; then
find $PASSWORD_STORE_DIR -not -type d -iname "*.gpg" -print0 | while IFS= read -r -d $'\0' f ; do {
GPG_FILE_NAME="${f:${#PASSWORD_STORE_DIR}+1}"
GPG_FILE_NAME=${GPG_FILE_NAME/\.gpg/}
PASSWORD=$(pass show "$GPG_FILE_NAME" | head -n1)
PASSWORD=${PASSWORD/\"/\\\"}
GPG_FILE_NAME=${GPG_FILE_NAME//\// > }
echo "Processing ${GPG_FILE_NAME}";
echo "\"$GPG_FILE_NAME\";\"$PASSWORD\"" >> $FINAL_FILE_NAME
}; done;
unset f;
echo "Process done!"
else
echo "Something strange! The file $FINAL_FILE_NAME does not exists!"
fi