Skip to content

Commit e50d2c4

Browse files
committed
Allow to skip running mkp224o if onion keys already present on SSD
1 parent 5451f43 commit e50d2c4

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

tools/finalize-nakamochi.sh

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ patch_lnd_conf()
3535
run_main()
3636
{
3737
if [[ -z $2 ]]; then
38-
echo "Usage: $(basename "$0") /dev/sda2 /dev/sdb1 [/mnt/usd [/mnt/ssd]]"
38+
echo "Usage: $(basename "$0") [--skip-mkp224o] /dev/sda2 /dev/sdb1 [/mnt/usd [/mnt/ssd]]"
3939
echo "Where:"
40-
echo " /dev/sda2 - uSD card root partition (use '-' to not mount)"
41-
echo " /dev/sdb1 - SSD data partition (use '-' to not mount)"
42-
echo " /mnt/usd - uSD card mount point / directory"
43-
echo " /mnt/ssd - SSD mount point / directory"
40+
echo " /dev/sda2 - uSD card root partition (use '-' to not mount)"
41+
echo " /dev/sdb1 - SSD data partition (use '-' to not mount)"
42+
echo " /mnt/usd - uSD card mount point / directory"
43+
echo " /mnt/ssd - SSD mount point / directory"
44+
echo "Options:"
45+
echo " --skip-mkp224o - skip generating onion keys (requires them to be already present on SSD)"
4446
echo "Example: $(basename "$0") /dev/sdc2 /dev/sdd1"
4547
exit 1
4648
fi
@@ -50,9 +52,18 @@ run_main()
5052
exit 1
5153
fi
5254

53-
if ! check_exists mkp224o; then
54-
echo "Error: mkp224o is not installed."
55-
exit 1
55+
if [[ "$1" == "--skip-mkp224o" ]]; then
56+
shift
57+
skip_mkp224o=1
58+
else
59+
skip_mkp224o=0
60+
fi
61+
62+
if [[ "$skip_mkp224o" -eq 0 ]]; then
63+
if ! check_exists mkp224o; then
64+
echo "Error: mkp224o is not installed."
65+
exit 1
66+
fi
5667
fi
5768

5869
if [[ ! -x "$(dirname "$0")/rpcauth.py" ]]; then
@@ -128,6 +139,18 @@ run_main()
128139
exit 1
129140
fi
130141

142+
if [[ "$skip_mkp224o" -eq 1 ]]; then
143+
# check for existing onion keys
144+
if [[ ! -f "$SSD_MOUNT_POINT"/tor/bitcoind/hostname ]]; then
145+
echo "Error: $SSD_MOUNT_POINT/tor/bitcoind/hostname does not exist, cannot --skip-mkp224o."
146+
exit 1
147+
fi
148+
if [[ ! -f "$SSD_MOUNT_POINT"/tor/lnd/hostname ]]; then
149+
echo "Error: $SSD_MOUNT_POINT/tor/lnd/hostname does not exist, cannot --skip-mkp224o."
150+
exit 1
151+
fi
152+
fi
153+
131154
# check for existing lightning wallet
132155
if [[ -f "$SSD_MOUNT_POINT/lnd/data/chain/bitcoin/mainnet/wallet.db" ]]; then
133156
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@@ -139,7 +162,7 @@ run_main()
139162
rm -rf "$SSD_MOUNT_POINT"/lnd/*
140163
echo "done."
141164
echo -n "Removing wallet unlock file and clearing LND config ... "
142-
rm "$USD_MOUNT_POINT"/home/lnd/walletunlock.txt
165+
rm -f "$USD_MOUNT_POINT"/home/lnd/walletunlock.txt
143166
sed -i "s/^wallet-unlock-password-file=.*/;wallet-unlock-password-file=\/home\/lnd\/walletunlock.txt/" "$USD_MOUNT_POINT"/home/lnd/lnd.mainnet.conf
144167
echo "done."
145168
else
@@ -160,18 +183,21 @@ run_main()
160183
echo "$NAKAMOCHI_ID" > "$USD_MOUNT_POINT"/etc/nakamochi-id
161184
echo "$NAKAMOCHI_ID" > "$SSD_MOUNT_POINT"/nakamochi-id
162185

163-
# generate 2 onion services, one for bitcoind and one for lnd
164-
echo -n "Generating onion services ... "
165-
onion_tmp_dir="$(mktemp -d)"
166-
mkp224o -d "$onion_tmp_dir" -n 1 b
167-
mkp224o -d "$onion_tmp_dir" -n 1 l
168-
echo "done."
186+
if [[ "$skip_mkp224o" -eq 0 ]]; then
187+
# generate 2 onion services, one for bitcoind and one for lnd
188+
echo -n "Generating onion services ... "
189+
mkp224o -d "$SSD_MOUNT_POINT"/tor/bitcoind -n 1 b
190+
mkp224o -d "$SSD_MOUNT_POINT"/tor/lnd -n 1 l
191+
echo "done."
192+
fi
169193

170194
# copy the generated service directories to the SSD and fix user/group
171195
echo -n "Configuring onion services ... "
172-
mkdir -p "$SSD_MOUNT_POINT"/tor/{bitcoind,lnd}
173-
cp -r "$onion_tmp_dir"/b*/* "$SSD_MOUNT_POINT"/tor/bitcoind/
174-
cp -r "$onion_tmp_dir"/l*/* "$SSD_MOUNT_POINT"/tor/lnd/
196+
if [[ "$skip_mkp224o" -eq 0 ]]; then
197+
mkdir -p "$SSD_MOUNT_POINT"/tor/{bitcoind,lnd}
198+
cp -r "$SSD_MOUNT_POINT"/tor/bitcoind/* "$SSD_MOUNT_POINT"/tor/lnd/
199+
cp -r "$SSD_MOUNT_POINT"/tor/lnd/* "$SSD_MOUNT_POINT"/tor/bitcoind/
200+
fi
175201
onion_user_group="$(grep tor "$USD_MOUNT_POINT"/etc/passwd | cut -d: -f 3-4)"
176202
chown -R "$onion_user_group" "$SSD_MOUNT_POINT"/tor
177203
echo "done."

0 commit comments

Comments
 (0)