#!/bin/bash # Define echo function # Blue color function ee_lib_echo() { echo $(tput setaf 4)$@$(tput sgr0) } # White color function ee_lib_echo_info() { echo $(tput setaf 7)$@$(tput sgr0) } # Red color function ee_lib_echo_fail() { echo $(tput setaf 1)$@$(tput sgr0) } # Checking permissions if [[ $EUID -ne 0 ]]; then ee_lib_echo_fail "Sudo privilege required..." ee_lib_echo_fail "Uses: wget -qO ee rt.cx/ee && sudo bash ee" exit 1 fi # Execute: apt-get update ee_lib_echo "Executing apt-get update, please wait..." apt-get update &>> /dev/null # Checking lsb_release package if [ ! -x /usr/bin/lsb_release ]; then ee_lib_echo "Installing lsb-release, please wait..." apt-get -y install lsb-release &>> /dev/null fi # Define variables for later use readonly EE_LOG_DIR=/var/log/easyengine readonly EE_INSTALL_LOG=/var/log/easyengine/install.log readonly EE_ERROR_LOG=/var/log/easyengine/error.log readonly EE_LINUX_DISTRO=$(lsb_release -i |awk '{print $3}') readonly EE_DEBIAN_VERSION=$(lsb_release -sc) # Checking linux distro if [ "$EE_LINUX_DISTRO" != "Ubuntu" ] && [ "$EE_LINUX_DISTRO" != "Debian" ]; then ee_lib_echo_fail "EasyEngine (ee) is made for Ubuntu and Debian only as of now" ee_lib_echo_fail "You are free to fork EasyEngine (ee): https://github.com/rtCamp/easyengine/fork" exit 100 fi # EasyEngine (ee) only support all Ubuntu/Debian distro except the distro reached EOL lsb_release -d | egrep -e "12.04|14.04|squeeze|wheezy" &>> /dev/null if [ "$?" -ne "0" ]; then ee_lib_echo_fail "EasyEngine (ee) only support Ubuntu 12.04/14.04 and Debian 6.x/7.x" exit 100 fi # Capture errors function ee_lib_error() { echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)" | tee -ai $EE_ERROR_LOG exit $2 } # Check the specified package is installed or not function ee_lib_package_check() { local ee_package for ee_package in $@;do dpkg --get-selections | grep -v deinstall | grep $ee_package &>> $EE_INSTALL_LOG # Generate a list of not installed package if [ $? -ne 0 ]; then EE_PACKAGE_NAME="$EE_PACKAGE_NAME $ee_package" fi done } # Pre checks to avoid later screw ups # Checking EasyEngine (ee) log directory if [ ! -d $EE_LOG_DIR ]; then ee_lib_echo "Creating EasyEngine (ee) log directory, please wait..." mkdir -p $EE_LOG_DIR || ee_lib_error "Unable to create log directory $EE_LOG_DIR, exit status = " $? # Create EasyEngine log files touch /var/log/easyengine/{ee.log,install.log,update.log,error.log} \ || ee_lib_error "Unable to create EasyEngine log files in $EE_LOG_DIR, exit status = " $? # Keep EasyEngine log folder accessible to root only chmod -R 700 /var/log/easyengine \ || ee_lib_error "Unable to change permissions for EasyEngine log folder, exit status = " $? fi # Install required packages if [ "$EE_LINUX_DISTRO" == "Ubuntu" ]; then ee_lib_package_check graphviz python-software-properties software-properties-common elif [ "$EE_LINUX_DISTRO" == "Debian" ]; then ee_lib_package_check graphviz python-software-properties fi if [ ! -x /usr/bin/tee ] || [ ! -x /bin/ed ] || [ ! -x /usr/bin/bc ] || [ ! -x /usr/bin/wget ] || [ ! -x /usr/bin/curl ] || [ ! -x /bin/tar ] || [ ! -x /usr/bin/git ] || [ ! -x /usr/bin/sudo ] || [ -n "$EE_PACKAGE_NAME" ]; then ee_lib_echo "Installing required packages, please wait..." | tee -ai $EE_INSTALL_LOG apt-get -y install coreutils ed bc wget curl tar git-core sudo $EE_PACKAGE_NAME | tee -ai $EE_INSTALL_LOG\ || ee_lib_error "Unable to install required packages, exit status = " $? fi # Checking name servers if [[ -z $(cat /etc/resolv.conf 2> /dev/null | awk '/^nameserver/ { print $2 }') ]]; then ee_lib_echo_fail "Unable to detect name servers" && ee_lib_error "Unable to detect name servers, exit status = " $? ee_lib_echo_fail "Please configure /etc/resolv.conf" && ee_lib_error "Please configure /etc/resolv.conf, exit status = " $? fi # Pre checks end # Decide EasyEngine (ee) branch BRANCH=$1 if [ -z "$BRANCH" ]; then BRANCH=stable else # Cross check EasyEngine (ee) branch name git ls-remote --heads https://github.com/rtCamp/easyengine | grep $BRANCH &>> $EE_INSTALL_LOG if [ $? -ne 0 ]; then ee_lib_error "The $BRANCH branch does not exist, please provide the correct branch name, exit status = " $? fi fi # Remove old version of EasyEngine (ee) rm -rf /tmp/easyengine &>> /dev/null # Let's clone EasyEngine (ee) ee_lib_echo "Cloning EasyEngine (ee) $BRANCH branch, please wait..." | tee -ai $EE_INSTALL_LOG git clone -b $BRANCH https://github.com/rtCamp/easyengine.git /tmp/easyengine &>> $EE_INSTALL_LOG \ || ee_lib_error "Unable to clone EasyEngine (ee) $BRANCH branch, exit status = " $? # Setup EasyEngine (ee) if [ ! -d /etc/easyengine ]; then mkdir -p /etc/easyengine \ || ee_lib_error "Unable to create /etc/easyengine directory, exit status = " $? fi if [ ! -d /usr/share/easyengine/ ] then mkdir -p /usr/share/easyengine/ \ || ee_lib_error "Unable to create /usr/share/easyengine/ directory, exit status = " $? fi if [ ! -d /usr/local/lib/easyengine ] then mkdir -p /usr/local/lib/easyengine \ || ee_lib_error "Unable to create /usr/local/lib/easyengine directory, exit status = " $? fi # Install EasyEngine (ee) ee_lib_echo "Installing EasyEngine (ee), please wait..." | tee -ai $EE_INSTALL_LOG # EasyEngine (ee) auto completion file cp -a /tmp/easyengine/config/bash_completion.d/ee /etc/bash_completion.d/ &>> $EE_INSTALL_LOG \ || ee_lib_error "Unable to copy EasyEngine (ee) auto completion file, exit status = " $? # EasyEngine (ee) config file cp -a /tmp/easyengine/config/easyengine/ee.conf /etc/easyengine/ &>> $EE_INSTALL_LOG \ || ee_lib_error "Unable to copy EasyEngine (ee) config file, exit status = " $? # Templates cp -a /tmp/easyengine/config/nginx /tmp/easyengine/templates/* /usr/share/easyengine/ &>> $EE_INSTALL_LOG \ || ee_lib_error "Unable to copy NGINX sample files, exit status = " $? # EasyEngine (ee) library and modules cp -a /tmp/easyengine/src/* /usr/local/lib/easyengine \ || ee_lib_error "Unable to copy src files, exit status = " $? # EasyEngine (ee) command cp -a /tmp/easyengine/bin/easyengine /usr/local/sbin/ &>> $EE_INSTALL_LOG \ || ee_lib_error "Unable to copy EasyEngine (ee) command, exit status = " $? # Change permission of EasyEngine (ee) command chmod 750 /usr/local/sbin/easyengine || ee_lib_error "Unable to change permission of EasyEngine (ee) command, exit status = " $? # Create symbolic link if [ ! -L /usr/local/sbin/ee ]; then ln -s /usr/local/sbin/easyengine /usr/local/sbin/ee fi # EasyEngine (ee) man page cp -a /tmp/easyengine/docs/man/ee.8 /usr/share/man/man8/ &>> $EE_INSTALL_LOG \ || ee_lib_error "Unable to copy EasyEngine (ee) man page, exit status = " $? # Git config settings GIT_USER_NAME=$(git config user.name) GIT_USER_EMAIL=$(git config user.email) if [ -z "$GIT_USER_NAME" ] || [ -z "$GIT_USER_EMAIL" ]; then echo ee_lib_echo "EasyEngine (ee) required your name & email address" | tee -ai $EE_INSTALL_LOG ee_lib_echo "to track changes you made under the Git version control" | tee -ai $EE_INSTALL_LOG ee_lib_echo "EasyEngine (ee) will be able to send you daily reports & alerts in upcoming version" | tee -ai $EE_INSTALL_LOG ee_lib_echo "EasyEngine (ee) will NEVER send your information across" | tee -ai $EE_INSTALL_LOG fi if [ -z "$GIT_USER_NAME" ]; then read -p "Enter your name [$(whoami)]: " GIT_USER_NAME # If enter is pressed if [[ $GIT_USER_NAME = "" ]]; then GIT_USER_NAME=$(whoami) fi git config --global user.name "${GIT_USER_NAME}" echo "git config user.name = $(git config user.name)" &>> $EE_INSTALL_LOG fi if [ -z "$GIT_USER_EMAIL" ];then read -p "Enter your email address [$(whoami)@$(hostname -f)]: " GIT_USER_EMAIL # If enter is pressed if [[ $GIT_USER_EMAIL = "" ]] then GIT_USER_EMAIL=$(whoami)@$(hostname -f) fi git config --global user.email $GIT_USER_EMAIL echo "git config user.email = $(git config user.email)" &>> $EE_INSTALL_LOG fi # Enable EasyEngine (ee) auto completion echo ee_lib_echo "For EasyEngine (ee) auto completion, run the following command" | tee -ai $EE_INSTALL_LOG ee_lib_echo_info "source /etc/bash_completion.d/ee" | tee -ai $EE_INSTALL_LOG echo # Display success message ee_lib_echo "EasyEngine (ee) installed successfully" | tee -ai $EE_INSTALL_LOG ee_lib_echo "EasyEngine (ee) help: https://rtcamp.com/easyengine/docs/" | tee -ai $EE_INSTALL_LOG echo