Last active
June 11, 2020 23:36
-
-
Save MiningBeaver/07f2df001a32c67d490d9b26d854dd1a to your computer and use it in GitHub Desktop.
ElectrumX-MONA Install script for Ubuntu 18.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Donation appreciated. | |
#Monacoin:MBeaverua23KLV6wDXmm1iggkfRBFHoUAc | |
#Bitcoin:3DUFHmY6GUSqajoBYBWZhRAmxHkYfHxabM | |
# __ __ _ | |
#| \/ | ___ _ __ __ _ ___ ___ (_)_ __ | |
#| |\/| |/ _ \| '_ \ / _` |/ __/ _ \| | '_ \ | |
#| | | | (_) | | | | (_| | (_| (_) | | | | | | |
#|_| |_|\___/|_| |_|\__,_|\___\___/|_|_| |_| | |
#Before run this script : | |
#adduser electrumx | |
#adduser electrumx sudo | |
#sudo apt -y install git | |
#su - electrumx | |
#If finished, copy this script to /home/electrumx/install.sh . | |
#To run this script : | |
#bash install.sh | |
#check | |
if test `whoami` != electrumx ; then | |
echo 'Please change user to "electrumx".' | |
echo 'If you are "electrumx", just type "bash install.sh".' | |
echo 'Exiting.' | |
exit | |
fi | |
sudo -v | |
if test $? != 0 ; then | |
echo 'Cannot sudo' | |
echo 'Please check sudoers' | |
echo 'Exiting.' | |
exit | |
fi | |
cd /home/electrumx/ | |
echo | |
if test -f .monacoin/monacoin.conf ; then | |
#If finded, get information by monacoin.conf | |
echo 'Finded monacoin.conf' | |
echo 'Automatically detect conf...' | |
rpcuser=`grep 'rpcuser=' .monacoin/monacoin.conf|cut -d '=' -f 2` | |
rpcpw=`grep 'rpcpassword=' .monacoin/monacoin.conf|cut -d '=' -f 2` | |
rpcport=`grep 'rpcport=' .monacoin/monacoin.conf|cut -d '=' -f 2` | |
rpcaddr=127.0.0.1 | |
else | |
echo 'Cannot finded monacoin.conf' | |
while : | |
do | |
echo | |
echo 'Already installed Monacoind?(Y/N)' | |
read installedmona | |
if test -z "$installedmona" ; then | |
echo 'Please retype' | |
elif test "$installedmona" = Y -o "$installedmona" = y ; then | |
break | |
elif test "$installedmona" = N -o "$installedmona" = n ; then | |
echo 'Please install monacoind first.' | |
echo 'Exiting.' | |
exit | |
else | |
echo 'Please retype' | |
fi | |
done | |
fi | |
while : | |
do | |
echo | |
echo 'Please type this server'"'"'s hostname(e.g. www.example.com)' | |
echo 'If you do not have hostname, please enter IP address' | |
read hostname | |
if test -n "$installedmona";then | |
echo 'Please type rpcuser' | |
read rpcuser | |
echo 'Please type rpcpassword' | |
read rpcpw | |
echo 'Please type rpcport(if default(9402), just hit return)' | |
read rpcport | |
echo 'Please type your Monacoind IP address(if localhost, just hit return)' | |
read rpchost | |
fi | |
if test -z "$rpcport" ; then | |
rpcport=9402 | |
fi | |
if test -z "$rpchost" ; then | |
rpchost=127.0.0.1 | |
fi | |
echo | |
echo | |
echo "RPC user:$rpcuser" | |
echo "RPC password:$rpcpw" | |
echo "RPC port:$rpcport" | |
echo "Monacoind IP address:$rpchost" | |
echo "ElectrumX hostname or IP address:$hostname" | |
echo 'Is this correct?(Y/N)' | |
read correct | |
if test -z "$correct" ; then | |
echo 'Please retype' | |
elif test "$correct" = Y -o "$correct" = y ; then | |
echo 'OK' | |
break | |
else | |
echo 'Please retype' | |
fi | |
installedmona=1 | |
done | |
#Check option | |
while : | |
do | |
echo | |
echo 'Install LetsEncrypt SSL?(Y/N)' | |
echo '(If you do not have hostname, or if you not your domain name pointed to this server,' | |
echo 'or using port 80, 443 , Enter "N"!)' | |
read ssl | |
if test -z "$ssl" ; then | |
echo 'Please retype' | |
elif test "$ssl" = Y -o "$ssl" = y ; then | |
break | |
elif test "$ssl" = N -o "$ssl" = n ; then | |
break | |
else | |
echo 'Please retype' | |
fi | |
done | |
#Install upgrades | |
echo | |
echo 'Installing Upgrades...' | |
sudo apt update | |
sudo apt -y upgrade | |
#Install depends | |
echo | |
echo 'Installing depends...' | |
sudo apt -y install git python3.6-dev python3-setuptools libleveldb-dev | |
#Clone git and install | |
echo | |
echo 'Installing ElectrumX...' | |
git clone https://github.com/kyuupichan/electrumx.git | |
cd ~/electrumx | |
sudo python3.6 setup.py install | |
sudo mkdir /var/electrumx | |
sudo chown electrumx.electrumx /var/electrumx | |
cd contrib/systemd | |
sudo cp electrumx.service /etc/systemd/system/ | |
#Install cert (Optional) | |
if test "$ssl" = Y -o "$ssl" = y ; then | |
echo | |
echo | |
echo 'Installing SSL...' | |
sudo iptables -I INPUT -j ACCEPT -p tcp -m multiport --dports 80,443 | |
sudo apt -y install letsencrypt | |
sudo letsencrypt certonly --standalone -d $hostname | |
sudo iptables -D INPUT 1 | |
fi | |
#Create electrumx.conf | |
echo | |
echo 'This is electrumx.conf' | |
echo | |
echo | |
cd /etc | |
echo '# default /etc/electrumx.conf for systemd' | sudo tee electrumx.conf | |
echo | sudo tee -a electrumx.conf | |
echo '# REQUIRED' | sudo tee -a electrumx.conf | |
echo 'DB_DIRECTORY = /var/electrumx' | sudo tee -a electrumx.conf | |
echo 'USERNAME = electrumx' | sudo tee -a electrumx.conf | |
echo '# Monacoin Node RPC Credentials' | sudo tee -a electrumx.conf | |
echo "DAEMON_URL = http://$rpcuser:$rpcpw@$rpchost:$rpcport/" | sudo tee -a electrumx.conf | |
echo | sudo tee -a electrumx.conf | |
echo '# Coinname' | sudo tee -a electrumx.conf | |
echo 'COIN = Monacoin' | sudo tee -a electrumx.conf | |
echo | sudo tee -a electrumx.conf | |
echo '# See http://electrumx.readthedocs.io/en/latest/environment.html for' | sudo tee -a electrumx.conf | |
echo '# information about other configuration settings you probably want to consider.' | sudo tee -a electrumx.conf | |
echo | sudo tee -a electrumx.conf | |
echo 'HOST = 0.0.0.0' | sudo tee -a electrumx.conf | |
echo 'TCP_PORT = 50001' | sudo tee -a electrumx.conf | |
echo 'SSL_PORT = 50002' | sudo tee -a electrumx.conf | |
echo "REPORT_HOST = $hostname" | sudo tee -a electrumx.conf | |
echo 'REPORT_TCP_PORT = 50001' | sudo tee -a electrumx.conf | |
echo 'REPORT_SSL_PORT = 50002' | sudo tee -a electrumx.conf | |
if test "$ssl" = Y -o "$ssl" = y ; then | |
echo | sudo tee -a electrumx.conf | |
echo "SSL_CERTFILE = /etc/letsencrypt/live/$hostname/fullchain.pem" | sudo tee -a electrumx.conf | |
echo "SSL_KEYFILE = /etc/letsencrypt/live/$hostname/privkey.pem" | sudo tee -a electrumx.conf | |
cd letsencrypt | |
sudo chown -R root.electrumx live/ | |
sudo chmod -R 750 live/ | |
sudo chown -R root.electrumx archive/ | |
sudo chmod -R 750 archive/ | |
fi | |
sudo iptables -A INPUT -j ACCEPT -p tcp -m multiport --dports 50001,50002 | |
echo | |
echo 'Installation complete!' | |
echo 'You should reboot before to run ElectrumX.' | |
while : | |
do | |
echo | |
echo 'Do you want to start ElectrumX at boot?(Y/N)' | |
read startatboot | |
if test -z "$startatboot" ; then | |
echo 'Please retype' | |
elif test "$startatboot" = Y -o "$startatboot" = y ; then | |
sudo systemctl enable electrumx | |
break | |
elif test "$startatboot" = N -o "$startatboot" = n ; then | |
break | |
else | |
echo 'Please retype' | |
fi | |
done | |
echo | |
echo 'To run ElectrumX' | |
echo '"sudo systemctl start electrumx"' | |
echo | |
echo 'You can see the log by' | |
echo '"journalctl -u electrumx -f"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment