Skip to content

Instantly share code, notes, and snippets.

@owenvoke
Created June 6, 2018 08:55
Show Gist options
  • Save owenvoke/e49ea5e99396c886446ae9af3722e6d8 to your computer and use it in GitHub Desktop.
Save owenvoke/e49ea5e99396c886446ae9af3722e6d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
COIN_NAME='Arionum'
NODE_VERSION='master'
TMP_DIR=$(mktemp -d)
NODE_DIR='/var/www/arionum-node'
NODE_URL="https://github.com/arionum/node/archive/${NODE_VERSION}.tar.gz"
NODE_TGZ="${NODE_VERSION}.tar.gz"
HOST=$(hostname)
CONFIG_PATH='include/config.inc.php'
NODE_IP=$(curl -s4 icanhazip.com)
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
function downloadNode() {
echo -e "${GREEN}Preparing to download $COIN_NAME${NC}."
cd ${TMP_DIR} >/dev/null 2>&1
rm ${NODE_TGZ} >/dev/null 2>&1
wget -q ${NODE_URL}
installError
tar -xvzf ${NODE_TGZ} >/dev/null 2>&1
installError
cp -r node-${NODE_VERSION} ${NODE_DIR}
cd - >/dev/null 2>&1
rm -rf ${TMP_DIR} >/dev/null 2>&1
clear
}
function createConfig() {
echo -e "${GREEN}Updating configuration${NC}"
read -ep "Database name: " DB_NAME
read -ep "Database user: " DB_USER
read -esp "Database password: " DB_PASS
if [[ DB_NAME == '' || DB_USER == '' || DB_PASS == '' ]]; then
echo -e "${RED}One or more empty database details specified.${NC}"
exit 801
fi
sed -i -e "s/ENTER-DB-NAME/${DB_NAME}/g" ${NODE_DIR}/${CONFIG_PATH}
sed -i -e "s/ENTER-DB-USER/${DB_USER}/g" ${NODE_DIR}/${CONFIG_PATH}
sed -i -e "s/ENTER-DB-PASS/${DB_PASS}/g" ${NODE_DIR}/${CONFIG_PATH}
clear
}
function installError() {
if [ "$?" -gt "0" ]; then
echo -e "${RED}Failed to install ${COIN_NAME}.${NC}"
exit 1
fi
}
function checks() {
if [[ $(lsb_release -d) != *Ubuntu* ]]; then
echo -e "${RED}You are not running Ubuntu. Installation has been cancelled.${NC}"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}Installation must be run as the root user.${NC}"
exit 1
fi
if [ -d "${NODE_DIR}" ]; then
echo -e "${RED}An ${COIN_NAME} node is already installed.${NC}"
exit 802
fi
}
function prepareSystem() {
echo -e "Preparing the system to install an ${GREEN}$COIN_NAME Node${NC} on this Ubuntu server."
echo -e " "
echo -e "Leave this terminal session open until you are provided the final installation screen with your server details."
apt-get update > /dev/null 2>&1
apt-get -y -qq upgrade >/dev/null 2>&1
apt install -y software-properties-common >/dev/null 2>&1
echo -e "${GREEN}Adding the Ondrej PHP repository${NC}"
apt-add-repository -y ppa:ondrej/php >/dev/null 2>&1
echo -e " "
echo -e "Continuing to install the required software packages."
echo -e " "
echo -e "Please wait."
echo -e " "
apt-get update >/dev/null 2>&1
apt-get install -y curl php7.2 php7.2-gmp php7.2-pdo php7.2-bcmath >/dev/null 2>&1
if [ "$?" -gt "0" ]; then
echo -e "${RED}Not all required packages were installed properly. Try to install them manually by running the following commands one at a time:${NC}\n"
exit 1
fi
clear
}
function nodeInformation() {
clear
echo -e ""
echo -e "==================================================================================================="
echo -e " ${GREEN}CONGRATULATIONS!!!${NC} Your ${GREEN}$COIN_NAME${NC} node has been installed and is running."
echo -e "==================================================================================================="
echo -e " "
echo -e " ARIONUM NODE DETAILS"
echo -e " "
echo -e " Your $COIN_NAME node ${GREEN}alias${NC} is: ${RED}$HOST${NC}"
echo -e " Your $COIN_NAME node ${GREEN}address${NC} is: ${RED}$NODE_IP${NC}"
echo -e " "
echo -e " The $COIN_NAME node configuration file is located at:"
echo -e " ${RED}${NODE_DIR}/${CONFIG_PATH}${NC}"
echo -e " "
echo -e " "
}
function setupNode() {
createConfig
nodeInformation
}
# Main
checks
prepareSystem
downloadNode
setupNode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment