From 9c1b0daefa25d9178d01da6ab58648aa974feac3 Mon Sep 17 00:00:00 2001 From: Mitesh Shah Date: Tue, 13 May 2014 17:57:04 +0530 Subject: [PATCH] Divide EasyEngine functions into library --- src/lib/APT_GET_UPDATE.sh | 6 ++++++ src/lib/DOT_DEB_GPG_KEY.sh | 6 ++++++ src/lib/ECHO.sh | 15 ++++++++++++++ src/lib/EE_ERROR.sh | 6 ++++++ src/lib/INSTALL_NGINX.sh | 6 ++++++ src/lib/NGINX_REPO.sh | 25 +++++++++++++++++++++++ src/lib/PACKAGE_CHECK.sh | 11 ++++++++++ src/lib/PHP_REPO.sh | 29 +++++++++++++++++++++++++++ src/lib/PYTHON_SOFTWARE_PROPERTIES.sh | 15 ++++++++++++++ src/lib/VARIABLE.sh | 7 +++++++ 10 files changed, 126 insertions(+) create mode 100644 src/lib/APT_GET_UPDATE.sh create mode 100644 src/lib/DOT_DEB_GPG_KEY.sh create mode 100644 src/lib/ECHO.sh create mode 100644 src/lib/EE_ERROR.sh create mode 100644 src/lib/INSTALL_NGINX.sh create mode 100644 src/lib/NGINX_REPO.sh create mode 100644 src/lib/PACKAGE_CHECK.sh create mode 100644 src/lib/PHP_REPO.sh create mode 100644 src/lib/PYTHON_SOFTWARE_PROPERTIES.sh create mode 100644 src/lib/VARIABLE.sh diff --git a/src/lib/APT_GET_UPDATE.sh b/src/lib/APT_GET_UPDATE.sh new file mode 100644 index 00000000..d386228b --- /dev/null +++ b/src/lib/APT_GET_UPDATE.sh @@ -0,0 +1,6 @@ +# Update apt-get cache +function APT_GET_UPDATE() +{ + ECHO_BLUE "apt-get update, Please Wait..." + apt-get update &>> $EE_LOG || EE_ERROR "Unable to execute apt-get update" +} \ No newline at end of file diff --git a/src/lib/DOT_DEB_GPG_KEY.sh b/src/lib/DOT_DEB_GPG_KEY.sh new file mode 100644 index 00000000..ad0e88c5 --- /dev/null +++ b/src/lib/DOT_DEB_GPG_KEY.sh @@ -0,0 +1,6 @@ +# Fetch and install dotdeb GnuPG key +function DOT_DEB_GPG_KEY() +{ + wget --no-check-certificate -cqO /tmp/dotdeb.gpg http://www.dotdeb.org/dotdeb.gpg || EE_ERROR "Unable to download dotdeb GnuPG key" + apt-key add /tmp/dotdeb.gpg &>> $EE_LOG || EE_ERROR "Unable to add dotdeb GnuPG key" +} diff --git a/src/lib/ECHO.sh b/src/lib/ECHO.sh new file mode 100644 index 00000000..1e782358 --- /dev/null +++ b/src/lib/ECHO.sh @@ -0,0 +1,15 @@ +# Define echo function for each color +function ECHO_RED() +{ + echo $(tput setaf 1)$@$(tput sgr0) +} + +function ECHO_BLUE() +{ + echo $(tput setaf 4)$@$(tput sgr0) +} + +function ECHO_WHITE() +{ + echo $(tput setaf 7)$@$(tput sgr0) +} diff --git a/src/lib/EE_ERROR.sh b/src/lib/EE_ERROR.sh new file mode 100644 index 00000000..ee201c75 --- /dev/null +++ b/src/lib/EE_ERROR.sh @@ -0,0 +1,6 @@ +# Capture errors +function EE_ERROR() +{ + echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)" | tee -ai $ERROR_LOG + exit 102 +} \ No newline at end of file diff --git a/src/lib/INSTALL_NGINX.sh b/src/lib/INSTALL_NGINX.sh new file mode 100644 index 00000000..89b0908e --- /dev/null +++ b/src/lib/INSTALL_NGINX.sh @@ -0,0 +1,6 @@ +# Install nginx +function INSTALL_NGINX() +{ + ECHO_BLUE "Installing $NGINXPACKAGE, please wait..." + $APT_GET install $NGINXPACKAGE || EE_ERROR "Unable to install $NGINXPACKAGE" +} \ No newline at end of file diff --git a/src/lib/NGINX_REPO.sh b/src/lib/NGINX_REPO.sh new file mode 100644 index 00000000..abe25176 --- /dev/null +++ b/src/lib/NGINX_REPO.sh @@ -0,0 +1,25 @@ +# Install nginx +function NGINX_REPO() +{ + if [ "$LINUX_DISTRO" == "Ubuntu" ]; then + # Add rtCamp nginx launchpad repository + ECHO_BLUE "Adding rtCamp nginx launchpad repository, please wait..." + add-apt-repository -y ppa:rtcamp/nginx &>> $EE_LOG \ + || EE_ERROR "Unable to add rtCamp nginx launchpad repository" + + # Specify nginx package + NGINX_PACKAGE=nginx-custom + + elif [ "$LINUX_DISTRO" == "Debian" ]; then + # Add dotdeb nginx repository + ECHO_BLUE "Adding dotdeb nginx repository, please wait..." + echo "deb http://packages.dotdeb.org $(lsb_release -c | awk '{print($2)}') all" > /etc/apt/sources.list.d/dotdeb-$(lsb_release -c | awk '{print($2)}').list \ + || EE_ERROR "Unable to add dotdeb nginx repository" + + # Fetch and install dotdeb GnuPG key + DOT_DEB_GPG_KEY + + # Specify nginx package + NGINX_PACKAGE=nginx-full + fi +} diff --git a/src/lib/PACKAGE_CHECK.sh b/src/lib/PACKAGE_CHECK.sh new file mode 100644 index 00000000..153441cc --- /dev/null +++ b/src/lib/PACKAGE_CHECK.sh @@ -0,0 +1,11 @@ +# Check the specified package is instlled or not +function PACKAGE_CHECK() +{ + for i in $@;do + dpkg --get-selections | grep -v deinstall | grep $i &>> INSTALL_LOG + # Generate a list of not installed package + if [ $? -ne 0 ]; then + PACKAGE_NAME="$PACKAGE_NAME $i" + fi + done +} diff --git a/src/lib/PHP_REPO.sh b/src/lib/PHP_REPO.sh new file mode 100644 index 00000000..79e50f84 --- /dev/null +++ b/src/lib/PHP_REPO.sh @@ -0,0 +1,29 @@ +# Install php5-fpm +function PHP_REPO() +{ + # Check LINUX_DISTRO + if [ "$LINUX_DISTRO" == "Ubuntu" ]; then + # Add ondrej php5 launchpad repository + ECHO_BLUE "Adding ondrej php5 launchpad repository, please wait..." + add-apt-repository -y ppa:ondrej/php5 &>> $EE_LOG \ + || EE_ERROR "Unable to add ondrej php5 launchpad repository" + + # Detect Debian version to select php repository + elif [ "$LINUX_DISTRO" == "Debian" ]; then + DEBIAN_VERSION=$(lsb_release -r | awk '{print($2)}' | cut -d'.' -f1) + + # Add dotdeb php5.x repository + if [ $DEBIAN_VERSION -eq 6 ]; then + ECHO_BLUE "Adding dotdeb php5.4 repository, please wait..." + echo "deb http://packages.dotdeb.org $(lsb_release -c | awk '{print($2)}')-php54 all" > /etc/apt/sources.list.d/dotdeb-$(lsb_release -c | awk '{print($2)}')-php54.list \ + || EE_ERROR "Unable to add dotdeb php5.4 repository" + elif [ $DEBIAN_VERSION -eq 7 ]; then + ECHO_BLUE "Adding dotdeb php5.5 repository, please wait..." + echo "deb http://packages.dotdeb.org $(lsb_release -c | awk '{print($2)}')-php55 all" > /etc/apt/sources.list.d/dotdeb-$(lsb_release -c | awk '{print($2)}')-php55.list \ + || EE_ERROR "Unable to add dotdeb php5.5 repository" + fi + + # Fetch and install dotdeb GnuPG key + DOT_DEB_GPG_KEY + fi +} diff --git a/src/lib/PYTHON_SOFTWARE_PROPERTIES.sh b/src/lib/PYTHON_SOFTWARE_PROPERTIES.sh new file mode 100644 index 00000000..39637565 --- /dev/null +++ b/src/lib/PYTHON_SOFTWARE_PROPERTIES.sh @@ -0,0 +1,15 @@ +# Install add-apt-repository command +PYTHON-SOFTWARE-PROPERTIES() +{ + if [ "$LINUX_DISTRO" == "Ubuntu" ]; then + # Install python-software-properties and software-properties-common + ECHO_BLUE "Installing python-software-properties and software-properties-common, please wait..." + $APT_GET install python-software-properties software-properties-common \ + || EE_ERROR "Unable to install python-software-properties and software-properties-common" + elif [ "$LINUX_DISTRO" == "Debian" ]; then + # Install python-software-properties + ECHO_BLUE "Installing python-software-properties, please wait..." + $APT_GET install python-software-properties \ + || EE_ERROR "Unable to install python-software-properties" + fi +} diff --git a/src/lib/VARIABLE.sh b/src/lib/VARIABLE.sh new file mode 100644 index 00000000..9a2bbf33 --- /dev/null +++ b/src/lib/VARIABLE.sh @@ -0,0 +1,7 @@ +# Define variables +LOG_DIR=/var/log/easyengine +EE_LOG=/var/log/easyengine/ee.log +ERROR_LOG=/var/log/easyengine/error.log +LINUX_DISTRO=$(lsb_release -i |awk '{print $3}') +IP_ADDRESS=$(grep ip_address /etc/easyengine/ee.conf | cut -d'=' -f2 | sed 's/ //g' | tr ',' '\n') +APT_GET=$(grep apt-get-assume-yes /etc/easyengine/ee.conf | grep -i true &> /dev/null && echo apt-get -y)