# Gales Bitcoin Wallet: GPG integration # J. Welsh, March 2020 gbw-init () { if [ -n "$GBW_DIR" ]; then echo 'gbw-init: already opened (GBW_DIR set)' return 1 fi if [ -z "$1" ]; then echo 'gbw-init: missing filename for encrypted archive' return 1 fi GBW_DIR=`mktemp -d -p "$GBW_TMPDIR"` || return GBW_FILENAME="$1" GBW_OLDPWD="$PWD" printf 'Entering GBW_DIR %s\n' "$GBW_DIR" cd "$GBW_DIR" mkdir -p wallet/keys cd wallet printf 'Transaction fee to pay, in BTC/kB : ' read GBW_FEE printf '%s\n' "$GBW_FEE" > fee unset GBW_FEE echo 'Generating change address...' gbw-signer gen-key > change } gbw-open () { if [ -n "$GBW_DIR" ]; then echo 'gbw-open: already opened (GBW_DIR set)' return 1 fi if [ -z "$1" ]; then echo 'gbw-open: missing filename' return 1 fi if ! [ -e "$1" ]; then printf 'gbw-open: not found: %s\n' "$1" return 1 fi GBW_DIR=`mktemp -d -p "$GBW_TMPDIR"` || return GBW_FILENAME="$1" GBW_OLDPWD="$PWD" gpg --decrypt "$1" | tar -xf - -C "$GBW_DIR" printf 'Entering GBW_DIR %s\n' "$GBW_DIR" cd "$GBW_DIR/wallet" } gbw-save () { if [ -z "$GBW_DIR" ]; then echo 'gbw-save: not opened (GBW_DIR unset)' return 1 fi (cd "$GBW_OLDPWD" && tar -cf - -C "$GBW_DIR" wallet | gpg --encrypt --armor --recipient "$GBW_RECIPIENT" --output "$GBW_FILENAME{new}" && sync && mv -f "$GBW_FILENAME{new}" "$GBW_FILENAME") } gbw-discard () { if [ -z "$GBW_DIR" ]; then echo 'gbw-discard: not opened (GBW_DIR unset)' return 1 fi printf 'Returning to %s\n' "$GBW_OLDPWD" cd "$GBW_OLDPWD" rm -rf "$GBW_DIR" unset GBW_OLDPWD GBW_DIR GBW_FILENAME } gbw-close () { gbw-save && gbw-discard }