#!/bin/bash PASS_EXECUTABLE=pass if ! hash $PASS_EXECUTABLE 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 DELIMITER=$'\t' 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${DELIMITER}Password${DELIMITER}Login" >> $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_EXECUTABLE show "$GPG_FILE_NAME" | head -n1) LOGIN_KEY=$($PASS_EXECUTABLE show "$GPG_FILE_NAME" | awk '/^login:|ID:|email:|user:/ {ORS=" ";for(i=2; i<=NF; i++) print $i; exit;}') GPG_FILE_NAME=${GPG_FILE_NAME//\// > } echo "Processing $GPG_FILE_NAME"; echo "$GPG_FILE_NAME$DELIMITER$PASSWORD$DELIMITER$LOGIN_KEY" >> $FINAL_FILE_NAME }; done; unset f; echo "Process done!" else echo "Something strange! The file $FINAL_FILE_NAME does not exists!" fi