Skip to content

Commit 36e4968

Browse files
committed
add generateJMconfig and setIRCtoTor functions
1 parent e3da3ab commit 36e4968

3 files changed

Lines changed: 196 additions & 189 deletions

File tree

scripts/_functions.sh

Lines changed: 189 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -9,101 +9,98 @@ currentJBtag=$(cd ~/joininbox; git tag | sort -V | tail -1)
99
currentJMversion=$(cd /home/joinmarket/joinmarket-clientserver 2>/dev/null; \
1010
git describe --tags 2>/dev/null)
1111

12-
# openMenuIfCancelled
13-
openMenuIfCancelled() {
14-
pressed=$1
15-
case $pressed in
16-
1)
17-
echo "Cancelled"
18-
echo "Returning to the menu..."
19-
sleep 1
20-
/home/joinmarket/menu.sh
21-
exit 1;;
22-
255)
23-
echo "ESC pressed."
24-
echo "Returning to the menu..."
25-
sleep 1
26-
/home/joinmarket/menu.sh
27-
exit 1;;
28-
esac
12+
function openMenuIfCancelled() {
13+
pressed=$1
14+
case $pressed in
15+
1)
16+
echo "Cancelled"
17+
echo "Returning to the menu..."
18+
sleep 1
19+
/home/joinmarket/menu.sh
20+
exit 1;;
21+
255)
22+
echo "ESC pressed."
23+
echo "Returning to the menu..."
24+
sleep 1
25+
/home/joinmarket/menu.sh
26+
exit 1;;
27+
esac
2928
}
3029

31-
# errorOnInstall
32-
errorOnInstall() {
33-
if [ "$1" -gt 0 ]; then
34-
DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \
35-
--msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56
36-
fi
30+
function errorOnInstall() {
31+
if [ "$1" -gt 0 ]; then
32+
DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \
33+
--msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56
34+
fi
3735
}
3836

39-
# write password into a file (to be shredded)
40-
passwordToFile() {
41-
# get password
42-
data=$(mktemp 2>/dev/null)
43-
# trap it
44-
trap 'rm -f $data' 0 1 2 5 15
45-
dialog --backtitle "Enter password" \
46-
--title "Enter password" \
47-
--insecure \
48-
--passwordbox "Type or paste the wallet decryption password" 8 52 2> "$data"
49-
# make decison
50-
pressed=$?
51-
case $pressed in
52-
0)
53-
touch /home/joinmarket/.pw
54-
chmod 600 /home/joinmarket/.pw
55-
tee /home/joinmarket/.pw 1>/dev/null < "$data"
56-
shred "$data"
57-
;;
58-
1)
59-
shred "$data"
60-
shred "$wallet"
61-
rm -f .pw
62-
echo "Cancelled"
63-
exit 1
64-
;;
65-
255)
66-
shred "$data"
67-
shred "$wallet"
68-
rm -f .pw
69-
[ -s "$data" ] && cat "$data" || echo "ESC pressed."
70-
exit 1
71-
;;
72-
esac
37+
function passwordToFile() {
38+
# write password into a file (to be shredded)
39+
# get password
40+
data=$(mktemp 2>/dev/null)
41+
# trap it
42+
trap 'rm -f $data' 0 1 2 5 15
43+
dialog --backtitle "Enter password" \
44+
--title "Enter password" \
45+
--insecure \
46+
--passwordbox "Type or paste the wallet decryption password" 8 52 2> "$data"
47+
# make decison
48+
pressed=$?
49+
case $pressed in
50+
0)
51+
touch /home/joinmarket/.pw
52+
chmod 600 /home/joinmarket/.pw
53+
tee /home/joinmarket/.pw 1>/dev/null < "$data"
54+
shred "$data"
55+
;;
56+
1)
57+
shred "$data"
58+
shred "$wallet"
59+
rm -f .pw
60+
echo "Cancelled"
61+
exit 1
62+
;;
63+
255)
64+
shred "$data"
65+
shred "$wallet"
66+
rm -f .pw
67+
[ -s "$data" ] && cat "$data" || echo "ESC pressed."
68+
exit 1
69+
;;
70+
esac
7371
}
7472

75-
# chooseWallet
76-
chooseWallet() {
73+
function chooseWallet() {
7774
source /home/joinmarket/joinin.conf
78-
wallet=$(mktemp 2>/dev/null)
79-
if [ "$defaultWallet" = "off" ]; then
8075
wallet=$(mktemp 2>/dev/null)
81-
dialog --backtitle "Choose a wallet by typing the full name of the file" \
82-
--title "Choose a wallet by typing the full name of the file" \
83-
--fselect "$walletPath" 10 60 2> "$wallet"
84-
openMenuIfCancelled $?
85-
else
86-
echo "$defaultWallet" > "$wallet"
87-
fi
76+
if [ "$defaultWallet" = "off" ]; then
77+
wallet=$(mktemp 2>/dev/null)
78+
dialog --backtitle "Choose a wallet by typing the full name of the file" \
79+
--title "Choose a wallet by typing the full name of the file" \
80+
--fselect "$walletPath" 10 60 2> "$wallet"
81+
openMenuIfCancelled $?
82+
else
83+
echo "$defaultWallet" > "$wallet"
84+
fi
8885
}
8986

9087
function stopYG() {
91-
# stop the background process (equivalent to CTRL+C)
92-
# use wallet from joinin.conf
93-
source /home/joinmarket/joinin.conf
94-
pkill -sigint -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin"
95-
# pgrep python | xargs kill -sigint
96-
# remove the service
97-
sudo systemctl stop yg-privacyenhanced
98-
sudo systemctl disable yg-privacyenhanced
99-
# check for failed services
100-
# sudo systemctl list-units --type=service
101-
sudo systemctl reset-failed
102-
# make sure the lock file is deleted
103-
rm -f ~/.joinmarket/wallets/.$wallet.lock
104-
# for old version <v0.6.3
105-
rm -f ~/.joinmarket/wallets/$wallet.lock 2>/dev/null
106-
echo "# stopped the Yield Generator background service"
88+
# stop the background process (equivalent to CTRL+C)
89+
# use wallet from joinin.conf
90+
source /home/joinmarket/joinin.conf
91+
pkill -sigint -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin"
92+
# pgrep python | xargs kill -sigint
93+
# remove the service
94+
sudo systemctl stop yg-privacyenhanced
95+
sudo systemctl disable yg-privacyenhanced
96+
# check for failed services
97+
# sudo systemctl list-units --type=service
98+
sudo systemctl reset-failed
99+
# make sure the lock file is deleted
100+
rm -f ~/.joinmarket/wallets/.$wallet.lock
101+
# for old version <v0.6.3
102+
rm -f ~/.joinmarket/wallets/$wallet.lock 2>/dev/null
103+
echo "# stopped the Yield Generator background service"
107104
}
108105

109106
function QRinTerminal() {
@@ -116,52 +113,52 @@ function QRinTerminal() {
116113
}
117114

118115
function feereport() {
119-
# puts the fees earned as a Maker into variables
120-
INPUT=/home/joinmarket/.joinmarket/logs/yigen-statement.csv
121-
allEarned=0
122-
allCoinjoins=0
123-
monthEarned=0
124-
monthCoinjoins=0
125-
weekEarned=0
126-
weekCoinjoins=0
127-
dayEarned=0
128-
dayCoinjoins=0
129-
unixtimeMonthAgo=$(date -d "1 month ago" +%s)
130-
unixtimeWeekAgo=$(date -d "1 week ago" +%s)
131-
unixtimeDayAgo=$(date -d "1 day ago" +%s)
132-
OLDIFS=$IFS
133-
IFS=","
134-
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
135-
#timestamp cj amount/satoshi my input count my input value/satoshi cjfee/satoshi earned/satoshi confirm time/min notes
136-
while read -r timestamp cj_amount_satoshi my_input_count my_input_value_satoshi cjfee_satoshi earned_satoshi confirm_time_min notes
137-
do
138-
unixtimeEvent=$(date -d "$timestamp" +%s 2>/dev/null)
139-
if [ "$earned_satoshi" -gt 0 ]; then
140-
allEarned=$(( allEarned + earned_satoshi ))
141-
allCoinjoins=$(( allCoinjoins + 1 ))
142-
if [ "$unixtimeEvent" -gt "$unixtimeMonthAgo" ]; then
143-
monthEarned=$(( monthEarned + earned_satoshi ))
144-
monthCoinjoins=$(( monthCoinjoins + 1 ))
145-
if [ "$unixtimeEvent" -gt "$unixtimeWeekAgo" ]; then
146-
weekEarned=$(( weekEarned + earned_satoshi ))
147-
weekCoinjoins=$((weekCoinjoins+1))
148-
if [ "$unixtimeEvent" -gt "$unixtimeDayAgo" ]; then
149-
dayEarned=$((dayEarned+earned_satoshi))
150-
dayCoinjoins=$((dayCoinjoins+1))
116+
# puts the fees earned as a Maker into variables
117+
INPUT=/home/joinmarket/.joinmarket/logs/yigen-statement.csv
118+
allEarned=0
119+
allCoinjoins=0
120+
monthEarned=0
121+
monthCoinjoins=0
122+
weekEarned=0
123+
weekCoinjoins=0
124+
dayEarned=0
125+
dayCoinjoins=0
126+
unixtimeMonthAgo=$(date -d "1 month ago" +%s)
127+
unixtimeWeekAgo=$(date -d "1 week ago" +%s)
128+
unixtimeDayAgo=$(date -d "1 day ago" +%s)
129+
OLDIFS=$IFS
130+
IFS=","
131+
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
132+
#timestamp cj amount/satoshi my input count my input value/satoshi cjfee/satoshi earned/satoshi confirm time/min notes
133+
while read -r timestamp cj_amount_satoshi my_input_count my_input_value_satoshi cjfee_satoshi earned_satoshi confirm_time_min notes
134+
do
135+
unixtimeEvent=$(date -d "$timestamp" +%s 2>/dev/null)
136+
if [ "$earned_satoshi" -gt 0 ]; then
137+
allEarned=$(( allEarned + earned_satoshi ))
138+
allCoinjoins=$(( allCoinjoins + 1 ))
139+
if [ "$unixtimeEvent" -gt "$unixtimeMonthAgo" ]; then
140+
monthEarned=$(( monthEarned + earned_satoshi ))
141+
monthCoinjoins=$(( monthCoinjoins + 1 ))
142+
if [ "$unixtimeEvent" -gt "$unixtimeWeekAgo" ]; then
143+
weekEarned=$(( weekEarned + earned_satoshi ))
144+
weekCoinjoins=$((weekCoinjoins+1))
145+
if [ "$unixtimeEvent" -gt "$unixtimeDayAgo" ]; then
146+
dayEarned=$((dayEarned+earned_satoshi))
147+
dayCoinjoins=$((dayCoinjoins+1))
148+
fi
151149
fi
152150
fi
153-
fi
154-
fi 2>/dev/null
155-
done < "$INPUT"
156-
IFS=$OLDIFS
151+
fi 2>/dev/null
152+
done < "$INPUT"
153+
IFS=$OLDIFS
157154
}
158155

159156
function YGuptime() {
160-
# puts the Yield Generator uptime to $JMUptime
161-
source /home/joinmarket/joinin.conf
162-
JMpid=$(pgrep -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin" 2>/dev/null | head -1)
163-
JMUptimeInSeconds=$(ps -p $JMpid -oetime= 2>/dev/null | tr '-' ':' | awk -F: '{ total=0; m=1; } { for (i=0; i < NF; i++) {total += $(NF-i)*m; m *= i >= 2 ? 24 : 60 }} {print total}')
164-
JMUptime=$(printf '%dd:%dh:%dm\n' $((JMUptimeInSeconds/86400)) $((JMUptimeInSeconds%86400/3600)) $((JMUptimeInSeconds%3600/60)))
157+
# puts the Yield Generator uptime to $JMUptime
158+
source /home/joinmarket/joinin.conf
159+
JMpid=$(pgrep -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin" 2>/dev/null | head -1)
160+
JMUptimeInSeconds=$(ps -p $JMpid -oetime= 2>/dev/null | tr '-' ':' | awk -F: '{ total=0; m=1; } { for (i=0; i < NF; i++) {total += $(NF-i)*m; m *= i >= 2 ? 24 : 60 }} {print total}')
161+
JMUptime=$(printf '%dd:%dh:%dm\n' $((JMUptimeInSeconds/86400)) $((JMUptimeInSeconds%86400/3600)) $((JMUptimeInSeconds%3600/60)))
165162
}
166163

167164

@@ -226,44 +223,72 @@ function installJoinMarket() {
226223

227224
# updateJoininBox <reset|commit>
228225
function updateJoininBox() {
229-
cd /home/joinmarket
230-
if [ "$1" = "reset" ];then
231-
echo "# Removing the joininbox source code"
232-
sudo rm -rf /home/joinmarket/joininbox
233-
echo "# Downloading the latest joininbox source code"
234-
fi
235-
# clone repo in case it is not present
236-
sudo -u joinmarket git clone https://github.com/openoms/joininbox.git \
237-
/home/joinmarket/joininbox 2>/dev/null
238-
echo "# Checking the updates in https://github.com/openoms/joininbox"
239-
# based on https://github.com/apotdevin/thunderhub/blob/master/scripts/updateToLatest.sh
240-
cd /home/joinmarket/joininbox
241-
# fetch latest master
242-
sudo -u joinmarket git fetch
243-
echo "# Pulling latest changes..."
244-
sudo -u joinmarket git pull -p
245-
if [ "$1" = "commit" ]; then
246-
TAG=$(git describe --tags)
247-
echo "# Updating to the latest commit in the default branch"
248-
else
249-
TAG=$(git tag | sort -V | tail -1)
250-
# unset $1
251-
set --
252-
UPSTREAM=${1:-'@{u}'}
253-
LOCAL=$(git rev-parse @)
254-
REMOTE=$(git rev-parse "$UPSTREAM")
255-
if [ $LOCAL = $REMOTE ]; then
256-
echo "# You are up-to-date on version" $TAG
226+
cd /home/joinmarket
227+
if [ "$1" = "reset" ];then
228+
echo "# Removing the joininbox source code"
229+
sudo rm -rf /home/joinmarket/joininbox
230+
echo "# Downloading the latest joininbox source code"
231+
fi
232+
# clone repo in case it is not present
233+
sudo -u joinmarket git clone https://github.com/openoms/joininbox.git \
234+
/home/joinmarket/joininbox 2>/dev/null
235+
echo "# Checking the updates in https://github.com/openoms/joininbox"
236+
# based on https://github.com/apotdevin/thunderhub/blob/master/scripts/updateToLatest.sh
237+
cd /home/joinmarket/joininbox
238+
# fetch latest master
239+
sudo -u joinmarket git fetch
240+
echo "# Pulling latest changes..."
241+
sudo -u joinmarket git pull -p
242+
if [ "$1" = "commit" ]; then
243+
TAG=$(git describe --tags)
244+
echo "# Updating to the latest commit in the default branch"
245+
else
246+
TAG=$(git tag | sort -V | tail -1)
247+
# unset $1
248+
set --
249+
UPSTREAM=${1:-'@{u}'}
250+
LOCAL=$(git rev-parse @)
251+
REMOTE=$(git rev-parse "$UPSTREAM")
252+
if [ $LOCAL = $REMOTE ]; then
253+
echo "# You are up-to-date on version" $TAG
254+
echo
255+
echo "Press ENTER to return to the menu"
256+
read key
257+
exit 0
258+
fi
259+
fi
260+
sudo -u joinmarket git reset --hard $TAG
261+
echo "# Updated to version" $TAG
262+
echo "# Copying the scripts in place"
263+
sudo -u joinmarket cp /home/joinmarket/joininbox/scripts/*.* /home/joinmarket/
264+
sudo -u joinmarket cp /home/joinmarket/joininbox/scripts/.* /home/joinmarket/ 2>/dev/null
265+
sudo -u joinmarket chmod +x /home/joinmarket/*.sh
266+
}
267+
268+
function setIRCtoTor() {
269+
#communicate with IRC servers via Tor
270+
sed -i "s/^host = irc.darkscience.net/#host = irc.darkscience.net/g" /home/joinmarket/.joinmarket/joinmarket.cfg
271+
sed -i "s/^#host = darksci3bfoka7tw.onion/host = darksci3bfoka7tw.onion/g" /home/joinmarket/.joinmarket/joinmarket.cfg
272+
sed -i "s/^host = irc.hackint.org/#host = irc.hackint.org/g" /home/joinmarket/.joinmarket/joinmarket.cfg
273+
sed -i "s/^#host = ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion/host = ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion/g" /home/joinmarket/.joinmarket/joinmarket.cfg
274+
sed -i "s/^socks5 = false/#socks5 = false/g" /home/joinmarket/.joinmarket/joinmarket.cfg
275+
sed -i "s/^#socks5 = true/socks5 = true/g" /home/joinmarket/.joinmarket/joinmarket.cfg
276+
sed -i "s/^#port = 6667/port = 6667/g" /home/joinmarket/.joinmarket/joinmarket.cfg
277+
sed -i "s/^#usessl = false/usessl = false/g" /home/joinmarket/.joinmarket/joinmarket.cfg
278+
echo "Edited the joinmarket.cfg to communicate over Tor only."
279+
}
280+
281+
function generateJMconfig() {
282+
if [ ! -f "/home/joinmarket/.joinmarket/joinmarket.cfg" ] ; then
283+
echo "# generating the joinmarket.cfg"
257284
echo
258-
echo "Press ENTER to return to the menu"
259-
read key
260-
exit 0
285+
. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate &&\
286+
cd /home/joinmarket/joinmarket-clientserver/scripts/
287+
python wallet-tool.py generate --datadir=/home/joinmarket/.joinmarket
288+
else
289+
echo "# the joinmarket.cfg is present"
290+
echo ""
261291
fi
262-
fi
263-
sudo -u joinmarket git reset --hard $TAG
264-
echo "# Updated to version" $TAG
265-
echo "# Copying the scripts in place"
266-
sudo -u joinmarket cp /home/joinmarket/joininbox/scripts/*.* /home/joinmarket/
267-
sudo -u joinmarket cp /home/joinmarket/joininbox/scripts/.* /home/joinmarket/ 2>/dev/null
268-
sudo -u joinmarket chmod +x /home/joinmarket/*.sh
269-
}
292+
# set strict permission to joinmarket.cfg
293+
sudo chmod 600 /home/joinmarket/.joinmarket/joinmarket.cfg || exit 1
294+
}

0 commit comments

Comments
 (0)