Created
September 14, 2020 17:22
-
-
Save Bharat-B/b2f4bea356c25f1fad0ed9a47ab2ef6d to your computer and use it in GitHub Desktop.
Install.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ECHO_PATH=/usr/bin/echo | |
TEE_PATH=/usr/bin/tee | |
YUM_PATH=/usr/bin/yum | |
CURL_PATH=/usr/bin/curl | |
TAR_PATH=/usr/bin/tar | |
WGET_PATH=/usr/bin/wget | |
INSTALL_LOG=./hypervisor-install.log | |
function menu() { | |
clear; | |
${ECHO_PATH} " o----------------------------------------------------------------o"; | |
${ECHO_PATH} " | :: Hypervisor Master Installer v1.0 (2020/08/31) |"; | |
${ECHO_PATH} " o----------------------------------------------------------------o"; | |
${ECHO_PATH} " | |"; | |
${ECHO_PATH} " | Thank you for choosing Hypervisor as your orchestrator! |"; | |
${ECHO_PATH} " | For any issues email [email protected] |"; | |
${ECHO_PATH} " | |"; | |
${ECHO_PATH} " o----------------------------------------------------------------o"; | |
${ECHO_PATH} ""; | |
} | |
function precheck(){ | |
${ECHO_PATH} "Please wait while the installer requirements are being assessed..." | |
if [ $(/usr/bin/id -u) != "0" ]; then | |
${ECHO_PATH} "Hypervisor must be installed as root. Please log in as root and try again." | |
fi | |
if [ -f /etc/redhat-release ] || [ -f /etc/system-release ]; then | |
REL=$(cat /etc/redhat-release) | |
else | |
${ECHO_PATH} "Script made for CentOS or allied flavors only!" | |
exit 1; | |
fi | |
if [ ! -f "$INSTALL_LOG" ]; then | |
touch "$INSTALL_LOG" | |
fi | |
if [ `uname -m` != "x86_64" ]; then | |
${ECHO_PATH} "Script made for x64 bit OS only" | |
exit 1; | |
fi | |
if [ "$?" -ne "0" ]; then | |
${ECHO_PATH} "Unsupported Operating System!" | |
${ECHO_PATH} "Exiting installer" | |
exit 1; | |
fi | |
sleep 3 | |
} | |
function precheck_clean { | |
${ECHO_PATH} "Cleaning up packages that might conflict..." | |
service httpd stop >> ${INSTALL_LOG} 2>&1 | |
service lighttpd stop >> ${INSTALL_LOG} 2>&1 | |
service nginx stop >> ${INSTALL_LOG} 2>&1 | |
service php-fpm stop >> ${INSTALL_LOG} 2>&1 | |
service mysql stop >> ${INSTALL_LOG} 2>&1 | |
service mariadb stop >> ${INSTALL_LOG} 2>&1 | |
yum -y remove httpd mysql* php* nginx lighttpd php-fpm vsftpd proftpd exim qmail postfix sendmail git pdns* MariaDB-server MariaDB-client >> ${INSTALL_LOG} 2>&1 | |
if [ -d /var/lib/mysql ]; then | |
rm -rf /var/lib/mysql >> ${INSTALL_LOG} 2>&1 | |
fi | |
check_error | |
} | |
function check_error(){ | |
if [ "$?" = "0" ]; then | |
true | |
else | |
${ECHO_PATH} " ** Error Code: $?" | |
${ECHO_PATH} " ** Exited on Error!" 1>&2 | |
${ECHO_PATH} " ** Please check ${INSTALL_LOG} for more information!" 1>&2 | |
exit 1 | |
fi | |
} | |
function setup_webserver(){ | |
${ECHO_PATH} "Setting up webserver..." | |
cat<<EOF > /etc/yum.repos.d/hypervisor-nginx.repo | |
[nginx] | |
name=Nginx repo | |
baseurl=http://nginx.org/packages/mainline/centos/7/x86_64/ | |
gpgcheck=0 | |
enabled=1 | |
EOF | |
${YUM_PATH} -y install nginx >> ${INSTALL_LOG} 2>&1; | |
check_error | |
} | |
function setup_sqldb(){ | |
${ECHO_PATH} "Setting up MySQL server..." | |
cat<<EOF > /etc/yum.repos.d/hypervisor-mariadb.repo | |
[mariadb] | |
name=MariaDB repo | |
baseurl=http://yum.mariadb.org/10.5/centos7-amd64/ | |
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB | |
gpgcheck=1 | |
enabled=1 | |
EOF | |
${YUM_PATH} makecache fast >> ${INSTALL_LOG} 2>&1; | |
${YUM_PATH} -y install mariadb-server mariadb-client >> ${INSTALL_LOG} 2>&1; | |
systemctl enable mariadb >> ${INSTALL_LOG} 2>&1 | |
systemctl start mariadb >> ${INSTALL_LOG} 2>&1 | |
MYSQL_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32;) | |
mysqladmin --user=root password ${MYSQL_PASSWORD}; | |
${ECHO_PATH} "DROP DATABASE IF EXISTS test;" >> mysql.temp; | |
${ECHO_PATH} "FLUSH PRIVILEGES;" >> mysql.temp; | |
${ECHO_PATH} "GRANT CREATE, DROP ON *.* TO hypervisor@localhost IDENTIFIED BY '${MYSQL_PASSWORD}' WITH GRANT OPTION;" >> mysql.temp; | |
${ECHO_PATH} "GRANT ALL PRIVILEGES ON *.* TO hypervisor@localhost IDENTIFIED BY '${MYSQL_PASSWORD}' WITH GRANT OPTION;" >> mysql.temp; | |
${ECHO_PATH} "create database hypervisor;" >> mysql.temp; | |
/usr/bin/mysql mysql --user=root --password="${MYSQL_PASSWORD}" < mysql.temp >> ${INSTALL_LOG} 2>&1; | |
/usr/bin/rm -rf mysql.temp; | |
systemctl stop mariadb >> ${INSTALL_LOG} 2>&1; | |
check_error | |
} | |
function setup_phpfpm(){ | |
${ECHO_PATH} "Setting up PHP-FPM..." | |
${YUM_PATH} -y install yum-utils >> ${INSTALL_LOG} 2>&1 | |
${WGET_PATH} https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -O epel-release.rpm >> ${INSTALL_LOG} 2>&1 | |
${WGET_PATH} http://rpms.remirepo.net/enterprise/remi-release-7.rpm -O remi-release.rpm >> ${INSTALL_LOG} 2>&1 | |
rpm -Uvh remi-release.rpm >> ${INSTALL_LOG} 2>&1 | |
rpm -Uvh epel-release.rpm >> ${INSTALL_LOG} 2>&1 | |
yum-config-manager --enable remi-php73 >> ${INSTALL_LOG} 2>&1; | |
yum clean all >> ${INSTALL_LOG} 2>&1 | |
yum makecache fast >> ${INSTALL_LOG} 2>&1 | |
${YUM_PATH} -y install php php-mcrypt php-cli php-gd php-curl libssh2 libssh2-devel php-devel php-mysql php-ldap php-zip php-fileinfo php-fpm php-xml zip unzip sendmail php-mcrypt make gcc-c++ gcc zlib-devel curl-devel php-mbstring git openssl php-exif php-soap php-ssh2 php-pspell >> ${INSTALL_LOG} 2>&1; | |
check_error | |
} | |
function setup_npm(){ | |
${ECHO_PATH} "Setting up NodeJS..." | |
${CURL_PATH} -sL https://rpm.nodesource.com/setup_14.x | bash - >> ${INSTALL_LOG} 2>&1; | |
${YUM_PATH} -y install nodejs >> ${INSTALL_LOG} 2>&1; | |
npm install -g pm2 >> ${INSTALL_LOG} 2>&1; | |
check_error | |
} | |
function setup_ioncube(){ | |
${ECHO_PATH} "Setting up Ioncube Loaders..." | |
${WGET_PATH} https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz -O ioncube_loaders_lin_x86-64.tar.gz >> ${INSTALL_LOG} 2>&1; | |
${TAR_PATH} -zxvf ioncube_loaders_lin_x86-64.tar.gz >> ${INSTALL_LOG} 2>&1; | |
PHPEXTDIR=$(php -i | grep extension_dir | head -n1 | awk '{print $3}') | |
PHPINIDIR=$(php -i | grep "Scan this dir for additional .ini files" | awk '{print $9}') | |
cp ./ioncube/ioncube_loader_lin_7.3.so $PHPEXTDIR/ioncube_loader_lin_7.3.so | |
${ECHO_PATH} "zend_extension = $PHPEXTDIR/ioncube_loader_lin_7.3.so" > $PHPINIDIR/00-ioncube.ini | |
} | |
function setup_master(){ | |
${ECHO_PATH} "Setting up Master API..." | |
adduser hypervisor --home /usr/local/hypervisor >> ${INSTALL_LOG} 2>&1 | |
${WGET_PATH} >> ${INSTALL_LOG} 2>&1 #//Get the master file here | |
unzip -o /root/master.zip -d /usr/local/hypervisor >> ${INSTALL_LOG} 2>&1 | |
chmod 777 /usr/local/hypervisor/storage -R >> ${INSTALL_LOG} 2>&1 | |
chmod 777 /usr/local/hypervisor/bootstrap/cache -R >> ${INSTALL_LOG} 2>&1 | |
setup_api_env | |
setup_ui_env | |
${ECHO_PATH} "Setting up Master UI..." | |
cd /usr/local/hypervisor/client | |
npm install >> ${INSTALL_LOG} 2>&1 | |
${ECHO_PATH} "Setting up Master Database..." | |
php /usr/local/hypervisor/artisan migrate --force --step >> ${INSTALL_LOG} 2>&1 | |
check_error | |
php /usr/local/hypervisor/artisan migrate --path=database/migrations/upgrades/* --force --step >> ${INSTALL_LOG} 2>&1 | |
check_error | |
php /usr/local/hypervisor/artisan db:seed >> ${INSTALL_LOG} 2>&1 | |
check_error | |
service mariadb stop >> ${INSTALL_LOG} 2>&1 | |
php /usr/local/hypervisor/artisan hypervisor:deploy | |
check_error | |
} | |
function setup_api_env(){ | |
APP_KEY=$(php /usr/local/hypervisor/artisan key:generate --force --show) | |
JWT_KEY=$(php /usr/local/hypervisor/artisan jwt:secret --force --show) | |
cat <<EOF > /usr/local/hypervisor/.env | |
APP_ENV=local | |
APP_KEY=$APP_KEY | |
JWT_SECRET=$JWT_KEY | |
APP_DEBUG=false | |
APP_LOG_LEVEL=debug | |
DB_USERNAME=hypervisor | |
DB_PASSWORD=$MYSQL_PASSWORD | |
DB_NAME=hypervisor | |
DB_SOCKET=/var/lib/mysql/mysql.sock | |
EOF | |
} | |
function setup_ui_env(){ | |
cat<<EOF > /usr/local/hypervisor/client/.env | |
API_URL=`curl http://ipinfo.io/ip`/api/v1 | |
EOF | |
} | |
menu | |
precheck_clean | |
precheck | |
setup_webserver | |
setup_phpfpm | |
setup_ioncube | |
setup_sqldb | |
setup_npm | |
setup_master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment