2024-01-30 03:38:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-02-25 13:28:40 +00:00
|
|
|
# Colors
|
|
|
|
red="echo -e -n \e[31;1m"
|
|
|
|
green="echo -e -n \e[32;1m"
|
|
|
|
nocolor="echo -e -n \e[0m"
|
|
|
|
|
|
|
|
# Detect Operating system
|
|
|
|
INSTALL=""
|
|
|
|
UPDATE=""
|
|
|
|
INIT_TOR="sudo systemctl restart tor"
|
|
|
|
detect_os_arch() {
|
|
|
|
if type -P apt > /dev/null; then
|
|
|
|
# Debian / Ubuntu / Mint
|
|
|
|
INSTALL="sudo apt install -y"
|
|
|
|
UPDATE="sudo apt update"
|
|
|
|
$green"\nDetected Debian\n";$nocolor
|
|
|
|
elif type -P dnf > /dev/null; then
|
|
|
|
# Fedora
|
|
|
|
INSTALL="sudo dnf install -y"
|
|
|
|
UPDATE="sudo dnf check-update"
|
|
|
|
$green"\nDetected Fedora\n";$nocolor
|
|
|
|
elif type -P pacman > /dev/null; then
|
|
|
|
# Arch Linux
|
|
|
|
INSTALL="sudo pacman -S"
|
|
|
|
UPDATE="sudo pacman -Syu"
|
|
|
|
$green"\nDetected Arch Linux\n";$nocolor
|
|
|
|
elif type -P brew > /dev/null; then
|
|
|
|
# MacOS
|
|
|
|
INSTALL="brew install"
|
|
|
|
$green"\nDetected MacOS\n";$nocolor
|
|
|
|
else
|
|
|
|
$red"Failed to detect OS. Unsupported or unknown distribution.\nInstall Failed.";$nocolor
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_os_arch
|
|
|
|
|
2024-02-05 02:03:49 +00:00
|
|
|
# Check for Tor installation
|
2024-02-25 13:28:40 +00:00
|
|
|
if type -P tor > /dev/null; then
|
2024-02-05 02:03:49 +00:00
|
|
|
echo -e "\nTor is already installed :)"
|
|
|
|
else
|
|
|
|
# Install and configure tor
|
|
|
|
echo "Installing Tor..."
|
2024-02-25 13:28:40 +00:00
|
|
|
$UPDATE
|
|
|
|
$INSTALL tor
|
2024-02-05 02:03:49 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-30 03:38:18 +00:00
|
|
|
# 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
|
2024-02-05 02:03:49 +00:00
|
|
|
# Edit /etc/tor/torrc
|
2024-01-30 03:38:18 +00:00
|
|
|
torhashedpass=$(tor --hash-password $torcontrolpass)
|
2024-02-05 02:03:49 +00:00
|
|
|
enabledcontrol=$(echo "ControlPort 9051")
|
2024-06-04 02:20:34 +00:00
|
|
|
skipcontrol=$(sudo grep -x "$enabledcontrol" /etc/tor/torrc)
|
|
|
|
echo "Check torrc for enabled ControlPort"
|
2024-02-05 02:03:49 +00:00
|
|
|
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
|
2024-01-30 03:38:18 +00:00
|
|
|
|
|
|
|
# Restart tor to apply
|
2024-02-25 13:28:40 +00:00
|
|
|
$INIT_TOR
|
2024-02-05 02:03:49 +00:00
|
|
|
echo "Waiting for Tor... 5sec" && sleep 5
|
2024-01-30 03:38:18 +00:00
|
|
|
|
|
|
|
# lol are we there yet?
|
|
|
|
TOR_PROXY_HOST=127.0.0.1
|
|
|
|
basicswap-prepare --datadir=$SWAP_DATADIR --enabletor
|
2024-02-05 02:03:49 +00:00
|
|
|
|
|
|
|
# Workaround: Replace torpassword in various config files
|
2024-01-30 03:38:18 +00:00
|
|
|
oldtorpass=$(cat $SWAP_DATADIR/basicswap.json | jq -r .tor_control_password)
|
|
|
|
sed -i "s/$oldtorpass/$torcontrolpass/" $SWAP_DATADIR/*/*.conf $SWAP_DATADIR/basicswap.json
|
2024-02-05 02:03:49 +00:00
|
|
|
# Fix: localhost binding for btc/ltc/part (etc) configs
|
2024-01-30 03:38:18 +00:00
|
|
|
sed -i -z "s/\nbind=0.0.0.0/\nbind=127.0.0.1/" $SWAP_DATADIR/*/*.conf
|