#!/bin/bash INFO="\e[96m" SUCCESS="\e[92m" YELLOW="\e[33m" BOLD="\e[1m" RESET="\e[0m" DOTTED="\e[5m" NGINX_SHARE="./usr/share/nginx/html" LETSENCRYPT_DIR="/opt/letsencrypt" function is_installed() { # set to 1 initially local return_=1 # set to 0 if not found type $1 >/dev/null 2>&1 || { local return_=0; } # return echo "$return_" } function is_yes() { local return_=1 if [[ "$1" == "${1#[Yy]}" && ! -z "$1" ]]; then local return_=0 else local return_=1 fi echo "$return_" } function install_vps() { read -r -p "$(echo -e $BOLD$YELLOW"Do you want to start the installation process $INFO[Y/n]: "$RESET)" start if [ "$(is_yes $start)" == "1" ]; then echo -e $INFO"Updating VPS..." apt-get update echo -e "Install [Nodejs|Server|Nginx|Redis|Postgreshql] - Ubuntu System"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install nginx $INFO[Y/n]: "$RESET)" nginx if [[ "$(is_installed nginx)" == "0" && "$(is_yes $nginx)" == "1" ]]; then echo -e $INFO"Installing nginx..." apt-get install nginx -y echo -e "Start nginx..." systemctl start nginx echo -e "Auto enable nginx when server reboot..."$RESET systemctl enable nginx echo -e $SUCCESS"Nginx install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install make $INFO[Y/n]: "$RESET)" make if [[ "$(is_installed make)" == "0" && "$(is_yes $make)" == "1" ]]; then echo -e $INFO"Installing build-essential..."$RESET apt-get install build-essential -y echo -e $SUCCESS"Make install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install nodejs-v13 $INFO[Y/n]: "$RESET)" nodejs if [[ "$(is_installed node)" == "0" && "$(is_yes $nodejs)" == "1" ]]; then echo -e $INFO"Download nodejs 13..." curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash - echo -e "Installing nodejs..."$RESET apt-get install nodejs -y node --version echo -e $SUCCESS"Nodejs install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install git $INFO[Y/n]: "$RESET)" git if [[ "$(is_installed git)" == "0" && "$(is_yes $git)" == "1" ]]; then echo -e $INFO"Installing git..."$RESET apt-get install git -y echo -e $SUCCESS"Git install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install pm2 $INFO[Y/n] "$RESET)" pm2 if [[ "$(is_installed pm2)" == "0" && "$(is_yes $pm2)" == "1" ]]; then echo -e $INFO"Installing pm2..."$RESET npm i -g pm2 echo -e $SUCCESS"PM2 install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install redis $INFO[Y/n] "$RESET)" redis if [[ "$(is_installed redis-cli)" == "0" && "$(is_yes $redis)" == "1" ]]; then echo -e $INFO"Installing redis..."$RESET apt-get install redis-server echo -e $SUCCESS"Redis install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install postgresql $INFO[Y/n] "$RESET)" postgresql if [[ "$(is_installed postgresql)" == "0" && "$(is_yes $postgresql)" == "1" ]]; then echo -e $INFO"Installing postgresql..."$RESET apt-get install postgresql -y echo -e $SUCCESS"PostGresql install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want install postgresql contrib $INFO[Y/n] "$RESET)" postgresql_contrib if [[ "$(is_installed postgresql-contrib)" == "0" && "$(is_yes $postgresql_contrib)" == "1" ]]; then echo -e $INFO"Installing postgresql-contrib"$RESET apt-get install postgresql-contrib -y echo -e $SUCCESS"PostGresql contrib install sucess"$RESET fi read -r -p "$(echo -e $BOLD$YELLOW"Install letsencrypt SSL : "$RESET)" ssl if [ "$(is_yes $ssl)" == "1" ]; then if [ ! -d "$LETSENCRYPT_DIR" ]; then git clone https://github.com/letsencrypt/letsencrypt $LETSENCRYPT_DIR fi fi echo -e $BOLD$SUCCESS"Install VPS success"$RESET } function setup_project() { read -r -p "$(echo -e $BOLD$YELLOW"Do you want to start setup project $INFO[Y/n]: "$RESET)" setup if [ "$(is_yes $setup)" == "1" ]; then echo -e $INFO"hihi"$RESET read -r -p "$(echo -e $BOLD$YELLOW"Git repo: "$RESET)" repo cd $NGINX_SHARE && git clone $repo fi read -r -p "$(echo -e $BOLD$YELLOW"Do you want setup domain ssl $INFO[Y/n]: "$RESET)" setup_ssl if [ "$(is_yes $setup_ssl)" == "1" ]; then /opt/letsencrypt/certbot-auto certonly --standalone fi } install_vps setup_project