deployment-azure/nodes/bootnode/install.sh

133 lines
4.0 KiB
Bash
Raw Normal View History

2017-06-30 11:48:28 -07:00
#!/bin/bash
2017-06-20 13:16:07 -07:00
set -e
set -u
set -x
2017-11-20 07:12:39 -08:00
# this should be provided through env by azure template
TEMPLATES_BRANCH="${TEMPLATES_BRANCH}"
2017-11-16 14:18:26 -08:00
echo "========== ${TEMPLATES_BRANCH}/bootnode/install.sh starting =========="
2017-06-20 13:16:07 -07:00
echo "===== current time: $(date)"
echo "===== username: $(whoami)"
echo "===== working directory: $(pwd)"
echo "===== operating system info:"
lsb_release -a
echo "===== memory usage info:"
free -m
2017-11-16 14:18:26 -08:00
EXT_IP="$(curl ifconfig.co)"
2017-06-23 13:04:31 -07:00
echo "===== external ip: ${EXT_IP}"
2017-11-16 14:18:26 -08:00
2017-11-17 01:50:46 -08:00
echo "===== downloading common.vars"
2017-11-21 13:15:10 -08:00
curl -sLO "https://raw.githubusercontent.com/oraclesorg/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.vars"
2017-11-17 01:50:46 -08:00
source common.vars
2017-11-21 13:15:10 -08:00
INSTALL_CONFIG_REPO="${REPO_BASE_PATH}/bootnode"
echo "===== INSTALL_CONFIG_REPO: ${INSTALL_CONFIG_REPO}"
2017-06-20 13:16:07 -07:00
# this should be provided through env by azure template
2017-10-02 14:18:38 -07:00
NETSTATS_SERVER="${NETSTATS_SERVER}"
2017-06-20 13:16:07 -07:00
NETSTATS_SECRET="${NETSTATS_SECRET}"
NODE_FULLNAME="${NODE_FULLNAME:-Bootnode}"
NODE_ADMIN_EMAIL="${NODE_ADMIN_EMAIL:-somebody@somehere}"
ADMIN_USERNAME="${ADMIN_USERNAME}"
2017-07-03 02:46:18 -07:00
export HOME="${HOME:-/home/${ADMIN_USERNAME}}"
2017-06-20 13:16:07 -07:00
2017-11-17 01:47:40 -08:00
echo "===== environmental variables:"
printenv
2017-11-16 14:30:27 -08:00
echo "===== downloading common.funcs"
2017-11-21 13:15:10 -08:00
curl -sLO "https://raw.githubusercontent.com/oraclesorg/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.funcs"
2017-11-16 14:30:27 -08:00
source common.funcs
2017-06-20 13:16:07 -07:00
2017-11-10 03:04:34 -08:00
setup_ufw() {
2017-11-10 06:23:57 -08:00
echo "=====> setup_ufw"
2017-11-10 03:04:34 -08:00
sudo sudo ufw enable
2017-11-10 04:56:08 -08:00
sudo ufw default deny incoming
2017-11-10 05:43:45 -08:00
sudo ufw allow 443
2017-11-10 05:20:34 -08:00
sudo ufw allow 8545
2017-11-10 03:04:34 -08:00
sudo ufw allow 22/tcp
sudo ufw allow 30303/tcp
sudo ufw allow 30303/udp
2017-11-10 06:23:57 -08:00
echo "<===== setup_ufw"
2017-11-10 03:04:34 -08:00
}
2017-06-20 13:16:07 -07:00
pull_image_and_configs() {
echo "=====> pull_image_and_configs"
# curl -s -O "${INSTALL_CONFIG_REPO}/../${GENESIS_JSON}"
curl -s -o "${GENESIS_JSON}" "${GENESIS_REPO_LOC}"
2017-10-21 09:14:44 -07:00
curl -s -o "bootnodes.txt" "${BOOTNODES_TXT}"
2017-11-16 14:44:55 -08:00
curl -s -O "${INSTALL_CONFIG_REPO}/node.toml"
2017-06-23 13:38:09 -07:00
sed -i "/\[network\]/a nat=\"extip:${EXT_IP}\"" ${NODE_TOML}
2017-10-25 06:42:42 -07:00
#sed -i "/\[network\]/a bootnodes=\[$(cat bootnodes.txt | sed 's/\r$//' | awk -F'#' '{ print $1 }' | awk '/enode/{ print "\""$1"\"" }' | paste -sd "," -)\]" ${NODE_TOML}
sed -i "/\[network\]/a reserved_peers=\"/home/${ADMIN_USERNAME}/bootnodes.txt\"" ${NODE_TOML}
2017-08-28 12:04:43 -07:00
cat >> ${NODE_TOML} <<EOF
[misc]
log_file = "/home/${ADMIN_USERNAME}/logs/parity.log"
EOF
2017-11-16 14:18:26 -08:00
mkdir -p parity_data/keys/OraclesPoA
2017-06-20 13:16:07 -07:00
echo "<===== pull_image_and_configs"
}
clone_dapps() {
echo "=====> clone_dapps"
2017-11-16 14:18:26 -08:00
mkdir -p parity_data/dapps
git clone -b ${DAPPS_BRANCH} --single-branch https://github.com/oraclesorg/oracles-dapps-keys-generation.git parity_data/dapps/KeysGenerator
git clone -b ${DAPPS_BRANCH} --single-branch https://github.com/oraclesorg/oracles-dapps-voting.git parity_data/dapps/Voting
git clone -b ${DAPPS_BRANCH} --single-branch https://github.com/oraclesorg/oracles-dapps-validators.git parity_data/dapps/ValidatorsList
2017-06-20 13:16:07 -07:00
echo "<===== clone_dapps"
}
2017-11-10 06:23:57 -08:00
gen_certs() {
echo "=====> gen_certs"
mkdir certs
openssl req -x509 -newkey rsa:4096 -nodes -subj "/CN=${EXT_IP}" -keyout certs/key.pem -out certs/cert.pem -days 1095
echo "<===== gen_certs"
}
install_nginx() {
echo "=====> install_nginx"
sudo apt-get install -y nginx
curl -sL "${NGINX_FILE_LOC}" | sed "s/ADMIN_USERNAME/${ADMIN_USERNAME}/g" | sudo tee /etc/nginx/sites-enabled/default > /dev/null
2017-11-10 08:20:11 -08:00
sudo service nginx restart
2017-11-10 06:23:57 -08:00
echo "<===== install_nginx"
}
2017-06-20 13:16:07 -07:00
# MAIN
main () {
2017-07-07 09:50:47 -07:00
sudo apt-get update
2017-06-20 13:16:07 -07:00
prepare_homedir
2017-11-10 03:04:34 -08:00
setup_ufw
2017-10-27 07:04:34 -07:00
increase_ulimit_n
2017-06-20 13:16:07 -07:00
install_ntpd
install_haveged
allocate_swap
install_nodejs
pull_image_and_configs
clone_dapps
2017-11-16 14:18:26 -08:00
if [ "${PARITY_INSTALLATION_MODE}" = "BIN" ]; then
use_bin_via_systemd
elif [ "${PARITY_INSTALLATION_MODE}" = "DEB" ]; then
use_deb_via_systemd
else
echo "===== invalid PARITY_INSTALLATION_MODE == ${PARITY_INSTALLATION_MODE}. Should be either BIN or DEB"
exit 1
fi
2017-11-16 09:09:07 -08:00
2017-11-10 06:23:57 -08:00
gen_certs
install_nginx
2017-09-29 08:29:56 -07:00
2017-08-31 03:37:40 -07:00
start_pm2_via_systemd
2017-08-28 12:04:43 -07:00
install_netstats_via_systemd
2017-08-28 12:04:43 -07:00
configure_logrotate
2017-06-20 13:16:07 -07:00
}
main
2017-11-16 14:18:26 -08:00
echo "========== ${TEMPLATES_BRANCH}/bootnode/install.sh finished =========="