2017-02-10 21:33:17 -08:00
#!/bin/bash
echo "This assumes that you are doing a green-field install. If you're not, please exit in the next 15 seconds."
sleep 15
echo "Continuing install, this will prompt you for your password if you're not already running as root and you didn't enable passwordless sudo. Please do not run me as root!"
if [ [ ` whoami` = = "root" ] ] ; then
echo "You ran me as root! Do not run me as root!"
exit 1
fi
ROOT_SQL_PASS = $( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
CURUSER = $( whoami)
2019-05-08 03:05:08 +03:00
SERVER_IP = $( dig +short myip.opendns.com @resolver1.opendns.com)
API_URL = " http:// $SERVER_IP :8000/leafApi "
2019-05-08 00:29:32 +03:00
WALLET_PASSWORD = ` cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
2019-05-08 03:05:08 +03:00
read -p " Enter a pool API URL or leave it blank for default ( $API_URL ): " USER_API_URL
2019-05-08 00:29:32 +03:00
printf "\n"
2019-05-08 03:05:08 +03:00
if [ [ ! -z $USER_API_URL ] ] ; then
API_URL = $USER_API_URL
2019-05-07 22:15:22 +03:00
fi
2019-05-08 00:29:32 +03:00
read -p "Enter a Mailgun key:" MAILGUN_KEY
printf "\n"
read -p "Enter a Mailgun URL:" MAILGUN_URL
printf "\n"
read -p "Enter an address for outgoing emails:" EMAIL_FROM
printf "\n"
2017-10-24 22:07:27 +02:00
sudo timedatectl set-timezone Etc/UTC
2017-02-10 21:33:17 -08:00
sudo apt-get update
sudo DEBIAN_FRONTEND = noninteractive apt-get -y upgrade
sudo debconf-set-selections <<< " mysql-server mysql-server/root_password password $ROOT_SQL_PASS "
sudo debconf-set-selections <<< " mysql-server mysql-server/root_password_again password $ROOT_SQL_PASS "
echo -e " [client]\nuser=root\npassword= $ROOT_SQL_PASS " | sudo tee /root/.my.cnf
2017-03-05 16:05:09 -08:00
sudo DEBIAN_FRONTEND = noninteractive apt-get -y install git python-virtualenv python3-virtualenv curl ntp build-essential screen cmake pkg-config libboost-all-dev libevent-dev libunbound-dev libminiupnpc-dev libunwind8-dev liblzma-dev libldns-dev libexpat1-dev libgtest-dev mysql-server lmdb-utils libzmq3-dev
2017-02-10 21:33:17 -08:00
cd ~
2026-04-01 22:24:13 +01:00
git clone https://github.com/letheanVPN/lethean-nodejs-pool.git # Change this depending on how the deployment goes.
2017-02-10 21:33:17 -08:00
cd /usr/src/gtest
sudo cmake .
sudo make
sudo mv libg* /usr/lib/
cd ~
sudo systemctl enable ntp
cd /usr/local/src
2026-04-01 22:24:13 +01:00
sudo git clone --recursive https://github.com/letheanVPN/lethean.git
cd lethean
2019-04-23 00:46:26 +03:00
sudo git checkout master
sudo mkdir build
sudo cd build
sudo cmake ..
2017-02-21 17:01:50 +02:00
sudo make -j$( nproc)
2019-05-08 00:29:32 +03:00
cd ~
export LC_ALL = C
unset LANGUAGE
2026-04-01 22:24:13 +01:00
POOL_WALLET = ` /usr/local/src/lethean/build/release/src/simplewallet --generate-new-wallet " /home/ $CURUSER /lethean.wallet " --password " $WALLET_PASSWORD " | grep "Generated new wallet" | awk '{ print $4 }' `
echo " $WALLET_PASSWORD " > " /home/ $CURUSER /lethean.wallet.passwd "
echo " Generated a new wallet $POOL_WALLET in /home/ $CURUSER /lethean.wallet with the password in /home/ $CURUSER /lethean.wallet.passwd. "
2019-05-08 00:29:32 +03:00
echo "!!! PLEASE BACK IT UP !!!"
2026-04-01 22:24:13 +01:00
sudo screen -S lethean -dm bash -c "/usr/local/src/lethean/build/release/src/letheand"
sudo screen -S simplewallet -dm bash -c " /usr/local/src/lethean/build/release/src/simplewallet --wallet-file /home/ $CURUSER /lethean.wallet --password `cat /home/ $CURUSER /lethean.wallet.passwd` --rpc-bind-port 46942 "
2017-02-10 21:33:17 -08:00
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
source ~/.nvm/nvm.sh
2017-12-20 04:52:29 -08:00
nvm install v8.9.3
2026-04-01 22:24:13 +01:00
cd ~/lethean-nodejs-pool
2017-02-10 21:33:17 -08:00
npm install
npm install -g pm2
openssl req -subj "/C=IT/ST=Pool/L=Daemon/O=Mining Pool/CN=mining.pool" -newkey rsa:2048 -nodes -keyout cert.key -x509 -out cert.pem -days 36500
mkdir ~/pool_db/
2019-05-07 22:15:22 +03:00
cp config_example.json config.json
2019-05-08 03:05:08 +03:00
sed -r " s/(\"db_storage_path\": ).*/\1\"\/home\/ $CURUSER \/pool_db\/\",/ ; s/(\"bind_ip\": ).*/\1\" $SERVER_IP \",/ ; s/(\"hostname\": ).*/\1\" $SERVER_IP \",/ " config_example.json > config.json
2026-04-01 22:24:13 +01:00
sed -i " s/localhost/ $SERVER_IP /g " /home/$CURUSER /lethean-nodejs-pool/frontend/app/globals.js
sed -i " s/localhost/ $SERVER_IP /g " /home/$CURUSER /lethean-nodejs-pool/frontend/app/globals.default.js
cd ~/lethean-nodejs-pool/frontend
2017-02-10 21:33:17 -08:00
npm install
2017-02-14 10:32:21 -08:00
./node_modules/bower/bin/bower update
./node_modules/gulp/bin/gulp.js build
cd build
2017-02-10 21:33:17 -08:00
sudo ln -s ` pwd ` /var/www
2017-02-19 14:32:45 +02:00
CADDY_DOWNLOAD_DIR = $( mktemp -d)
cd $CADDY_DOWNLOAD_DIR
2019-04-23 20:37:46 +03:00
curl -sL "https://github.com/mholt/caddy/releases/download/v0.11.4/caddy_v0.11.4_linux_amd64.tar.gz" | tar -xz caddy init/linux-systemd/caddy.service
2017-02-19 14:32:45 +02:00
sudo mv caddy /usr/local/bin
2017-02-10 21:33:17 -08:00
sudo chown root:root /usr/local/bin/caddy
sudo chmod 755 /usr/local/bin/caddy
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
sudo groupadd -g 33 www-data
sudo useradd -g www-data --no-user-group --home-dir /var/www --no-create-home --shell /usr/sbin/nologin --system --uid 33 www-data
sudo mkdir /etc/caddy
sudo chown -R root:www-data /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R www-data:root /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
2026-04-01 22:24:13 +01:00
sudo cp ~/lethean-nodejs-pool/deployment/caddyfile /etc/caddy/Caddyfile
2017-02-10 21:33:17 -08:00
sudo chown www-data:www-data /etc/caddy/Caddyfile
sudo chmod 444 /etc/caddy/Caddyfile
2017-02-19 14:32:45 +02:00
sudo sh -c "sed 's/ProtectHome=true/ProtectHome=false/' init/linux-systemd/caddy.service > /etc/systemd/system/caddy.service"
2017-02-10 21:33:17 -08:00
sudo chown root:root /etc/systemd/system/caddy.service
2017-09-06 12:31:48 +02:00
sudo chmod 644 /etc/systemd/system/caddy.service
2017-02-10 21:33:17 -08:00
sudo systemctl daemon-reload
sudo systemctl enable caddy.service
sudo systemctl start caddy.service
2017-02-19 14:32:45 +02:00
rm -rf $CADDY_DOWNLOAD_DIR
2017-02-10 21:33:17 -08:00
cd ~
2017-12-20 04:53:22 -08:00
sudo env PATH = $PATH :` pwd ` /.nvm/versions/node/v8.9.3/bin ` pwd ` /.nvm/versions/node/v8.9.3/lib/node_modules/pm2/bin/pm2 startup systemd -u $CURUSER --hp ` pwd `
2026-04-01 22:24:13 +01:00
cd ~/lethean-nodejs-pool
2017-02-10 21:33:17 -08:00
sudo chown -R $CURUSER . ~/.pm2
2017-02-12 14:13:10 -08:00
echo "Installing pm2-logrotate in the background!"
pm2 install pm2-logrotate &
2017-02-10 21:33:17 -08:00
mysql -u root --password= $ROOT_SQL_PASS < deployment/base.sql
2017-02-11 02:33:38 -08:00
mysql -u root --password= $ROOT_SQL_PASS pool -e "INSERT INTO pool.config (module, item, item_value, item_type, Item_desc) VALUES ('api', 'authKey', '`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`', 'string', 'Auth key sent with all Websocket frames for validation.')"
mysql -u root --password= $ROOT_SQL_PASS pool -e "INSERT INTO pool.config (module, item, item_value, item_type, Item_desc) VALUES ('api', 'secKey', '`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`', 'string', 'HMAC key for Passwords. JWT Secret Key. Changing this will invalidate all current logins.')"
2019-05-07 22:15:22 +03:00
mysql -u root --password= $ROOT_SQL_PASS pool -e " UPDATE pool.config SET item_value = ' $POOL_WALLET ' WHERE module = 'pool' and item = 'address'; "
2019-05-08 00:29:32 +03:00
mysql -u root --password= $ROOT_SQL_PASS pool -e " UPDATE pool.config SET item_value = ' $POOL_WALLET ' WHERE module = 'payout' and item = 'feeAddress'; "
2019-05-07 22:15:22 +03:00
mysql -u root --password= $ROOT_SQL_PASS pool -e " UPDATE pool.config SET item_value = ' $API_URL ' WHERE module = 'general' and item = 'shareHost'; "
mysql -u root --password= $ROOT_SQL_PASS pool -e " UPDATE pool.config SET item_value = ' $MAILGUN_KEY ' WHERE module = 'general' and item = 'mailgunKey'; "
mysql -u root --password= $ROOT_SQL_PASS pool -e " UPDATE pool.config SET item_value = ' $MAILGUN_URL ' WHERE module = 'general' and item = 'mailgunURL'; "
mysql -u root --password= $ROOT_SQL_PASS pool -e " UPDATE pool.config SET item_value = ' $EMAIL_FROM ' WHERE module = 'general' and item = 'emailFrom'; "
2019-05-08 15:42:41 +03:00
pm2 start init.js --name= blockManager --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= blockManager
pm2 start init.js --name= worker --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= worker
pm2 start init.js --name= payments --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= payments
pm2 start init.js --name= remoteShare --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= remoteShare
pm2 start init.js --name= longRunner --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= longRunner
pm2 start init.js --name= pool --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= pool
2017-02-11 12:01:51 -08:00
pm2 start init.js --name= api --log-date-format= "YYYY-MM-DD HH:mm Z" -- --module= api
2026-04-01 22:24:13 +01:00
bash ~/lethean-nodejs-pool/deployment/install_lmdb_tools.sh
cd ~/lethean-nodejs-pool/sql_sync/
2017-12-21 06:46:34 -08:00
env PATH = $PATH :` pwd ` /.nvm/versions/node/v8.9.3/bin node sql_sync.js
2017-02-14 08:52:54 -08:00
echo "You're setup! Please read the rest of the readme for the remainder of your setup and configuration. These steps include: Setting your Fee Address, Pool Address, Global Domain, and the Mailgun setup!"
2019-05-08 03:05:08 +03:00
printf "\n"
2019-05-08 00:29:32 +03:00
echo "!!! DO NOT FORGET TO BACK UP THE GENERATED WALLET AND ITS PASSWORD !!!"
2019-05-08 03:05:08 +03:00
printf "\n"