host info updates
[distro-setup] / disabled / bitcoin
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23 ## bitcoin disabled. fees too high
24
25 if [[ $HOSTNAME == frodo ]]; then
26 case $distro in
27 debian)
28 if [[ `debian-archive` == testing ]]; then
29 # has no unstable dependencies
30 pi bitcoind/unstable
31 src=/a/opt/bitcoin/contrib/init/bitcoind.service
32 s cp $src /etc/systemd/system
33 p=/etc/bitcoin/bitcoin
34 dst=/etc/systemd/system/bitcoinjm.service
35 # jm for joinmarket
36 $sed -r "/^\s*ExecStart/s,${p}.conf,${p}jm.conf," $src \
37 >/etc/systemd/system/bitcoinjm.service
38
39 d=jm; jm=d # being clever for succinctness
40 for s in d jm; do
41 s $sed -ri "/^\s*\[Unit\]/a Conflicts=bitcoin${!s}.service" \
42 /etc/systemd/system/bitcoin${s}.service
43 done
44
45 ser daemon-reload
46
47 dir=/nocow/.bitcoin
48 s mkdir -p $dir
49 s chown -R bitcoin:bitcoin $dir
50 dir=/etc/bitcoin
51 s mkdir -p $dir
52 s chown -R root:bitcoin $dir
53 s chmod 750 $dir
54
55 # pruning decreases the bitcoin dir to 2 gb, keeps
56 # just the recent blocks. can\'t do a few things like
57 # import a wallet dump.
58 # pruning works, but people had to do
59 # some manual stuff in joinmarket. I dun need the
60 # disk space, so not bothering yet, maybe in a year or so.
61 # https://github.com/JoinMarket-Org/joinmarket/issues/431
62 #https://bitcoin.org/en/release/v0.12.0#wallet-pruning
63 #prune=550
64
65 f=$dir/bitcoin.conf
66 s dd of=$f <<EOF
67 server=1
68 # necessary for joinmarket, not bad in general
69 rpcpassword=$(openssl rand -base64 32)
70 rpcuser=$(openssl rand -base64 32)
71 EOF
72
73 # dunno about sharing a wallet between multiple instances
74 # manually did, wallet.dat symlinked in /nocow/.bitcoin
75 sgo bitcoind
76 fi
77 ;;
78 # other distros unknown
79 esac
80
81
82
83 ## disabling joinmarket, its too expensive
84 ### begin joinmarket setup ###
85
86 case $distro in
87 debian)
88 f=$dir/bitcoin.conf
89 f2=$dir/bitcoinjm.conf
90 s cp $f $f2
91 s tee -a $f2 >/dev/null <<EOF
92 # Joinmarket
93 walletnotify=curl -sI --connect-timeout 1 http://localhost:62602/walletnotify?%s
94 alertnotify=curl -sI --connect-timeout 1 http://localhost:62602/alertnotify?%s
95 wallet=joinmarket.dat
96 EOF
97
98 ;;
99 # other distros unknown
100 esac
101
102 pi libsodium-dev python-pip
103 cd /a/opt/joinmarket
104 # using develop branch, as it seems to be mostly bug fixes,
105 # and this is quite new software.
106 # note: python3 does not work.
107 # has seg fault error due to some bug, but it still works
108 pip install -r requirements.txt || [[ $? == 139 ]]
109 # note, the target must exist ahead of time, or bitcoin
110 # just overwrites the link, and it\'s not happy with an empty file,
111 # so we have to create the wallet, then move and link it.
112 s lnf -T /q/bitcoin/wallet.dat /nocow/.bitcoin/wallet.dat
113 s lnf -T /q/bitcoin/joinmarket.dat /nocow/.bitcoin/joinmarket.dat
114 # not technically needed, but seems cleaner not to have
115 # symlinks be root owned unlike everything else
116 s chown -h bitcoin:bitcoin /nocow/.bitcoin/*
117
118 for var in rpcuser rpcpassword; do
119 u="$(s sed -rn "s/^$var=(.*)/\1/p" /etc/bitcoin/bitcoin.conf)"
120 # escape backslashes
121 u="${u//\\/\\\\\\\\}"
122 # escape commas
123 u="${u//,/\\,}"
124 sed -ri "s,^(rpc_${var#rpc}\s*=).*,\1 $u," joinmarket.cfg
125 done
126 sed -ri "s/^\s*(blockchain_source\s*=).*/\1 bitcoin-rpc/" joinmarket.cfg
127 ### end joinmarket setup ###
128 fi