Skip to content

Instantly share code, notes, and snippets.

@MiningBeaver
Last active July 13, 2019 09:04
Show Gist options
  • Save MiningBeaver/31082557774aab751ef84ccd828e1587 to your computer and use it in GitHub Desktop.
Save MiningBeaver/31082557774aab751ef84ccd828e1587 to your computer and use it in GitHub Desktop.
ElectrumX-MONA Install script for Ubuntu 18.04 (Japanese version)
#!/bin/bash
#English version:
#https://gist.github.com/MiningBeaver/07f2df001a32c67d490d9b26d854dd1a
#寄付歓迎。
#Monacoin:MBeaverua23KLV6wDXmm1iggkfRBFHoUAc
#Bitcoin:3DUFHmY6GUSqajoBYBWZhRAmxHkYfHxabM
# __ __ _
#| \/ | ___ _ __ __ _ ___ ___ (_)_ __
#| |\/| |/ _ \| '_ \ / _` |/ __/ _ \| | '_ \
#| | | | (_) | | | | (_| | (_| (_) | | | | |
#|_| |_|\___/|_| |_|\__,_|\___\___/|_|_| |_|
#このスクリプトを実行する前に下記を行ってください:
#adduser electrumx
#adduser electrumx sudo
#sudo apt -y install git
#su - electrumx
#上記が終わったらこのスクリプトを/home/electrumxの中に置いてください。
#このスクリプトを実行するには:
#bash install.sh
#check
if test `whoami` != electrumx ; then
echo 'ユーザーを"electrumx"に変えてください。'
echo 'もし"electrumx"で操作している場合、sudoを使わずに単に"bash install.sh"と入力してください。'
echo 'Exiting.'
exit
fi
sudo -v
if test $? != 0 ; then
echo 'sudoできません。'
echo 'sudoersファイルを確認してください。'
echo 'Exiting.'
exit
fi
cd /home/electrumx/
echo
if test -f .monacoin/monacoin.conf ; then
#If finded, get information by monacoin.conf
echo 'monacoin.confファイルを発見しました。'
echo '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 'monacoin.confファイルを発見できませんでした。'
while :
do
echo
echo 'Monacoindはインストール済みですか?(Y/N)'
read installedmona
if test -z "$installedmona" ; then
echo 'もう一度入力してください。'
elif test "$installedmona" = Y -o "$installedmona" = y ; then
break
elif test "$installedmona" = N -o "$installedmona" = n ; then
echo 'Monacoindをインストールしてからこのスクリプトを開いてください。'
echo 'Exiting.'
exit
else
echo 'もう一度入力してください。'
fi
done
fi
while :
do
echo
echo 'このサーバーのホストを入力してください。(www.example.com等)'
echo 'もしホスト名が存在しない場合はIPアドレスを入力してください。'
read hostname
if test -n "$installedmona";then
echo 'rpcuserを入れてください。'
read rpcuser
echo 'rpcpasswordを入れてください。'
read rpcpw
echo 'rpcportを入れてください。(もしデフォルトならば(9402)何も入力せずにエンターを押してください。)'
read rpcport
echo 'MonacoindのIPアドレスを入力してください。(もしローカルホストならば、何も入力せずにエンターを押してください。)'
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 'これでよろしいですか?(Y/N)'
read correct
if test -z "$correct" ; then
echo 'もう一度入力してください'
elif test "$correct" = Y -o "$correct" = y ; then
echo 'OK'
break
else
echo 'もう一度入力してください'
fi
installedmona=1
done
#Check option
while :
do
echo
echo 'LetsEncrypt SSLをインストールしますか?(Y/N)'
echo '(もしホスト名がない場合や、このサーバーにまだ割り当てていない場合、もしくは'
echo 'ポート80,443を使用中の場合は"N"を入力し、後ほど手動で行ってください。)'
read ssl
if test -z "$ssl" ; then
echo 'もう一度入力してください'
elif test "$ssl" = Y -o "$ssl" = y ; then
break
elif test "$ssl" = N -o "$ssl" = n ; then
break
else
echo 'もう一度入力してください'
fi
done
#Install upgrades
echo
echo 'Upgradeを入れています...'
sudo apt update
sudo apt -y upgrade
#Install depends
echo
echo 'dependsを入れています...'
sudo apt -y install git python3.6-dev python3-setuptools libleveldb-dev
#Clone git and install
echo
echo '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 '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 '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 'インストール完了!'
echo 'ElectrumXを起動する前にrebootすることをお勧めします。'
while :
do
echo
echo 'ブート時にElectrumXを起動するようにしますか?(Y/N)'
read startatboot
if test -z "$startatboot" ; then
echo 'もう一度入力してください'
elif test "$startatboot" = Y -o "$startatboot" = y ; then
sudo systemctl enable electrumx
break
elif test "$startatboot" = N -o "$startatboot" = n ; then
break
else
echo 'もう一度入力してください'
fi
done
echo
echo '以下のコマンドでElectrumXを実行できます'
echo '"sudo systemctl start electrumx"'
echo
echo '以下のコマンドでログが見られます。'
echo '"journalctl -u electrumx -f"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment