Skip to content

Commit 3b47666

Browse files
committed
refactor: check and install JM on the first run
1 parent 496622c commit 3b47666

9 files changed

Lines changed: 64 additions & 94 deletions

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ A terminal based graphical menu for JoinMarket.
4444
or
4545
log in with ssh to:
4646
`joinmarket@LAN_IP_ADDRESS` (the default password is: `joininbox` - will be prompted to change it on the first start)
47-
48-
* Choose `UPDATE` in the menu to install JoinMarket and edit the `joinmarket.cfg` to connect to bitcoind.
4947
---
5048

5149
## More info:

build_joininbox.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,5 @@ fi
451451
echo "# BASE IMAGE IS READY "
452452
echo
453453
echo "# look through / save this output and continue with:"
454-
echo "# 'sudo su - joinmarket'"
454+
echo "# 'sudo su - joinmarket'"
455+
echo

scripts/_functions.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22

33
walletPath="/home/joinmarket/.joinmarket/wallets/"
4+
currentJBcommit=$(cd $HOME/joininbox; git describe --tags)
5+
currentJBtag=$(cd ~/joininbox; git tag | sort -V | tail -1)
6+
currentJMversion=$(cd $HOME/joinmarket-clientserver; git describe --tags)
47

58
# openMenuIfCancelled
69
openMenuIfCancelled() {
@@ -21,6 +24,14 @@ case $pressed in
2124
esac
2225
}
2326

27+
# errorOnInstall
28+
errorOnInstall() {
29+
if [ "$1" -gt 0 ]; then
30+
DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \
31+
--msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56
32+
fi
33+
}
34+
2435
# write password into a file (to be shredded)
2536
passwordToFile() {
2637
# get password

scripts/info.importwallet.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,7 @@ case $CHOICE in
1616
*) exit 1;;
1717
esac
1818

19-
if [ ! -f "/home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate" ]; then
20-
dialog --title "JoinMarket is not installed" --yesno "
21-
Do you want to install Joinmarket now?" 7 42
22-
response=$?
23-
echo "response(${response})"
24-
if [ "${response}" = "0" ]; then
25-
echo "OK - starting JoinMarket installation"
26-
/home/joinmarket/install.joinmarket.sh install
27-
/home/joinmarket/install.joinmarket.sh config
28-
errorOnInstall=$?
29-
if [ ${errorOnInstall} -eq 0 ]; then
30-
dialog --title "Installed JoinMarket" \
31-
--msgbox "\nContinue from the menu or use the command line " 3 50
32-
else
33-
DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \
34-
--msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56
35-
fi
36-
menu
37-
fi
38-
fi
19+
3920

4021
if [ "${CHOICE}" = "LAN" ]; then
4122
# get local ip

scripts/info.qtgui.sh

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@ case $CHOICE in
1818
*) exit 1;;
1919
esac
2020

21-
if [ ! -f "/home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate" ]; then
22-
dialog --title "JoinMarket is not installed" --yesno "
23-
Do you want to install Joinmarket now?" 7 42
24-
response=$?
25-
echo "response(${response})"
26-
if [ "${response}" = "0" ]; then
27-
echo "OK - starting JoinMarket installation"
28-
/home/joinmarket/install.joinmarket.sh install
29-
/home/joinmarket/install.joinmarket.sh config
30-
errorOnInstall=$?
31-
if [ ${errorOnInstall} -eq 0 ]; then
32-
dialog --title "Installed JoinMarket" \
33-
--msgbox "\nContinue from the menu or use the command line " 7 56
34-
else
35-
DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \
36-
--msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56
37-
fi
38-
menu
39-
fi
40-
fi
41-
4221
# get local ip
4322
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
4423

scripts/install.joinmarket.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ source /home/joinmarket/joinin.conf
4040
if [ "$1" = "install" ]; then
4141
# install joinmarket
4242
if [ ! -f "/home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate" ] ; then
43-
installJoinMarket
43+
echo
44+
echo "# JoinMarket is not yet installed - proceeding now"
45+
echo
46+
installJoinMarket
47+
errorOnInstall $?
48+
# run config after install
49+
/home/joinmarket/install.joinmarket.sh config
4450
else
45-
echo "# JoinMarket is already installed"
46-
echo ""
51+
echo
52+
echo "# JoinMarket $currentJMversion is installed"
53+
echo
4754
fi
4855
exit 0
4956
fi
@@ -52,7 +59,7 @@ if [ "$1" = "config" ]; then
5259
# generate joinmarket.cfg
5360
if [ ! -f "/home/joinmarket/.joinmarket/joinmarket.cfg" ] ; then
5461
echo "# generating the joinmarket.cfg"
55-
echo ""
62+
echo
5663
. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate &&\
5764
cd /home/joinmarket/joinmarket-clientserver/scripts/
5865
python wallet-tool.py generate --datadir=/home/joinmarket/.joinmarket
@@ -89,10 +96,10 @@ if [ "$1" = "config" ]; then
8996
fi
9097

9198
if [ "$1" = "update" ]; then
92-
source /home/joinmarket/_functions.sh
9399
stopYG
94100
echo "# deleting the old source code (joinmarket-clientserver directory)"
95101
sudo rm -rf /home/joinmarket/joinmarket-clientserver
96102
installJoinMarket
103+
errorOnInstall $?
97104
exit 0
98105
fi

scripts/menu.sh

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
11
#!/bin/bash
22

33
/home/joinmarket/start.joininbox.sh
4-
5-
# add default value to joinin config if needed
6-
if ! grep -Eq "^RPCoverTor=" /home/joinmarket/joinin.conf; then
7-
echo "RPCoverTor=off" >> /home/joinmarket/joinin.conf
8-
fi
9-
10-
# check if bitcoin RPC connection is over Tor
11-
if grep -Eq "^rpc_host = .*.onion" /home/joinmarket/.joinmarket/joinmarket.cfg; then
12-
echo "# RPC over Tor is on"
13-
sed -i "s/^RPCoverTor=.*/RPCoverTor=on/g" /home/joinmarket/joinin.conf
14-
else
15-
echo "# RPC over Tor is off"
16-
sed -i "s/^RPCoverTor=.*/RPCoverTor=off/g" /home/joinmarket/joinin.conf
17-
fi
18-
19-
# check if there is only one wallet and make default
20-
# add default value to joinin config if needed
21-
if ! grep -Eq "^defaultWallet=" /home/joinmarket/joinin.conf; then
22-
echo "defaultWallet=off" >> /home/joinmarket/joinin.conf
23-
fi
24-
if [ "$(ls -p /home/joinmarket/.joinmarket/wallets/ | grep -cv /)" -gt 1 ]; then
25-
echo "# Found more than one wallet file"
26-
echo "# Setting defaultWallet to off"
27-
sed -i "s#^defaultWallet=.*#defaultWallet=off#g" /home/joinmarket/joinin.conf
28-
elif [ "$(ls -p /home/joinmarket/.joinmarket/wallets/ | grep -cv /)" -eq 1 ]; then
29-
onlyWallet=$(ls -p /home/joinmarket/.joinmarket/wallets/ | grep -v /)
30-
echo "# Found only one wallet file: $onlyWallet"
31-
echo "# Using it as default"
32-
sed -i "s#^defaultWallet=.*#defaultWallet=$onlyWallet#g" /home/joinmarket/joinin.conf
33-
fi
34-
35-
currentVersion=$(cd ~/joininbox; git tag | sort -V | tail -1)
36-
374
source /home/joinmarket/joinin.conf
385
source /home/joinmarket/_functions.sh
396

407
# BASIC MENU INFO
418
HEIGHT=24
429
WIDTH=57
4310
CHOICE_HEIGHT=20
44-
BACKTITLE="JoininBox GUI $currentVersion"
45-
TITLE="JoininBox $currentVersion"
11+
BACKTITLE="JoininBox GUI $currentJBtag"
12+
TITLE="JoininBox $currentJBtag"
4613
MENU="
4714
Choose from the options:"
4815
OPTIONS=()
@@ -130,11 +97,6 @@ Leave the box empty to show the addresses in all five" 10 64 2> $mixdepth
13097
;;
13198
CONFIG)
13299
/home/joinmarket/install.joinmarket.sh config
133-
errorOnInstall=$?
134-
if [ ${errorOnInstall} -gt 0 ]; then
135-
DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \
136-
--msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56
137-
fi
138100
echo "Returning to the menu..."
139101
sleep 1
140102
/home/joinmarket/menu.sh

scripts/menu.update.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
source /home/joinmarket/_functions.sh
44

5-
currentJBversion=$(cd $HOME/joininbox; git describe --tags)
6-
currentJMversion=$(cd $HOME/joinmarket-clientserver; git describe --tags)
7-
85
# BASIC MENU INFO
96
HEIGHT=11
107
WIDTH=56
118
CHOICE_HEIGHT=2
129
TITLE="Update options"
1310
MENU="
14-
Current JoininBox version: $currentJBversion
11+
Current JoininBox version: $currentJBcommit
1512
Current JoinMarket version: $currentJMversion"
1613
OPTIONS=()
1714
BACKTITLE="JoininBox GUI"
@@ -33,6 +30,7 @@ CHOICE=$(dialog --clear \
3330
case $CHOICE in
3431
JOININBOX)
3532
updateJoininBox
33+
errorOnInstall $?
3634
echo ""
3735
echo "Press ENTER to return to the menu"
3836
read key

scripts/start.joininbox.sh

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ "$cpuEntry" -eq 0 ]; then
1414
echo "cpu=$cpu" >> /home/joinmarket/joinin.conf
1515
fi
1616

17-
# get settings on first run
17+
# get settings on the first run
1818
runningEnvEntry=$(grep -c "runningEnv" < /home/joinmarket/joinin.conf)
1919
if [ "$runningEnvEntry" -eq 0 ]; then
2020
if [ -f "/mnt/hdd/raspiblitz.conf" ] ; then
@@ -44,6 +44,9 @@ if [ "$runningEnvEntry" -eq 0 ]; then
4444
sudo apt install dialog
4545
fi
4646

47+
# check if JoinMarket is installed
48+
/home/joinmarket/install.joinmarket.sh install
49+
4750
fi
4851

4952
source /home/joinmarket/joinin.conf
@@ -82,4 +85,34 @@ elif [ "$runningEnv" = "raspiblitz" ]; then
8285
sed -i "s/^#usessl = false/usessl = false/g" /home/joinmarket/.joinmarket/joinmarket.cfg
8386
echo "# edited the joinmarket.cfg to communicate over Tor only"
8487
fi
88+
fi
89+
90+
# check bitcoind RPC setting
91+
# add default value to joinin config if needed
92+
if ! grep -Eq "^RPCoverTor=" /home/joinmarket/joinin.conf; then
93+
echo "RPCoverTor=off" >> /home/joinmarket/joinin.conf
94+
fi
95+
# check if bitcoin RPC connection is over Tor
96+
if grep -Eq "^rpc_host = .*.onion" /home/joinmarket/.joinmarket/joinmarket.cfg; then
97+
echo "# RPC over Tor is on"
98+
sed -i "s/^RPCoverTor=.*/RPCoverTor=on/g" /home/joinmarket/joinin.conf
99+
else
100+
echo "# RPC over Tor is off"
101+
sed -i "s/^RPCoverTor=.*/RPCoverTor=off/g" /home/joinmarket/joinin.conf
102+
fi
103+
104+
# check if there is only one wallet and make default
105+
# add default value to joinin config if needed
106+
if ! grep -Eq "^defaultWallet=" /home/joinmarket/joinin.conf; then
107+
echo "defaultWallet=off" >> /home/joinmarket/joinin.conf
108+
fi
109+
if [ "$(ls -p /home/joinmarket/.joinmarket/wallets/ | grep -cv /)" -gt 1 ]; then
110+
echo "# Found more than one wallet file"
111+
echo "# Setting defaultWallet to off"
112+
sed -i "s#^defaultWallet=.*#defaultWallet=off#g" /home/joinmarket/joinin.conf
113+
elif [ "$(ls -p /home/joinmarket/.joinmarket/wallets/ | grep -cv /)" -eq 1 ]; then
114+
onlyWallet=$(ls -p /home/joinmarket/.joinmarket/wallets/ | grep -v /)
115+
echo "# Found only one wallet file: $onlyWallet"
116+
echo "# Using it as default"
117+
sed -i "s#^defaultWallet=.*#defaultWallet=$onlyWallet#g" /home/joinmarket/joinin.conf
85118
fi

0 commit comments

Comments
 (0)