pass2secret (942B)
- #!/bin/sh
- # pass2secret: Converts pass(1) storage to secret(1) storage
- # Copyright 2020 Haelwenn (lanodan) Monnier <contact+secret@hacktivis.me>
- # SPDX-License-Identifier: ISC
- OLDPWD="$PWD"
- workdir="$HOME/.secret-storage/"
- PASSWORD_STORE_DIR="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
- export SECRET_FILE="/dev/shm/pass2secret"
- set -e
- touch "$SECRET_FILE"
- chmod 700 "$SECRET_FILE"
- printf "secret(1) passphrase: "
- read -r passphrase
- echo
- # Create needed directories
- cd "$workdir"
- (cd "$PASSWORD_STORE_DIR" && find . -type d | grep -v ./.git) | xargs mkdir -p
- # Convert each entry
- (
- cd "$PASSWORD_STORE_DIR"
- find . -type f -name '*.gpg' | sed -e 's;\.gpg$;;' -e 's;^./;;'
- ) | while read -r entry
- do
- ( pass show "$entry" && echo ) > "$SECRET_FILE"
- if [ ! -f "$workdir/$entry.reop" ]
- then echo "$passphrase" | secret write "$entry"
- else echo "following entry exists, ignoring: $entry"
- fi
- done
- shred -u "$SECRET_FILE"
- cd "$OLDPWD"