You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
8.2 KiB

#!/bin/bash
11 years ago
# Define echo function
11 years ago
# Blue color
function ee_lib_echo()
{
11 years ago
echo $(tput setaf 4)$@$(tput sgr0)
}
11 years ago
# White color
function ee_lib_echo_info()
{
11 years ago
echo $(tput setaf 7)$@$(tput sgr0)
}
11 years ago
# Red color
function ee_lib_echo_fail()
{
11 years ago
echo $(tput setaf 1)$@$(tput sgr0)
}
11 years ago
11 years ago
# 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"
11 years ago
exit 1
fi
11 years ago
# Execute: apt-get update
ee_lib_echo "Executing apt-get update, please wait..."
11 years ago
apt-get update &>> /dev/null
11 years ago
# Checking lsb_release package
11 years ago
if [ ! -x /usr/bin/lsb_release ]; then
11 years ago
ee_lib_echo "Installing lsb-release, please wait..."
11 years ago
apt-get -y install lsb-release &>> /dev/null
fi
# Define variables for later use
readonly EE_LOG_DIR=/var/log/easyengine
11 years ago
readonly EE_INSTALL_LOG=/var/log/easyengine/install.log
11 years ago
readonly EE_ERROR_LOG=/var/log/easyengine/error.log
11 years ago
readonly EE_LINUX_DISTRO=$(lsb_release -i |awk '{print $3}')
readonly EE_DEBIAN_VERSION=$(lsb_release -sc)
# Checking linux distro
11 years ago
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
11 years ago
# EasyEngine (ee) only support all Ubuntu/Debian distro except the distro reached EOL
11 years ago
lsb_release -d | egrep -e "12.04|14.04|squeeze|wheezy" &>> /dev/null
11 years ago
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
11 years ago
function ee_lib_error()
{
11 years ago
echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)" | tee -ai $EE_ERROR_LOG
11 years ago
exit $2
}
11 years ago
# Check the specified package is installed or not
function ee_lib_package_check()
{
local ee_package
11 years ago
for ee_package in $@;do
11 years ago
dpkg --get-selections | grep -v deinstall | grep $ee_package &>> $EE_INSTALL_LOG
11 years ago
# 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
11 years ago
if [ ! -d $EE_LOG_DIR ]; then
ee_lib_echo "Creating EasyEngine (ee) log directory, please wait..."
11 years ago
mkdir -p $EE_LOG_DIR || ee_lib_error "Unable to create log directory $EE_LOG_DIR, exit status = " $?
# Create EasyEngine log files
10 years ago
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
11 years ago
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
11 years ago
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
11 years ago
# Decide EasyEngine (ee) branch
11 years ago
BRANCH=$1
11 years ago
if [ -z "$BRANCH" ]; then
BRANCH=stable
else
# Cross check EasyEngine (ee) branch name
11 years ago
git ls-remote --heads https://github.com/rtCamp/easyengine | grep $BRANCH &>> $EE_INSTALL_LOG
if [ $? -ne 0 ]; then
11 years ago
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)
11 years ago
ee_lib_echo "Cloning EasyEngine (ee) $BRANCH branch, please wait..." | tee -ai $EE_INSTALL_LOG
11 years ago
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 \
11 years ago
|| ee_lib_error "Unable to create /etc/easyengine directory, exit status = " $?
fi
11 years ago
if [ ! -d /usr/share/easyengine/ ]
then
11 years ago
mkdir -p /usr/share/easyengine/ \
11 years ago
|| 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
11 years ago
# Install EasyEngine (ee)
11 years ago
ee_lib_echo "Installing EasyEngine (ee), please wait..." | tee -ai $EE_INSTALL_LOG
# EasyEngine (ee) auto completion file
11 years ago
cp -a /tmp/easyengine/config/bash_completion.d/ee /etc/bash_completion.d/ &>> $EE_INSTALL_LOG \
11 years ago
|| ee_lib_error "Unable to copy EasyEngine (ee) auto completion file, exit status = " $?
# EasyEngine (ee) config file
11 years ago
cp -a /tmp/easyengine/config/easyengine/ee.conf /etc/easyengine/ &>> $EE_INSTALL_LOG \
11 years ago
|| ee_lib_error "Unable to copy EasyEngine (ee) config file, exit status = " $?
11 years ago
# Templates
11 years ago
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 = " $?
11 years ago
# 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
11 years ago
cp -a /tmp/easyengine/bin/easyengine /usr/local/sbin/ &>> $EE_INSTALL_LOG \
11 years ago
|| ee_lib_error "Unable to copy EasyEngine (ee) command, exit status = " $?
# Change permission of EasyEngine (ee) command
11 years ago
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
11 years ago
# 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
11 years ago
GIT_USER_NAME=$(git config user.name)
GIT_USER_EMAIL=$(git config user.email)
11 years ago
if [ -z "$GIT_USER_NAME" ] || [ -z "$GIT_USER_EMAIL" ]; then
echo
11 years ago
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
11 years ago
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
11 years ago
if [ -z "$GIT_USER_NAME" ]; then
read -p "Enter your name [$(whoami)]: " GIT_USER_NAME
# If enter is pressed
if [[ $GIT_USER_NAME = "" ]]; then
11 years ago
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
11 years ago
if [ -z "$GIT_USER_EMAIL" ];then
read -p "Enter your email address [$(whoami)@$(hostname -f)]: " GIT_USER_EMAIL
# If enter is pressed
11 years ago
if [[ $GIT_USER_EMAIL = "" ]]
then
11 years ago
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
11 years ago
ee_lib_echo_info "source /etc/bash_completion.d/ee" | tee -ai $EE_INSTALL_LOG
12 years ago
echo
# Display success message
11 years ago
ee_lib_echo "EasyEngine (ee) installed successfully" | tee -ai $EE_INSTALL_LOG
11 years ago
ee_lib_echo "EasyEngine (ee) help: https://rtcamp.com/easyengine/docs/" | tee -ai $EE_INSTALL_LOG
echo