Projects : gbw-signer : gbw-signer_genesis
1 | # Gales Bitcoin Wallet: GPG integration |
2 | # J. Welsh, March 2020 |
3 | |
4 | gbw-init () { |
5 | if [ -n "$GBW_DIR" ]; then |
6 | echo 'gbw-init: already opened (GBW_DIR set)' |
7 | return 1 |
8 | fi |
9 | |
10 | if [ -z "$1" ]; then |
11 | echo 'gbw-init: missing filename for encrypted archive' |
12 | return 1 |
13 | fi |
14 | |
15 | GBW_DIR=`mktemp -d -p "$GBW_TMPDIR"` || return |
16 | GBW_FILENAME="$1" |
17 | GBW_OLDPWD="$PWD" |
18 | |
19 | printf 'Entering GBW_DIR %s\n' "$GBW_DIR" |
20 | cd "$GBW_DIR" |
21 | mkdir -p wallet/keys |
22 | cd wallet |
23 | |
24 | printf 'Transaction fee to pay, in BTC/kB : ' |
25 | read GBW_FEE |
26 | printf '%s\n' "$GBW_FEE" > fee |
27 | unset GBW_FEE |
28 | |
29 | echo 'Generating change address...' |
30 | gbw-signer gen-key > change |
31 | } |
32 | |
33 | gbw-open () { |
34 | if [ -n "$GBW_DIR" ]; then |
35 | echo 'gbw-open: already opened (GBW_DIR set)' |
36 | return 1 |
37 | fi |
38 | |
39 | if [ -z "$1" ]; then |
40 | echo 'gbw-open: missing filename' |
41 | return 1 |
42 | fi |
43 | |
44 | if ! [ -e "$1" ]; then |
45 | printf 'gbw-open: not found: %s\n' "$1" |
46 | return 1 |
47 | fi |
48 | |
49 | GBW_DIR=`mktemp -d -p "$GBW_TMPDIR"` || return |
50 | GBW_FILENAME="$1" |
51 | GBW_OLDPWD="$PWD" |
52 | |
53 | gpg --decrypt "$1" | tar -xf - -C "$GBW_DIR" |
54 | |
55 | printf 'Entering GBW_DIR %s\n' "$GBW_DIR" |
56 | cd "$GBW_DIR/wallet" |
57 | } |
58 | |
59 | gbw-save () { |
60 | if [ -z "$GBW_DIR" ]; then |
61 | echo 'gbw-save: not opened (GBW_DIR unset)' |
62 | return 1 |
63 | fi |
64 | |
65 | (cd "$GBW_OLDPWD" && |
66 | tar -cf - -C "$GBW_DIR" wallet | gpg --encrypt --armor --recipient "$GBW_RECIPIENT" --output "$GBW_FILENAME{new}" && |
67 | sync && |
68 | mv -f "$GBW_FILENAME{new}" "$GBW_FILENAME") |
69 | } |
70 | |
71 | gbw-discard () { |
72 | if [ -z "$GBW_DIR" ]; then |
73 | echo 'gbw-discard: not opened (GBW_DIR unset)' |
74 | return 1 |
75 | fi |
76 | |
77 | printf 'Returning to %s\n' "$GBW_OLDPWD" |
78 | cd "$GBW_OLDPWD" |
79 | rm -rf "$GBW_DIR" |
80 | unset GBW_OLDPWD GBW_DIR GBW_FILENAME |
81 | } |
82 | |
83 | gbw-close () { |
84 | gbw-save && gbw-discard |
85 | } |