basicswap-bash/install.sh

264 lines
7.5 KiB
Bash
Raw Permalink Normal View History

2024-01-21 22:34:44 +00:00
#/bin/bash
2024-11-09 20:39:55 +00:00
#set -x
2024-09-16 20:58:53 +00:00
export SWAP_DATADIR=$HOME/coinswaps
2024-11-09 20:39:55 +00:00
if [[ $USER == amnesia ]]; then
export SWAP_DATADIR=$HOME/Persistent/coinswaps
fi
2024-01-21 22:34:44 +00:00
# Colors
2024-11-09 03:03:53 +00:00
red="printf \e[31;1m"
green="printf \e[32;1m"
nocolor="printf \e[0m"
2024-11-09 20:39:55 +00:00
# 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
2024-09-16 20:58:53 +00:00
# Check if basicswap is running
2024-11-09 20:39:55 +00:00
if [[ -f ${SWAP_DATADIR}/particl/particl.pid ]]; then
bsx_pid=$(cat ${SWAP_DATADIR}/particl/particl.pid)
2024-09-16 20:58:53 +00:00
if [[ $bsx_pid ]]; then
2024-11-09 20:39:55 +00:00
bsx_run=$(pgrep particld | grep $bsx_pid)
2024-09-16 20:58:53 +00:00
if [[ $bsx_run ]]; then
$red"\nError: BasicSwapDEX is already installed.\n"; $nocolor
exit
fi
fi
fi
# Title Bar
2024-01-26 10:31:51 +00:00
$green "\n"
2024-02-05 02:03:49 +00:00
title="BasicSwapDEX Installer"
COLUMNS=$(tput cols)
title_size=${#title}
span=$(((COLUMNS + title_size) / 2))
2024-11-09 03:03:53 +00:00
printf "%${COLUMNS}s" " " | tr " " "#"
printf "%${span}s\n" "$title"
2024-11-09 03:03:53 +00:00
printf "%${COLUMNS}s" " " | tr " " "#"
$nocolor
2024-02-25 13:28:40 +00:00
# Detect Operating system
INSTALL=""
UPDATE=""
DEPENDENCY=""
2024-06-04 02:20:34 +00:00
TAILS=""
check_tails() {
2024-11-09 03:03:53 +00:00
if [[ $USER == amnesia ]]; then
$green"\n\nDetected Tails";$nocolor
2024-06-04 02:20:34 +00:00
TAILS=1
else
2024-11-09 03:03:53 +00:00
$green"\n\nDetected Debian";$nocolor
2024-06-04 02:20:34 +00:00
fi
}
2024-02-25 13:28:40 +00:00
detect_os_arch() {
2024-11-07 17:08:42 +00:00
if [[ $(uname -s) = "Darwin" ]]; then
# MacOS
export MACOS=1
2024-11-09 03:03:53 +00:00
if type -p brew > /dev/null; then
2024-11-07 17:08:42 +00:00
$green"Homebrew is installed\n";$nc
INSTALL="brew install"
else
$green"Installing Homebrew\n";$nc
INSTALL="curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | /bin/bash && brew install"
fi
DEPENDENCY="python gnupg pkg-config"
2024-11-09 03:03:53 +00:00
$green"\n\nDetected MacOS";$nocolor
elif type -p apt > /dev/null; then
2024-06-04 02:20:34 +00:00
check_tails
2024-02-25 13:28:40 +00:00
# Debian / Ubuntu / Mint
INSTALL="sudo apt install"
UPDATE="sudo apt update"
2024-11-09 20:39:55 +00:00
DEPENDENCY="python3-pip python3-venv gnupg pkg-config"
2024-11-09 03:03:53 +00:00
elif type -p dnf > /dev/null; then
2024-02-25 13:28:40 +00:00
# Fedora
INSTALL="sudo dnf install"
UPDATE="sudo dnf check-update"
2024-06-04 02:20:34 +00:00
DEPENDENCY="python3-virtualenv python3-pip python3-devel gnupg2 pkgconf"
2024-11-09 03:03:53 +00:00
$green"\n\nDetected Fedora";$nocolor
elif type -p pacman > /dev/null; then
2024-02-25 13:28:40 +00:00
# Arch Linux
INSTALL="sudo pacman -S"
UPDATE="sudo pacman -Syu"
2024-11-09 03:03:53 +00:00
DEPENDENCY="curl python-pipenv gnupg pkgconf base-devel"
$green"\n\nDetected Arch Linux";$nocolor
2024-10-18 20:49:40 +00:00
elif type -P apk > /dev/null; then
# Alpine Linux
INSTALL="sudo apk add"
UPDATE="sudo apk update"
DEPENDENCY="py3-virtualenv python3-dev gnupg gcc musl-dev"
$green"\nDetected Alpine Linux";$nocolor
2024-02-25 13:28:40 +00:00
else
2024-11-09 03:03:53 +00:00
$red"\nFailed to detect OS. Unsupported or unknown distribution.\nInstall Failed.\n";$nocolor
2024-02-25 13:28:40 +00:00
exit
fi
}
detect_os_arch
## Update & Install dependencies
2024-11-09 03:03:53 +00:00
printf "\n\nInstalling dependencies\nPress CTRL-C at password prompt(s) to skip. If skipped, you must install the dependencies manually before proceeding\n\n"
2024-09-21 03:23:43 +00:00
$green"$UPDATE\n$INSTALL $DEPENDENCY curl automake libtool jq\n"; $nocolor
$UPDATE
2024-11-09 03:03:53 +00:00
$INSTALL $DEPENDENCY automake libtool jq
2024-02-25 13:28:40 +00:00
# Enable tor
2024-11-09 03:03:53 +00:00
printf "\n[1] Tor ON (requires sudo)\n[2] Tor OFF\n"
2024-02-25 13:28:40 +00:00
until [[ "$tor_on" =~ ^[12]$ ]]; do
2024-11-09 20:39:55 +00:00
read -p 'Select an option: [1|2]: ' tor_on
2024-02-25 13:28:40 +00:00
case $tor_on in
1)
2024-11-09 03:03:53 +00:00
$green"BasicSwapDEX will use Tor\n";$nocolor
2024-02-25 13:28:40 +00:00
;;
2)
2024-11-09 03:03:53 +00:00
$red"BasicSwapDEX will NOT use Tor\n";$nocolor
2024-02-25 13:28:40 +00:00
;;
*)
$red"You must answer 1 or 2\n";$nocolor
;;
esac
done
2024-02-05 02:03:49 +00:00
## Particl restore Seed
2024-11-09 03:03:53 +00:00
printf "\n[1] New Install (default)\n[2] Restore from Particl Seed\n"
2024-02-05 02:03:49 +00:00
until [[ "$restore" =~ ^[12]$ ]]; do
2024-11-09 20:39:55 +00:00
read -p 'Select an option: [1|2]: ' restore
2024-02-05 02:03:49 +00:00
case $restore in
1)
2024-11-09 03:03:53 +00:00
$green"Installing BasicSwapDEX\n"; $nocolor
2024-02-05 02:03:49 +00:00
;;
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
2024-11-09 03:03:53 +00:00
printf "Restoring BasicSwapDEX\n"
2024-02-05 02:03:49 +00:00
$green"$particl_mnemonic\n";$nocolor
else
2024-11-09 03:03:53 +00:00
$red"Try again. Seed must be 24 words\n"; $nocolor
2024-02-05 02:03:49 +00:00
fi
done
;;
*)
$red"You must answer 1 or 2\n";$nocolor
;;
esac
done
# 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)
2024-11-09 03:03:53 +00:00
$red"Not using a custom XMR Restore height\n";$nocolor
2024-02-05 02:03:49 +00:00
;;
*)
until [[ "$xmrrestoreheight" =~ ^[0-9]{1,7}$ ]]; do
read -p $'Enter your Monero Restore Height [example: 2548568] ' xmrrestoreheight
if [[ $xmrrestoreheight =~ ^[0-9]{7}$ ]]; then
2024-11-09 03:03:53 +00:00
$green"Your XMR Restore height: $xmrrestoreheight\n"; $nocolor
2024-02-05 02:03:49 +00:00
else
$red"Try again. Must be 1-7 digits\n"; $nocolor
fi
done
;;
esac
fi
## Configure Monero
2024-11-09 03:03:53 +00:00
printf "\n[1] Connect to a Monero node\n[2] Allow BasicSwapDEX to run a Monero node (+70GB)\n"
2024-01-26 10:31:51 +00:00
until [[ "$l" =~ ^[12]$ ]]; do
2024-02-05 02:03:49 +00:00
read -p 'Select an option [1|2]: ' l
2024-01-26 10:31:51 +00:00
case $l in
2024-02-05 02:03:49 +00:00
1)
2024-06-05 00:31:08 +00:00
until [[ $checknode ]]; do
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
2024-11-09 03:03:53 +00:00
checknode=$(curl -sk http://$monerod_addr:$monerod_port/get_info | jq .height)
2024-06-05 00:31:08 +00:00
if [[ $checknode ]]; then
2024-11-09 03:03:53 +00:00
$green"Successfully connected to the XMR node @ $monerod_addr:$monerod_port\n"; $nocolor
2024-06-05 00:31:08 +00:00
else
2024-11-09 03:03:53 +00:00
$red"The node at $monerod_addr:$monerod_port is not accessible. Try again\n"; $nocolor
2024-06-05 00:31:08 +00:00
fi
2024-11-09 20:39:55 +00:00
2024-06-05 00:31:08 +00:00
done
2024-11-09 20:39:55 +00:00
if [[ -z $xmrrestoreheight ]]; then
xmrrestoreheight="${checknode}"
fi
$green"Monero wallet Restore Height set to ${xmrrestoreheight}\n"; $nocolor
2024-02-05 02:03:49 +00:00
;;
2)
2024-11-09 20:39:55 +00:00
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; })
2024-11-09 03:03:53 +00:00
$green"BasicSwapDEX will run the Monero node for you.\n"; $nocolor
2024-11-09 20:39:55 +00:00
$green"Monero wallet Restore Height set to ${xmrrestoreheight}\n"; $nocolor
2024-02-05 02:03:49 +00:00
;;
*)
$red"You must answer 1 or 2\n"; $nocolor
;;
2024-01-26 10:31:51 +00:00
esac
done
2024-01-21 22:34:44 +00:00
2024-02-05 02:03:49 +00:00
## Begin Install
2024-11-09 03:03:53 +00:00
printf "\nInstalling BasicSwapDEX\n"
2024-02-05 02:03:49 +00:00
read -p 'Press Enter to continue, or CTRL-C to exit.'
2024-06-05 18:36:36 +00:00
# Quest to make trasher happy
2024-10-09 12:34:42 +00:00
addpath='PATH="$HOME/.local/bin:$PATH"'
2024-10-17 19:43:16 +00:00
trasherdk=$(echo $PATH | grep -F '.local/bin')
2024-10-17 16:57:40 +00:00
if [[ ! -d $HOME/.local/bin ]]; then
2024-10-09 12:34:42 +00:00
mkdir -p $HOME/.local/bin
2024-10-17 16:57:40 +00:00
fi
if [[ -z $trasherdk ]]; then
2024-10-09 12:34:42 +00:00
# Bash
if [[ -f $HOME/.bashrc ]]; then
echo "export $addpath" | tee -a $HOME/.bashrc
fi
# Zsh
if [[ -f $HOME/.zshrc ]]; then
echo "export $addpath" | tee -a $HOME/.zshrc
fi
# xfce4
if [[ -f $HOME/.xsessionrc ]]; then
echo "export $addpath" | tee -a $HOME/.xsessionrc
fi
2024-06-05 18:36:36 +00:00
fi
2024-10-09 12:34:42 +00:00
2024-06-05 18:36:36 +00:00
# Move scripts to .local/bin
2024-09-16 19:17:57 +00:00
if [[ -d $HOME/.local/bin/bsx ]]; then
2024-10-09 12:34:42 +00:00
rm -r $HOME/.local/bin/bsx* $HOME/.local/bin/basicswap-bash
2024-06-05 18:36:36 +00:00
fi
2024-11-07 17:48:57 +00:00
cp -r basicswap-bash bsx* $HOME/.local/bin/
2024-06-05 18:36:36 +00:00
2024-02-05 02:03:49 +00:00
## Make venv and set variables for install
2024-11-09 20:39:55 +00:00
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"
2024-01-21 22:34:44 +00:00
## Activate venv
2024-06-05 18:36:36 +00:00
$HOME/.local/bin/bsx/activate_venv.sh