Restore BSX from seed

This commit is contained in:
nahuhh 2024-02-04 21:03:49 -05:00
parent a2dc857a8a
commit 011eb56027
4 changed files with 125 additions and 43 deletions

View file

@ -1,28 +1,39 @@
#!/bin/bash
# TODO: check for tor instead of YOLOing it
# Install and configure tor
sudo apt install tor -y
# Check for Tor installation
torinstall=$(apt-cache policy tor | grep "Installed:" | grep -E -o "[0-9]\w+")
if [[ "$torinstall" ]]; then
echo -e "\nTor is already installed :)"
else
# Install and configure tor
echo "Installing Tor..."
sudo apt install tor -y
fi
# Create HashesControlPassword
echo -e "In the next step you'll choose a password. NOTE: It will be saved in PLAIN TEXT."
read -p "Enter a (new) tor control password [example: 123123] " torcontrolpass
# Edit /etc/tor/torrc
torhashedpass=$(tor --hash-password $torcontrolpass)
# Remove conflicting ControlPort if enabled
sudo sed -i -z "s/\nControlPort 9051//" /etc/tor/torrc
# Add New ControlPort and HashedControlPassword
echo -e "\n#Added by BSX\nControlPort 9051\nHashedControlPassword $torhashedpass" | sudo tee -a /etc/tor/torrc
enabledcontrol=$(echo "ControlPort 9051")
skipcontrol=$(grep -x "$enabledcontrol" /etc/tor/torrc)
if [[ $skipcontrol ]]; then
# Use Existing enabled ControlPort and append HashedControlPassword
echo -e "# Added by basicswap-bash\nHashedControlPassword $torhashedpass" | sudo tee -a /etc/tor/torrc
else
echo -e "# Added by basicswap-bash\n$enabledcontrol\nHashedControlPassword $torhashedpass" | sudo tee -a /etc/tor/torrc
fi
# Restart tor to apply
sudo systemctl restart tor
echo "waiting for tor" && sleep 5
echo "Waiting for Tor... 5sec" && sleep 5
# lol are we there yet?
TOR_PROXY_HOST=127.0.0.1
basicswap-prepare --datadir=$SWAP_DATADIR --enabletor
# Replace torpassword in various config files
# Workaround: Replace torpassword in various config files
oldtorpass=$(cat $SWAP_DATADIR/basicswap.json | jq -r .tor_control_password)
sed -i "s/$oldtorpass/$torcontrolpass/" $SWAP_DATADIR/*/*.conf $SWAP_DATADIR/basicswap.json
# localhost binding for btc/ltc/part (etc) configs
# Fix: localhost binding for btc/ltc/part (etc) configs
sed -i -z "s/\nbind=0.0.0.0/\nbind=127.0.0.1/" $SWAP_DATADIR/*/*.conf
# TODO edit use tor proxy for with coin upgrades

View file

@ -1,5 +1,10 @@
#!/bin/bash
# Colors
red="echo -e -n \e[31;1m"
green="echo -e -n \e[32;1m"
nocolor="echo -e -n \e[0m"
## Download & Install coincurve stuff
cd $SWAP_DATADIR
wget -O coincurve-anonswap.zip https://github.com/tecnovert/coincurve/archive/refs/tags/anonswap_v0.2.zip
@ -18,16 +23,31 @@ cd $SWAP_DATADIR/basicswap
protoc -I=basicswap --python_out=basicswap basicswap/messages.proto
pip3 install .
## Run basicswap-prepare with particl and monero
if [[ "$monerod_addr" && "$monerod_port" ]]; then
# Use remote Monero node
## Decide a source for Monero's restore height
if [[ "$xmrrestoreheight" ]]; then
CURRENT_XMR_HEIGHT=$xmrrestoreheight
elif [[ "$monerod_addr" ]]; then
# Use custom Monero node
CURRENT_XMR_HEIGHT=$(curl "http://$monerod_addr:$monerod_port/get_info" | jq .height)
XMR_RPC_HOST=$monerod_addr BASE_XMR_RPC_PORT=$monerod_port basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
else # Use BasicSwapDEX's Monero node
else
# Use public node
CURRENT_XMR_HEIGHT=$(curl https://localmonero.co/blocks/api/get_stats | jq .height)
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
fi
$red; echo -e "\n\nMake note of your seed above\n"; $nocolor
echo 'Install complete.
Use `basicswap-bash` to run, `bsx-update` to update, and `bsx-addcoin` to add a coin'
# Use the custom Monero node
if [[ "$monerod_addr" && "$particl_mnemonic" ]]; then
PARTICL_MNEMONIC=$particl_mnemonic
basicswap-prepare --datadir=$SWAP_DATADIR --particl_mnemonic="$PARTICL_MNEMONIC"
XMR_RPC_HOST=$monerod_addr BASE_XMR_RPC_PORT=$monerod_port basicswap-prepare --datadir=$SWAP_DATADIR --addcoin=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
elif [[ "$monerod_addr" ]]; then
XMR_RPC_HOST=$monerod_addr BASE_XMR_RPC_PORT=$monerod_port basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
$red"\n\nMake note of your seed above\n"; $nocolor
elif [[ "particl_mnemonic" ]]; then
PARTICL_MNEMONIC=$particl_mnemonic
basicswap-prepare --datadir=$SWAP_DATADIR --particl_mnemonic="$PARTICL_MNEMONIC"
else
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
$red"\n\nMake note of your seed above\n"; $nocolor
fi
$green"Install complete.\n\nUse 'basicswap-bash' to run, 'bsx-update' to update, and 'bsx-addcoin' to add a coin"; $nocolor

View file

@ -2,7 +2,7 @@
## Prompt for user input
echo "You can only update coins which you have already added to your install"
echo -e "\n\nList of coins supported by BasicSwapDEX (case sensitive):\nbitcoin\ndash\nfiro\nlitecoin\nparticl\nPIVX\n"
echo -e "\n\nList of coins supported by BasicSwapDEX (case sensitive):\nbitcoin\ndash\nfiro\nlitecoin\nmonero\nparticl\nPIVX\n"
read -p 'Full name of coin to update [example: litecoin] ' updatecoin
## Confirm

View file

@ -1,14 +1,13 @@
#/bin/bash
# Colors
cyan="echo -e -n \e[36;1m"
red="echo -e -n \e[31;1m"
green="echo -e -n \e[32;1m"
nocolor="echo -e -n \e[0m"
# Title Bar
$green "\n"
title="BasicSwapDEX installer"
title="BasicSwapDEX Installer"
COLUMNS=$(tput cols)
title_size=${#title}
span=$(((COLUMNS + title_size) / 2))
@ -17,33 +16,85 @@ printf "%${span}s\n" "$title"
printf "%${COLUMNS}s" " " | tr " " "*"
$nocolor
## Configure Monero node
echo -e "\n\n[1]Connect to a Monero node\n[2]Allow BasicSwapDEX to run a Monero node (+70GB)\n"
until [[ "$l" =~ ^[12]$ ]]; do
read -p 'Select an option: ' l
case $l in
1) read -p 'Enter Address of Monero node [example: 192.168.1.123] ' monerod_addr
read -p 'Enter RPC Port for the Monero node [example: 18081] ' monerod_port
$green "Look good? $monerod_addr:$monerod_port"; $nocolor;;
2) $green "\nBasicSwapDEX will run the Monero node for you."; $nocolor;;
*) $red "\nYou must answer 1 or 2\n"; $nocolor;;
## Particl restore Seed
echo -e "\n\n[1] New Install (default)\n[2] Restore from Particl Seed\n"
until [[ "$restore" =~ ^[12]$ ]]; do
read -p 'Select an option: [1|2] ' restore
case $restore in
1)
$green"\nInstalling BasicSwapDEX\n"; $nocolor
;;
2)
until [[ "$wordcount" = "24" ]]; do
read -p $'\nEnter your Particl Seed\n[example: word word word word word...] ' particl_mnemonic
wordcount=$(echo $particl_mnemonic | wc -w)
if [[ $wordcount = 24 ]]; then
echo -e "Restoring BasicSwapDEX"
$green"$particl_mnemonic\n";$nocolor
else
$red"Try again. Seed must be 24 words"; $nocolor
fi
done
;;
*)
$red"You must answer 1 or 2\n";$nocolor
;;
esac
done
echo -e "\nShall we begin?"
read -p 'Press any key to continue, or CTRL-C to exit.'
# Monero restore height
if [[ $particl_mnemonic ]]; then
read -p $'\nEnter a restore height for your BasicSwap XMR wallet? [Y/n] ' height
case $height in
n|N)
$red"\nNot using a custom XMR Restore height";$nocolor
;;
*)
until [[ "$xmrrestoreheight" =~ ^[0-9]{1,7}$ ]]; do
read -p $'Enter your Monero Restore Height [example: 2548568] ' xmrrestoreheight
if [[ $xmrrestoreheight =~ ^[0-9]{7}$ ]]; then
$green"\nYour XMR Restore height: $xmrrestoreheight"; $nocolor
else
$red"Try again. Must be 1-7 digits\n"; $nocolor
fi
done
;;
esac
fi
## Configure Monero
echo -e "\n[1] Connect to a Monero node\n[2] Allow BasicSwapDEX to run a Monero node (+70GB)\n"
until [[ "$l" =~ ^[12]$ ]]; do
read -p 'Select an option [1|2]: ' l
case $l in
1)
read -p 'Enter Address of Monero node [example: 192.168.1.123] ' monerod_addr
read -p 'Enter RPC Port for the Monero node [example: 18081] ' monerod_port
$green"\nLook good? $monerod_addr:$monerod_port"; $nocolor
;;
2)
$green"\nBasicSwapDEX will run the Monero node for you."; $nocolor
;;
*)
$red"You must answer 1 or 2\n"; $nocolor
;;
esac
done
## Begin Install
echo -e "\n\nShall we begin?"
read -p 'Press Enter to continue, or CTRL-C to exit.'
## Update & Install dependencies
sudo apt update
## python-is-python3 for ubuntu
sudo apt install -y git wget python-is-python3 python3-full python3-pip gnupg unzip protobuf-compiler automake libtool pkg-config curl jq
sudo apt update # python-is-python3 for ubuntu
sudo apt install -y git wget python-is-python3 python3-venv python3-pip gnupg unzip protobuf-compiler automake libtool pkg-config curl jq
# Move scripts to /usr/local/bin
sudo rm -r /usr/local/bin/bsx # Remove old
sudo mv -f -t /usr/local/bin/ basicswap-bash bsx* # Add new
## Make venv
sudo cp -r -f -t /usr/local/bin/ basicswap-bash bsx*
## Make venv and set variables for install
export SWAP_DATADIR=$HOME/coinswaps
export monerod_addr=$monerod_addr
export monerod_port=$monerod_port
export particl_mnemonic=$particl_mnemonic
export xmrrestoreheight=$xmrrestoreheight
mkdir -p "$SWAP_DATADIR/venv"
python3 -m venv "$SWAP_DATADIR/venv"
## Activate venv