-
-
Save mpepping/b520ac964b25af62b3815a3604e21b62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# https://support.1password.com/command-line-getting-started/ | |
# | |
# Full docs: https://support.1password.com/command-line/ | |
# | |
# gpg --receive-keys 3FEF9748469ADBE15DA7CA80AC2D62742012EA22 | |
# gpg --verify op.sig op | |
# | |
# First sign-in: | |
# | |
# op signin $NAME.1password.com $EMAIL $SECRET_KEY | |
# | |
# Subsequent sign-ins: | |
# | |
# op signin $NAME | |
# | |
# Exporting to shell: | |
# | |
# eval $(op signin $NAME) | |
# | |
set -e | |
# https://stackoverflow.com/a/246128/2103996 | |
BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
cd "$BASE" | |
echo 'Running from:' | |
pwd | |
echo 'Using 1Password command-line tool:' | |
which op | |
echo 'Using jq JSON tool:' | |
which jq | |
echo 'Using parallel:' | |
which parallel | |
FOLDER=$(date '+%Y-%m-%d') | |
mkdir -p "$FOLDER" | |
cd "$FOLDER" | |
echo 'Dumping to:' | |
pwd | |
eval $(op signin $NAME) | |
echo 'Dumping vaults -> vaults.json' | |
op vault list --format=json | jq . > vaults.json | |
while read VAULT <&3 | |
do | |
echo "Vault: $VAULT" | |
mkdir -p vaults/"$VAULT"/{items,documents} | |
op vault get "$VAULT" --format=json | jq . > vaults/"$VAULT"/vault.json | |
op item list --include-archive --vault="$VAULT" --format=json | jq . > vaults/"$VAULT"/items.json | |
op document list --vault="$VAULT" --format=json | jq . > vaults/"$VAULT"/documents.json | |
jq -r '.[].id' vaults/"$VAULT"/items.json | parallel --eta -j 8 "op item get '{}' --format=json | jq . > vaults/$VAULT/items/{}.json" | |
while read DOCUMENT <&4 | |
do | |
echo "Document: $DOCUMENT" | |
# many of these fail with 500 errors | |
# op get document "$DOCUMENT" > vaults/"$VAULT"/documents/"$DOCUMENT".bin | |
done 4< <(jq -r '.[].id' vaults/"$VAULT"/documents.json) | |
done 3< <(jq -r '.[].id' vaults.json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment