Skip to content

Instantly share code, notes, and snippets.

@wincent
Created February 27, 2018 07:05
Show Gist options
  • Save wincent/d18d2586c748330c8c08452c67a7370c to your computer and use it in GitHub Desktop.
Save wincent/d18d2586c748330c8c08452c67a7370c to your computer and use it in GitHub Desktop.
#!/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 list vaults | jq . > vaults.json
while read VAULT <&3
do
echo "Vault: $VAULT"
mkdir -p vaults/"$VAULT"/{items,documents}
op get vault "$VAULT" | jq . > vaults/"$VAULT"/vault.json
op list items --include-trash --vault="$VAULT" | jq . > vaults/"$VAULT"/items.json
op list documents --vault="$VAULT" | jq . > vaults/"$VAULT"/documents.json
jq -r '.[].uuid' vaults/"$VAULT"/items.json | parallel --eta -j 8 "op get item '{}' | 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 '.[].uuid' vaults/"$VAULT"/documents.json)
done 3< <(jq -r '.[].uuid' vaults.json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment