2024-01-21 22:34:44 +00:00
#/bin/bash
2024-01-22 22:06:38 +00:00
# Colors
red = "echo -e -n \e[31;1m"
green = "echo -e -n \e[32;1m"
nocolor = "echo -e -n \e[0m"
# Title Bar
2024-01-26 10:31:51 +00:00
$green "\n"
2024-02-05 02:03:49 +00:00
title = "BasicSwapDEX Installer"
2024-01-22 22:06:38 +00:00
COLUMNS = $( tput cols)
title_size = ${# title }
span = $(( ( COLUMNS + title_size) / 2 ))
printf " % ${ COLUMNS } s " " " | tr " " "*"
printf " % ${ span } s\n " " $title "
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( ) {
if [ $USER = = amnesia ] ; then
$green "\nDetected Tails\n" ; $nocolor
TAILS = 1
else
$green "\nDetected Debian\n" ; $nocolor
fi
}
2024-02-25 13:28:40 +00:00
detect_os_arch( ) {
if 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-06-04 02:20:34 +00:00
DEPENDENCY = "python-is-python3 python3-pip python3-venv gnupg pkg-config"
2024-02-25 13:28:40 +00:00
elif type -P dnf > /dev/null; then
# 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-02-25 13:28:40 +00:00
$green "\nDetected Fedora\n" ; $nocolor
elif type -P pacman > /dev/null; then
# Arch Linux
INSTALL = "sudo pacman -S"
UPDATE = "sudo pacman -Syu"
2024-06-04 02:20:34 +00:00
DEPENDENCY = "python-pipenv gnupg pkgconf base-devel"
2024-02-25 13:28:40 +00:00
$green "\nDetected Arch Linux\n" ; $nocolor
elif type -P brew > /dev/null; then
# MacOS
INSTALL = "brew install"
2024-06-04 02:20:34 +00:00
DEPENDENCY = "python gnupg pkg-config"
2024-02-25 13:28:40 +00:00
$green "\nDetected MacOS\n" ; $nocolor
else
$red "Failed to detect OS. Unsupported or unknown distribution.\nInstall Failed." ; $nocolor
exit
fi
}
2024-07-08 13:37:49 +00:00
2024-02-25 13:28:40 +00:00
detect_os_arch
2024-06-06 12:34:03 +00:00
## Update & Install dependencies
echo -e "\n\nInstalling dependencies\nPress CTRL-C at password prompt(s) to skip. If skipped, you must install the dependencies manually before proceeding"
$green " $UPDATE \n $INSTALL $DEPENDENCY git curl wget unzip automake libtool jq\n " ; $nocolor
$UPDATE
$INSTALL $DEPENDENCY git curl wget unzip automake libtool jq
2024-02-25 13:28:40 +00:00
# Enable tor
2024-06-05 18:36:36 +00:00
echo -e "\n\n[1] Tor ON (requires sudo)\n[2] Tor OFF\n"
2024-02-25 13:28:40 +00:00
until [ [ " $tor_on " = ~ ^[ 12] $ ] ] ; do
read -p 'Select an option: [1|2] ' tor_on
case $tor_on in
1)
$green "\nBasicSwapDEX will use Tor" ; $nocolor
; ;
2)
$red "\nBasicSwapDEX will NOT use Tor" ; $nocolor
; ;
*)
$red "You must answer 1 or 2\n" ; $nocolor
; ;
esac
done
2024-02-05 02:03:49 +00:00
## 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
# 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"
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
checknode = $( curl -sk http://$monerod_addr :$monerod_port /get_info)
if [ [ $checknode ] ] ; then
$green " \nSuccessfully connected to the XMR node @ $monerod_addr : $monerod_port " ; $nocolor
else
$red " \nThe node at $monerod_addr : $monerod_port is not accessible. Try again\n\n " ; $nocolor
fi
done
2024-02-05 02:03:49 +00:00
; ;
2)
$green "\nBasicSwapDEX will run the Monero node for you." ; $nocolor
; ;
*)
$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-06-05 18:36:36 +00:00
echo -e "\n\nInstalling BasicSwapDEX"
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
trasherdk = $( echo $PATH | grep $USER /.local/bin)
if ! [ [ $trasherdk ] ] ; then
mkdir -p $HOME /.local/bin
fi
# Move scripts to .local/bin
if [ -d $HOME /.local/bin/bsx ] ; then
rm -r $HOME /.local/bin/bsx* $HOME /.local/bin/basicswap-bash
fi
mv -f -t $HOME /.local/bin/ basicswap-bash bsx*
2024-07-08 13:37:49 +00:00
# Enable .profile detection on XFCE
xfce_check = $( echo $XDG_CURRENT_DESKTOP | grep XFCE)
xsessionrc_check = $( cat ~/.xsessionrc | grep '. ~/.profile' )
if [ [ $xfce_chek ] ] && [ [ -z $xsessionrc_check ] ] ; then
echo '. ~/.profile' | tee -a ~/.xsessionrc
fi
2024-06-05 18:36:36 +00:00
2024-02-05 02:03:49 +00:00
## Make venv and set variables for install
2024-01-21 22:34:44 +00:00
export SWAP_DATADIR = $HOME /coinswaps
export monerod_addr = $monerod_addr
export monerod_port = $monerod_port
2024-02-05 02:03:49 +00:00
export particl_mnemonic = $particl_mnemonic
export xmrrestoreheight = $xmrrestoreheight
2024-02-25 13:28:40 +00:00
export tor_on = $tor_on
2024-06-04 02:20:34 +00:00
export TAILS = $TAILS
2024-01-21 22:34:44 +00:00
mkdir -p " $SWAP_DATADIR /venv "
2024-02-25 13:28:40 +00:00
python -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