#!/bin/bash -x NODEJS_VERSION=v20.12.2 WWW_DNS=$1 API_DNS=$2 CF_DNS_API_TOKEN=$3 CERTBOT_EMAIL=$4 test -z $WWW_DNS && WWW_DNS="moneroocean.stream" test -z $API_DNS && API_DNS="api.moneroocean.stream" test -z $CF_DNS_API_TOKEN && CF_DNS_API_TOKEN="n/a" test -z $CERTBOT_EMAIL && CERTBOT_EMAIL="support@moneroocean.stream" if [[ $(whoami) != "root" ]]; then echo "Please run this script as root" exit 1 fi DEBIAN_FRONTEND=noninteractive apt-get update DEBIAN_FRONTEND=noninteractive apt-get full-upgrade -y timedatectl set-timezone Etc/UTC adduser --disabled-password --gecos "" user grep -q "user ALL=(ALL) NOPASSWD:ALL" /etc/sudoers || echo "user ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers su user -c "mkdir /home/user/.ssh" if [ -f "/root/.ssh/authorized_keys" ]; then mv /root/.ssh/authorized_keys /home/user/.ssh/authorized_keys chown user:user /home/user/.ssh/authorized_keys chmod 600 /home/user/.ssh/authorized_keys sed -i 's/#\?PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config sed -i 's/#\?PermitRootLogin .\+/PermitRootLogin no/g' /etc/ssh/sshd_config sed -i 's/#\?PermitEmptyPasswords .\+/PermitEmptyPasswords no/g' /etc/ssh/sshd_config service ssh restart fi ufw default deny incoming ufw default allow outgoing ufw allow ssh ufw allow 443 ufw --force enable cat >/root/.vimrc <<'EOF' colorscheme desert set fo-=ro EOF cat >/home/user/.vimrc <<'EOF' colorscheme desert set fo-=ro EOF chown user:user /home/user/.vimrc DEBIAN_FRONTEND=noninteractive apt-get install -y nginx ntp sudo snap install --classic certbot snap set certbot trust-plugin-with-root=ok snap install certbot-dns-cloudflare find /snap/certbot -name options-ssl-nginx.conf | xargs -I{} cp {} /etc/letsencrypt/options-ssl-nginx.conf echo "dns_cloudflare_api_token=$CF_DNS_API_TOKEN" >/root/dns_cloudflare_api_token.ini chmod 600 /root/dns_cloudflare_api_token.ini certbot certonly --non-interactive --agree-tos --email "$CERTBOT_EMAIL" --dns-cloudflare --dns-cloudflare-propagation-seconds 30 --dns-cloudflare-credentials /root/dns_cloudflare_api_token.ini -d $WWW_DNS certbot certonly --non-interactive --agree-tos --email "$CERTBOT_EMAIL" --dns-cloudflare --dns-cloudflare-propagation-seconds 30 --dns-cloudflare-credentials /root/dns_cloudflare_api_token.ini -d $API_DNS cat >/etc/nginx/sites-enabled/default <~/wallets/wallet_pass echo 1 | /usr/local/src/monero/build/release/bin/monero-wallet-cli --offline --create-address-file --generate-new-wallet ~/wallets/wallet --password-file ~/wallets/wallet_pass --command address echo 1 | /usr/local/src/monero/build/release/bin/monero-wallet-cli --offline --create-address-file --generate-new-wallet ~/wallets/wallet_fee --password-file ~/wallets/wallet_pass --command address EOF ) | su user -l echo; echo; echo read -p "*** Write down your seeds for wallet and wallet_fee listed above and press ENTER to continue ***" cat >/lib/systemd/system/monero.service <<'EOF' [Unit] Description=Monero Daemon After=network.target [Service] ExecStart=/usr/local/src/monero/build/release/bin/monerod --hide-my-port --prune-blockchain --enable-dns-blocklist --no-zmq --out-peers 64 --non-interactive --restricted-rpc --block-notify '/bin/bash /home/user/nodejs-pool/block_notify.sh' Restart=always User=monerodaemon Nice=10 CPUQuota=400% [Install] WantedBy=multi-user.target EOF useradd -m monerodaemon -d /home/monerodaemon systemctl daemon-reload systemctl enable monero systemctl start monero sleep 30 echo "Please wait until Monero daemon is fully synced" tail -f /home/monerodaemon/.bitmonero/bitmonero.log 2>/dev/null | grep Synced & ( tail -F -n0 /home/monerodaemon/.bitmonero/bitmonero.log & ) | egrep -q "You are now synchronized with the network" killall tail 2>/dev/null echo "Monero daemon is synced" DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server ROOT_SQL_PASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) (cat </root/mysql_pass chmod 600 /root/mysql_pass grep max_connections /etc/mysql/my.cnf || cat >>/etc/mysql/my.cnf <<'EOF' [mysqld] max_connections = 10000 EOF systemctl restart mysql (cat <>/home/user/.bashrc echo 'export PATH=/home/user/.bin:$PATH' >>/home/user/.bashrc for i in mdb_copy mdb_dump mdb_load mdb_stat; do cp \$i /home/user/.bin/; done ) npm install -g pm2 pm2 install pm2-logrotate 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 /home/user/pool_db sed -r 's#("db_storage_path": ).*#\1"/home/user/pool_db/",#' config_example.json >config.json mysql -u root --password=$ROOT_SQL_PASS