From df11c596a2ec0c52c76f4b4ee4e9e153b12028aa Mon Sep 17 00:00:00 2001 From: Edi Septriyanto Date: Sat, 11 Dec 2021 23:15:07 +0700 Subject: [PATCH] Add pre-flight checks --- scripts/cleanup_server.sh | 3 +++ scripts/install_fail2ban.sh | 3 +++ scripts/install_imagemagick.sh | 3 +++ scripts/install_mailer.sh | 3 +++ scripts/install_memcached.sh | 3 +++ scripts/install_phalcon.sh | 3 +++ scripts/install_php.sh | 34 +++++++++++++++++++++------------- scripts/install_phploader.sh | 3 +++ scripts/install_vsftpd.sh | 7 +++++-- 9 files changed, 47 insertions(+), 15 deletions(-) diff --git a/scripts/cleanup_server.sh b/scripts/cleanup_server.sh index 98dd9f6..045f5d4 100755 --- a/scripts/cleanup_server.sh +++ b/scripts/cleanup_server.sh @@ -23,6 +23,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + echo "Cleaning up server..." # Fix broken install, first? diff --git a/scripts/install_fail2ban.sh b/scripts/install_fail2ban.sh index 622b76b..7a983db 100755 --- a/scripts/install_fail2ban.sh +++ b/scripts/install_fail2ban.sh @@ -16,6 +16,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + ## # Install Fail2ban. ## diff --git a/scripts/install_imagemagick.sh b/scripts/install_imagemagick.sh index 58d5024..310c3e6 100755 --- a/scripts/install_imagemagick.sh +++ b/scripts/install_imagemagick.sh @@ -16,6 +16,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + ## # Install ImageMagick. ## diff --git a/scripts/install_mailer.sh b/scripts/install_mailer.sh index 4226539..5dae9c7 100755 --- a/scripts/install_mailer.sh +++ b/scripts/install_mailer.sh @@ -16,6 +16,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + ## # Install Postfix Mail Transfer Agent. ## diff --git a/scripts/install_memcached.sh b/scripts/install_memcached.sh index 94df54c..dd772a6 100755 --- a/scripts/install_memcached.sh +++ b/scripts/install_memcached.sh @@ -16,6 +16,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + ## # Initialize Memcached Installation. ## diff --git a/scripts/install_phalcon.sh b/scripts/install_phalcon.sh index e62e76c..0b3085f 100755 --- a/scripts/install_phalcon.sh +++ b/scripts/install_phalcon.sh @@ -16,6 +16,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + # Install Phalcon from source. function install_phalcon() { local PHALCON_VERSION=${1} diff --git a/scripts/install_php.sh b/scripts/install_php.sh index c4d204b..4dcfcba 100755 --- a/scripts/install_php.sh +++ b/scripts/install_php.sh @@ -37,18 +37,22 @@ function add_php_repo() { else info "PHP package repository already exists." fi - - run apt-get update -qq -y ;; ubuntu) - run apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C - run add-apt-repository -y ppa:ondrej/php - run apt-get update -qq -y + if [[ ! -f "/etc/apt/sources.list.d/ondrej-php-${RELEASE_NAME}.list" ]]; then + run apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C + run add-apt-repository -y ppa:ondrej/php + else + info "PHP package repository already exists." + fi ;; *) fail "Unable to install PHP, this GNU/Linux distribution is not supported." ;; esac + + info "Updating repository..." + run apt-get update -qq -y } ## @@ -72,11 +76,11 @@ function install_php_fpm() { local PHP_EXTS=() local PHP_PECL_EXTS=() - local PHP_CUST_EXTS=() && \ - read -r -a PHP_CUST_EXTS <<< "${PHP_EXTENSIONS}" # Read additional PHP extensions from env variable. + local PHP_REPO_EXTS=() && \ + read -r -a PHP_REPO_EXTS <<< "${PHP_EXTENSIONS}" # Read additional PHP extensions from .env variable. # Check additional PHP extensions availability. - for EXT_NAME in "${PHP_CUST_EXTS[@]}"; do + for EXT_NAME in "${PHP_REPO_EXTS[@]}"; do echo "Checking additional PHP extension: ${EXT_NAME}..." if apt-cache search "php${PHPv}-${EXT_NAME}" | grep -c "${PHPv}" > /dev/null; then PHP_EXTS+=("php${PHPv}-${EXT_NAME}") @@ -105,6 +109,10 @@ function install_php_fpm() { run pecl -d "php_suffix=${PHPv}" "${PHP_PECL_EXTS[@]}" fi + # Install additional PHP extensions. + [[ "${INSTALL_MEMCACHED}" == true ]] && install_php_memcached "${PHPv}" + [[ "${INSTALL_MONGODB}" == true ]] && install_php_mongodb "${PHPv}" + if [[ -n $(command -v "php${PHPv}") ]]; then TOTAL_EXTS=$((${#PHP_EXTS[@]} + ${#PHP_PECL_EXTS[@]})) success "PHP ${PHPv} along with ${TOTAL_EXTS} extensions installed." @@ -476,7 +484,11 @@ function install_php_mongodb() { CURRENT_DIR=$(pwd) run cd "${BUILD_DIR}" || return 1 - run git clone --depth=1 -q https://github.com/mongodb/mongo-php-driver.git && \ + + if [[ ! -d "${BUILD_DIR}/php-${PHPv}-mongodb" ]]; then + run git clone --depth=1 -q https://github.com/mongodb/mongo-php-driver.git + fi + run cd mongo-php-driver && \ run git submodule update --init @@ -689,8 +701,6 @@ function init_php_fpm_install() { if [[ "${IS_PKG_AVAIL}" -gt 0 ]]; then # Install PHP + default extensions. install_php_fpm "${VERSION}" - [[ "${INSTALL_MEMCACHED}" == true ]] && install_php_memcached "${VERSION}" - [[ "${INSTALL_MONGODB}" == true ]] && install_php_mongodb "${VERSION}" else error "PHP ${VERSION} package is not available on your operating system." fi @@ -702,8 +712,6 @@ function init_php_fpm_install() { echo "PHP ${DEFAULT_PHP_VERSION} now being installed..." install_php_fpm "${DEFAULT_PHP_VERSION}" - [[ "${INSTALL_MEMCACHED}" == true ]] && install_php_memcached "${DEFAULT_PHP_VERSION}" - [[ "${INSTALL_MONGODB}" == true ]] && install_php_mongodb "${DEFAULT_PHP_VERSION}" fi # Install PHP composer. diff --git a/scripts/install_phploader.sh b/scripts/install_phploader.sh index ba38bda..5249f13 100755 --- a/scripts/install_phploader.sh +++ b/scripts/install_phploader.sh @@ -16,6 +16,9 @@ fi # Make sure only root can run this installer script. requires_root +# Make sure only supported distribution can run this installer script. +preflight_system_check + ## # Install ionCube Loader. # diff --git a/scripts/install_vsftpd.sh b/scripts/install_vsftpd.sh index 0ca7114..9d7b1a6 100755 --- a/scripts/install_vsftpd.sh +++ b/scripts/install_vsftpd.sh @@ -16,8 +16,8 @@ fi # Make sure only root can run this installer script. requires_root -DISTRIB_NAME=${DISTRIB_NAME:-$(get_distrib_name)} -RELEASE_NAME=${RELEASE_NAME:-$(get_release_name)} +# Make sure only supported distribution can run this installer script. +preflight_system_check ## # Install Vsftpd. @@ -62,6 +62,9 @@ function init_vsftpd_install() { #https://www.linuxfromscratch.org/blfs/view/svn/server/vsftpd.html + DISTRIB_NAME=${DISTRIB_NAME:-$(get_distrib_name)} + RELEASE_NAME=${RELEASE_NAME:-$(get_release_name)} + # Install libraries. case "${DISTRIB_NAME}" in "debian")