base: add error checking

This commit is contained in:
nahuhh 2024-11-09 20:39:55 +00:00
parent c319bcfcd3
commit fc7e543162
3 changed files with 75 additions and 47 deletions

View file

@ -7,8 +7,13 @@ nocolor="printf \e[0m"
## Clone basicswap git
cd $SWAP_DATADIR
git clone https://github.com/basicswap/basicswap
cd $SWAP_DATADIR/basicswap
if [[ -d basicswap ]]; then
cd $SWAP_DATADIR/basicswap
git pull || { $red"Failed to pull repo. Installation aborted"; exit; }
else
git clone https://github.com/basicswap/basicswap || { $red"Failed to clone repo. Please run the installer again"; exit; }
cd $SWAP_DATADIR/basicswap
fi
## Macos
if [[ $MACOS ]]; then
@ -19,17 +24,6 @@ fi
$SWAP_DATADIR/venv/bin/pip3 install -r requirements.txt --require-hashes
$SWAP_DATADIR/venv/bin/pip3 install .
## 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)
else
# Use public node
CURRENT_XMR_HEIGHT=$(curl http://node3.monerodevs.org:18089/get_info | jq .height)
fi
# Use Tor if we want
enable_tor() {
if [[ "$tor_on" = 1 ]]; then
@ -42,22 +36,26 @@ if [[ "$particl_mnemonic" && "$monerod_addr" ]]; then
# Restore seed
PARTICL_MNEMONIC=$particl_mnemonic
XMR_RPC_HOST=$monerod_addr XMR_RPC_PORT=$monerod_port \
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC"
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC" || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
enable_tor
elif [[ "$particl_mnemonic" ]]; then
# Restore seed
PARTICL_MNEMONIC=$particl_mnemonic
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC"
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC" || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
enable_tor
elif [[ "$monerod_addr" ]]; then
# Setup new install and use a remote monero node
XMR_RPC_HOST=$monerod_addr XMR_RPC_PORT=$monerod_port \
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
$red"\n\nMake note of your seed above\n\n"; $nocolor
enable_tor
else
# Setup new install using local nodes
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
$red"\n\nMake note of your seed above\n\n"; $nocolor
enable_tor
fi

View file

@ -7,8 +7,13 @@ nocolor="printf \e[0m"
## Clone basicswap git
cd $SWAP_DATADIR
git clone https://github.com/basicswap/basicswap
cd $SWAP_DATADIR/basicswap
if [[ -d basicswap ]]; then
cd $SWAP_DATADIR/basicswap
git pull || { $red"Failed to pull repo. Installation aborted"; exit; }
else
git clone https://github.com/basicswap/basicswap || { $red"Failed to clone repo. Please run the installer again"; exit; }
cd $SWAP_DATADIR/basicswap
fi
## Macos
if [[ $MACOS ]]; then
@ -19,17 +24,6 @@ fi
torsocks $SWAP_DATADIR/venv/bin/pip3 install -r requirements.txt --require-hashes
torsocks $SWAP_DATADIR/venv/bin/pip3 install .
## 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)
else
# Use public node
CURRENT_XMR_HEIGHT=$(curl http://node3.monerodevs.org:18089/get_info | jq .height)
fi
# Use Tor if we want
enable_tor() {
if [[ "$tor_on" = 1 ]]; then
@ -42,22 +36,26 @@ if [[ "$particl_mnemonic" && "$monerod_addr" ]]; then
# Restore seed
PARTICL_MNEMONIC=$particl_mnemonic
XMR_RPC_HOST=$monerod_addr XMR_RPC_PORT=$monerod_port \
torsocks basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC"
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC" || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
enable_tor
elif [[ "$particl_mnemonic" ]]; then
# Restore seed
PARTICL_MNEMONIC=$particl_mnemonic
torsocks basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC"
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 --particl_mnemonic="$PARTICL_MNEMONIC" || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
enable_tor
elif [[ "$monerod_addr" ]]; then
# Setup new install and use a remote monero node
XMR_RPC_HOST=$monerod_addr XMR_RPC_PORT=$monerod_port \
torsocks basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
$red"\n\nMake note of your seed above\n\n"; $nocolor
enable_tor
else
# Setup new install using local nodes
torsocks basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$CURRENT_XMR_HEIGHT --wowrestoreheight=600000
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 || { $red"Installation failed. Try again"; exit; }
$red"\n\nMonero wallet restore height is ${xmrrestoreheight}"; $nocolor
$red"\n\nMake note of your seed above\n\n"; $nocolor
enable_tor
fi

View file

@ -1,16 +1,41 @@
#/bin/bash
#set -x
export SWAP_DATADIR=$HOME/coinswaps
if [[ $USER == amnesia ]]; then
export SWAP_DATADIR=$HOME/Persistent/coinswaps
fi
# Colors
red="printf \e[31;1m"
green="printf \e[32;1m"
nocolor="printf \e[0m"
# Check if bsx is already installedo
chain=(particl monero wownero dash decred firo litecoin bitcoin bitcoincash pivx)
for coin in "${chain[@]}"; do
if [[ -f "${SWAP_DATADIR}/${coin}/${coin}.conf" ]]; then
printf "Existing configuration file found at ${SWAP_DATADIR}/${coin}/${coin}.conf\n"
abort=1
fi
if [[ -f "${SWAP_DATADIR}/${coin}/${coin}d.conf" ]]; then
printf "Existing configuration file found at ${SWAP_DATADIR}/${coin}/${coin}d.conf\n"
abort=1
fi
done
if [[ -f "${SWAP_DATADIR}/basicswap.json" ]]; then
printf "Existing configuration file(s) found at ${SWAP_DATADIR}/basicswap.json.\n"
abort=1
fi
if [[ $abort ]]; then
$red"Aborting install\n"; $nocolor; exit
fi
# Check if basicswap is running
if [[ -f $SWAP_DATADIR/particl/particl.pid ]]; then
bsx_pid=$(cat $SWAP_DATADIR/particl/particl.pid)
if [[ -f ${SWAP_DATADIR}/particl/particl.pid ]]; then
bsx_pid=$(cat ${SWAP_DATADIR}/particl/particl.pid)
if [[ $bsx_pid ]]; then
bsx_run=$(pidof particld | grep $bsx_pid)
bsx_run=$(pgrep particld | grep $bsx_pid)
if [[ $bsx_run ]]; then
$red"\nError: BasicSwapDEX is already installed.\n"; $nocolor
exit
@ -62,7 +87,7 @@ detect_os_arch() {
# Debian / Ubuntu / Mint
INSTALL="sudo apt install"
UPDATE="sudo apt update"
DEPENDENCY="python3-pip python3-venv libpython3-dev gnupg pkg-config"
DEPENDENCY="python3-pip python3-venv gnupg pkg-config"
elif type -p dnf > /dev/null; then
# Fedora
INSTALL="sudo dnf install"
@ -92,7 +117,7 @@ $INSTALL $DEPENDENCY automake libtool jq
# Enable tor
printf "\n[1] Tor ON (requires sudo)\n[2] Tor OFF\n"
until [[ "$tor_on" =~ ^[12]$ ]]; do
read -p 'Select an option: [1|2] ' tor_on
read -p 'Select an option: [1|2]: ' tor_on
case $tor_on in
1)
$green"BasicSwapDEX will use Tor\n";$nocolor
@ -109,7 +134,7 @@ done
## Particl restore Seed
printf "\n[1] New Install (default)\n[2] Restore from Particl Seed\n"
until [[ "$restore" =~ ^[12]$ ]]; do
read -p 'Select an option: [1|2] ' restore
read -p 'Select an option: [1|2]: ' restore
case $restore in
1)
$green"Installing BasicSwapDEX\n"; $nocolor
@ -167,10 +192,17 @@ read -p 'Select an option [1|2]: ' l
else
$red"The node at $monerod_addr:$monerod_port is not accessible. Try again\n"; $nocolor
fi
done
if [[ -z $xmrrestoreheight ]]; then
xmrrestoreheight="${checknode}"
fi
$green"Monero wallet Restore Height set to ${xmrrestoreheight}\n"; $nocolor
;;
2)
xmrrestoreheight=$(curl -s http://node3.monerodevs.org:18089/get_info | jq .height || { echo "Failed to get Monero blockchain height. Please run the installer again."; exit; })
$green"BasicSwapDEX will run the Monero node for you.\n"; $nocolor
$green"Monero wallet Restore Height set to ${xmrrestoreheight}\n"; $nocolor
;;
*)
$red"You must answer 1 or 2\n"; $nocolor
@ -214,12 +246,12 @@ fi
cp -r basicswap-bash bsx* $HOME/.local/bin/
## Make venv and set variables for install
export monerod_addr=$monerod_addr
export monerod_port=$monerod_port
export particl_mnemonic=$particl_mnemonic
export xmrrestoreheight=$xmrrestoreheight
export tor_on=$tor_on
export TAILS=$TAILS
python3 -m venv "$SWAP_DATADIR/venv"
export monerod_addr="${monerod_addr}"
export monerod_port="${monerod_port}"
export particl_mnemonic="${particl_mnemonic}"
export xmrrestoreheight="${xmrrestoreheight}"
export tor_on="${tor_on}"
export TAILS="${TAILS}"
python3 -m venv "${SWAP_DATADIR}/venv"
## Activate venv
$HOME/.local/bin/bsx/activate_venv.sh