minor tweaks
[distro-setup] / disabled / bitcoin
1 #!/bin/bash
2 ## bitcoin disabled. fees too high
3
4 if [[ $HOSTNAME == frodo ]]; then
5 case $distro in
6 debian)
7 if [[ `debian-archive` == testing ]]; then
8 # has no unstable dependencies
9 pi bitcoind/unstable
10 src=/a/opt/bitcoin/contrib/init/bitcoind.service
11 s cp $src /etc/systemd/system
12 p=/etc/bitcoin/bitcoin
13 dst=/etc/systemd/system/bitcoinjm.service
14 # jm for joinmarket
15 $sed -r "/^\s*ExecStart/s,${p}.conf,${p}jm.conf," $src \
16 >/etc/systemd/system/bitcoinjm.service
17
18 d=jm; jm=d # being clever for succinctness
19 for s in d jm; do
20 s $sed -ri "/^\s*\[Unit\]/a Conflicts=bitcoin${!s}.service" \
21 /etc/systemd/system/bitcoin${s}.service
22 done
23
24 ser daemon-reload
25
26 dir=/nocow/.bitcoin
27 s mkdir -p $dir
28 s chown -R bitcoin:bitcoin $dir
29 dir=/etc/bitcoin
30 s mkdir -p $dir
31 s chown -R root:bitcoin $dir
32 s chmod 750 $dir
33
34 # pruning decreases the bitcoin dir to 2 gb, keeps
35 # just the recent blocks. can\'t do a few things like
36 # import a wallet dump.
37 # pruning works, but people had to do
38 # some manual stuff in joinmarket. I dun need the
39 # disk space, so not bothering yet, maybe in a year or so.
40 # https://github.com/JoinMarket-Org/joinmarket/issues/431
41 #https://bitcoin.org/en/release/v0.12.0#wallet-pruning
42 #prune=550
43
44 f=$dir/bitcoin.conf
45 s dd of=$f <<EOF
46 server=1
47 # necessary for joinmarket, not bad in general
48 rpcpassword=$(openssl rand -base64 32)
49 rpcuser=$(openssl rand -base64 32)
50 EOF
51
52 # dunno about sharing a wallet between multiple instances
53 # manually did, wallet.dat symlinked in /nocow/.bitcoin
54 sgo bitcoind
55 fi
56 ;;
57 # other distros unknown
58 esac
59
60
61
62 ## disabling joinmarket, its too expensive
63 ### begin joinmarket setup ###
64
65 case $distro in
66 debian)
67 f=$dir/bitcoin.conf
68 f2=$dir/bitcoinjm.conf
69 s cp $f $f2
70 s tee -a $f2 >/dev/null <<EOF
71 # Joinmarket
72 walletnotify=curl -sI --connect-timeout 1 http://localhost:62602/walletnotify?%s
73 alertnotify=curl -sI --connect-timeout 1 http://localhost:62602/alertnotify?%s
74 wallet=joinmarket.dat
75 EOF
76
77 ;;
78 # other distros unknown
79 esac
80
81 pi libsodium-dev python-pip
82 cd /a/opt/joinmarket
83 # using develop branch, as it seems to be mostly bug fixes,
84 # and this is quite new software.
85 # note: python3 does not work.
86 # has seg fault error due to some bug, but it still works
87 pip install -r requirements.txt || [[ $? == 139 ]]
88 # note, the target must exist ahead of time, or bitcoin
89 # just overwrites the link, and it\'s not happy with an empty file,
90 # so we have to create the wallet, then move and link it.
91 s lnf -T /q/bitcoin/wallet.dat /nocow/.bitcoin/wallet.dat
92 s lnf -T /q/bitcoin/joinmarket.dat /nocow/.bitcoin/joinmarket.dat
93 # not technically needed, but seems cleaner not to have
94 # symlinks be root owned unlike everything else
95 s chown -h bitcoin:bitcoin /nocow/.bitcoin/*
96
97 for var in rpcuser rpcpassword; do
98 u="$(s sed -rn "s/^$var=(.*)/\1/p" /etc/bitcoin/bitcoin.conf)"
99 # escape backslashes
100 u="${u//\\/\\\\\\\\}"
101 # escape commas
102 u="${u//,/\\,}"
103 sed -ri "s,^(rpc_${var#rpc}\s*=).*,\1 $u," joinmarket.cfg
104 done
105 sed -ri "s/^\s*(blockchain_source\s*=).*/\1 bitcoin-rpc/" joinmarket.cfg
106 ### end joinmarket setup ###
107 fi