#!/usr/bin/env bash # +-------------------------------------------------------------------------+ # | LEMPer is a simple LEMP stack installer for Debian/Ubuntu Linux | # |-------------------------------------------------------------------------+ # | Min requirement : GNU/Linux Debian 8, Ubuntu 18.04 or Linux Mint 17 | # | Last Update : 13/02/2022 | # | Author : MasEDI.Net (me@masedi.net) | # | Since Version : 2.6.0 | # +-------------------------------------------------------------------------+ # | Copyright (c) 2014-2022 MasEDI.Net (https://masedi.net/lemper) | # +-------------------------------------------------------------------------+ # | This source file is subject to the GNU General Public License | # | that is bundled with this package in the file LICENSE.md. | # | | # | If you did not receive a copy of the license and are unable to | # | obtain it through the world-wide-web, please send an email | # | to license@lemper.cloud so we can send you a copy immediately. | # +-------------------------------------------------------------------------+ # | Authors: Edi Septriyanto | # +-------------------------------------------------------------------------+ PROG_NAME=$(basename "$0") # Make sure only root can run this installer script. if [[ "$(id -u)" -ne 0 ]]; then if ! hash sudo 2>/dev/null; then echo "Installer script must be run as 'root' or with sudo." exit 1 else sudo -E "$0" "$@" exit 0 fi fi # Try to re-export global path. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ## # Main LEMPer Installer ## function lemper_install() { echo "Starting LEMPer Stack installation..." echo "Please ensure that you're on a fresh install!" echo -e "\nPress [Ctrl+C] to abort the installation process." sleep 3 if [[ "${AUTO_INSTALL}" != true ]]; then echo "" read -t 60 -rp "Press [Enter] to continue..." # # COMMANDS: # install # uninstall | remove # # OPTIONS: # --with-mysql-server : Install MySQL Server (MySQL or MariaDB) with specific version. ## function init_lemper_install() { START_TIME=$(date +%s) # Clone LEMPer repository first. git_clone_lemper "master" > /dev/null 2>&1 # Check dotenv config file. if [[ ! -f .env.dist ]]; then echo "${PROG_NAME}: .env.dist file not found." exit 1 fi if [[ -f .env ]]; then cp -f .env .env.bak else cp .env.dist .env fi # Set default args. DEBUG_MODE=false DRYRUN=false # Get sub command. CMD=${1} shift # Set getopt options. OPTS=$(getopt -o h:i:dgpDBF \ -l debug,development,dry-run,fix-broken-install,force,guided,hostname:,ipv4:,production,unattended \ -l with-nginx:,with-nginx-installer:,with-nginx-custom-ssl:,with-nginx-lua,with-nginx-pagespeed,with-nginx-passenger \ -l with-nginx-pcre:,with-nginx-rtmp,with-php:,with-php-extensions:,with-php-loader: \ -l with-mysql-server:,with-memcached:,with-memcached-installer:,with-mongodb:,with-mongodb-admin: \ -l with-redis:,with-redis-installer:,with-redis-requirepass:,with-ftp-server: \ -n "${PROG_NAME}" -- "$@") eval set -- "${OPTS}" while true; do case "${1}" in # Usage: --with-nginx --with-nginx) exit_if_optarg_is_empty "${1}" "${2}" shift NGINX_VERSION=${1} sed -i "s/INSTALL_NGINX=[a-zA-Z]*/INSTALL_NGINX=true/g" .env sed -i "s/NGINX_VERSION=\"[0-9a-zA-Z.\ ]*\"/NGINX_VERSION=\"${NGINX_VERSION}\"/g" .env shift ;; # Usage: --with-nginx-installer --with-nginx-installer) exit_if_optarg_is_empty "${1}" "${2}" shift NGINX_INSTALLER=${1} case "${NGINX_INSTALLER}" in source) sed -i "s/NGINX_INSTALLER=\"[a-zA-Z.\ ]*\"/NGINX_INSTALLER=\"source\"/g" .env ;; *) sed -i "s/NGINX_INSTALLER=\"[a-zA-Z]*\"/NGINX_INSTALLER=\"repo\"/g" .env ;; esac shift ;; --with-nginx-custom-ssl) exit_if_optarg_is_empty "${1}" "${2}" shift NGINX_CUSTOMSSL_VERSION=${1-"openssl-1.1.1l"} sed -i "s/NGINX_WITH_CUSTOMSSL=[a-zA-Z]*/NGINX_WITH_CUSTOMSSL=true/g" .env sed -i "s/NGINX_CUSTOMSSL_VERSION=\"[0-9a-zA-Z.-\ ]*\"/NGINX_CUSTOMSSL_VERSION=\"${NGINX_CUSTOMSSL_VERSION}\"/g" .env shift ;; --with-nginx-lua) sed -i "s/NGX_HTTP_LUA=[a-zA-Z]*/NGX_HTTP_LUA=true/g" .env shift ;; --with-nginx-pagespeed) sed -i "s/NGX_PAGESPEED=[a-zA-Z]*/NGX_PAGESPEED=true/g" .env shift ;; --with-nginx-passenger) sed -i "s/NGX_HTTP_PASSENGER=[a-zA-Z]*/NGX_HTTP_PASSENGER=true/g" .env shift ;; --with-nginx-pcre) exit_if_optarg_is_empty "${1}" "${2}" shift NGINX_PCRE_VERSION=${1-"8.45"} sed -i "s/NGINX_WITH_PCRE=[a-zA-Z]*/NGINX_WITH_PCRE=true/g" .env sed -i "s/NGINX_PCRE_VERSION=\"[0-9a-zA-Z.\ ]*\"/NGINX_PCRE_VERSION=\"${NGINX_PCRE_VERSION}\"/g" .env shift ;; --with-nginx-rtmp) sed -i "s/NGX_RTMP=[a-zA-Z]*/NGX_RTMP=true/g" .env shift ;; # Usage: --with-php --with-php) exit_if_optarg_is_empty "${1}" "${2}" shift PHP_VERSIONS=${1} sed -i "s/INSTALL_PHP=[a-zA-Z]*/INSTALL_PHP=true/g" .env sed -i "s/PHP_VERSIONS=\"[0-9.\ ]*\"/PHP_VERSIONS=\"${PHP_VERSIONS}\"/g" .env shift ;; # Usage: --with-php-extensions= --with-php-extensions) exit_if_optarg_is_empty "${1}" "${2}" shift PHP_EXTENSIONS=$( echo "${1}" | tr '[:upper:]' '[:lower:]' ) sed -i "s/PHP_EXTENSIONS=\"[a-zA-Z,\ ]*\"/PHP_EXTENSIONS=\"${PHP_EXTENSIONS}\"/g" .env shift ;; # Usage: --with-php-loader --with-php-loader) exit_if_optarg_is_empty "${1}" "${2}" shift sed -i "s/INSTALL_PHP_LOADER=[a-zA-Z]*/INSTALL_PHP_LOADER=true/g" .env PHP_LOADER=$( echo "${1}" | tr '[:upper:]' '[:lower:]' ) case "${PHP_LOADER}" in all) sed -i "s/PHP_LOADER=\"[a-zA-Z]*\"/PHP_LOADER=\"all\"/g" .env ;; ic | ioncube) sed -i "s/PHP_LOADER=\"[a-zA-Z]*\"/PHP_LOADER=\"ioncube\"/g" .env ;; sg | sourceguardian) sed -i "s/PHP_LOADER=\"[a-zA-Z]*\"/PHP_LOADER=\"sourceguardian\"/g" .env ;; *) echo "Selected PHP Loader: ${PHP_LOADER} is not supported." sed -i "s/INSTALL_PHP_LOADER=[a-zA-Z]*/INSTALL_PHP_LOADER=false/g" .env ;; esac shift ;; # Usage: --with-mysql-server --with-mysql-server) exit_if_optarg_is_empty "${1}" "${2}" shift sed -i "s/INSTALL_MYSQL=[a-zA-Z]*/INSTALL_MYSQL=true/g" .env MYSQL_SERVER=$( echo "${1}" | tr '[:upper:]' '[:lower:]' ) # Reserve default IFS _IFS=${IFS} IFS='-' read -r -a _MYSQL_SERVER <<< "${MYSQL_SERVER}" MYSQL_SERVER_NAME="${_MYSQL_SERVER[0]}" MYSQL_SERVER_VER="${_MYSQL_SERVER[1]}" # Restore default IFS IFS=${_IFS} case "${MYSQL_SERVER_NAME}" in mysql | mysql-server) sed -i "s/MYSQL_SERVER=\"[a-zA-Z]*\"/MYSQL_SERVER=\"mysql\"/g" .env ;; mariadb) sed -i "s/MYSQL_SERVER=\"[a-zA-Z]*\"/MYSQL_SERVER=\"mariadb\"/g" .env ;; *) echo "Selected MySQL Server: ${MYSQL_SERVER} is not supported, fallback to MariaDB Server." sed -i "s/MYSQL_SERVER=\"[a-zA-Z]*\"/MYSQL_SERVER=\"mariadb\"/g" .env ;; esac if [ -n "${MYSQL_SERVER_VER}" ]; then sed -i "s/MYSQL_VERSION=\"[0-9.\ ]*\"/MYSQL_VERSION=\"${MYSQL_SERVER_VER}\"/g" .env fi shift ;; # Usage: --with-memcached --with-memcached) exit_if_optarg_is_empty "${1}" "${2}" shift MEMCACHED_VERSION=${1} sed -i "s/INSTALL_MEMCACHED=[a-zA-Z]*/INSTALL_MEMCACHED=true/g" .env sed -i "s/MEMCACHED_VERSION=\"[0-9a-zA-Z.\ ]*\"/MEMCACHED_VERSION=\"${MEMCACHED_VERSION}\"/g" .env shift ;; # Usage: --with-memcached-installer --with-memcached-installer) exit_if_optarg_is_empty "${1}" "${2}" shift MEMCACHED_INSTALLER=${1} case "${MEMCACHED_INSTALLER}" in source) sed -i "s/MEMCACHED_INSTALLER=\"[a-zA-Z]*\"/MEMCACHED_INSTALLER=\"source\"/g" .env ;; *) sed -i "s/MEMCACHED_INSTALLER=\"[a-zA-Z]*\"/MEMCACHED_INSTALLER=\"repo\"/g" .env ;; esac shift ;; # Usage: --with-mongodb --with-mongodb) exit_if_optarg_is_empty "${1}" "${2}" shift MONGODB_VERSION=${1} sed -i "s/INSTALL_MONGODB=[a-zA-Z]*/INSTALL_MONGODB=true/g" .env sed -i "s/MONGODB_VERSION=\"[0-9a-zA-Z.\ ]*\"/MONGODB_VERSION=\"${MONGODB_VERSION}\"/g" .env shift ;; # Usage: --with-mongodb-admin --with-mongodb-admin) exit_if_optarg_is_empty "${1}" "${2}" shift MONGODB_ADMIN="${1}" # Reserve default IFS _IFS=${IFS} IFS=':' read -r -a MONGODB_ADMIN_AUTH <<< "${MONGODB_ADMIN}" MONGODB_ADMIN_USER="${MONGODB_ADMIN_AUTH[0]}" MONGODB_ADMIN_PASS="${MONGODB_ADMIN_AUTH[1]}" # Restore default IFS IFS=${_IFS} sed -i "s/MONGODB_ADMIN_USER=\"[0-9a-zA-Z._-]*\"/MONGODB_ADMIN_USER=\"${MONGODB_ADMIN_USER}\"/g" .env sed -i "s/MONGODB_ADMIN_PASSWORD=\"[0-9a-zA-Z._-]*\"/MONGODB_ADMIN_PASSWORD=\"${MONGODB_ADMIN_PASS}\"/g" .env shift ;; # Usage: --with-redis --with-redis) exit_if_optarg_is_empty "${1}" "${2}" shift REDIS_VERSION=${1} if [ -z "${REDIS_VERSION}" ]; then REDIS_VERSION="stable"; fi sed -i "s/INSTALL_REDIS=[a-zA-Z]*/INSTALL_REDIS=true/g" .env sed -i "s/REDIS_VERSION=\"[0-9a-zA-Z._-]*\"/REDIS_VERSION=\"${REDIS_VERSION}\"/g" .env shift ;; # Usage: --with-redis-installer --with-redis-installer) exit_if_optarg_is_empty "${1}" "${2}" shift REDIS_INSTALLER=${1} case "${REDIS_INSTALLER}" in source) sed -i "s/REDIS_INSTALLER=\"[a-zA-Z.\ ]*\"/REDIS_INSTALLER=\"source\"/g" .env ;; *) sed -i "s/REDIS_INSTALLER=\"[a-zA-Z]*\"/REDIS_INSTALLER=\"repo\"/g" .env ;; esac shift ;; # Usage: --with-redis-requirepass --with-redis-requirepass) exit_if_optarg_is_empty "${1}" "${2}" shift REDIS_PASSWORD=${1} sed -i "s/REDIS_REQUIRE_PASSWORD=[a-zA-Z]*/REDIS_REQUIRE_PASSWORD=true/g" .env sed -i "s/REDIS_PASSWORD=\"[0-9a-zA-Z._-]*\"/REDIS_PASSWORD=\"${REDIS_PASSWORD}\"/g" .env shift ;; --with-ssh-port) exit_if_optarg_is_empty "${1}" "${2}" shift SSH_PORT=${1} if [[ ${SSH_PORT} =~ ^[0-9]+$ ]]; then sed -i "s/SSH_PORT=[0-9]*/SSH_PORT=${SSH_PORT}/g" .env else sed -i "s/SSH_PORT=[0-9]*/SSH_PORT=2269/g" .env fi shift ;; --with-ssh-passwordless) sed -i "s/SSH_ROOT_LOGIN=[a-zA-Z]*/SSH_ROOT_LOGIN=false/g" .env sed -i "s/SSH_PASSWORDLESS=[a-zA-Z]*/SSH_PASSWORDLESS=true/g" .env shift ;; -B | --fix-broken-install) sed -i "s/FIX_BROKEN_INSTALL=[a-zA-Z]*/FIX_BROKEN_INSTALL=true/g" .env shift ;; -d | --development) sed -i "s/ENVIRONMENT=\"[a-zA-Z]*\"/ENVIRONMENT=\"development\"/g" .env shift ;; -D | --debug) DEBUG_MODE=true shift ;; --dry-run) DRYRUN=true sed -i "s/DRYRUN=[a-zA-Z]*/DRYRUN=true/g" .env shift ;; -F | --force) sed -i "s/FORCE_INSTALL=[a-zA-Z]*/FORCE_INSTALL=true/g" .env sed -i "s/FORCE_REMOVE=[a-zA-Z]*/FORCE_REMOVE=true/g" .env shift ;; -g | --guided | --unattended) sed -i "s/AUTO_INSTALL=[a-zA-Z]*/AUTO_INSTALL=false/g" .env sed -i "s/AUTO_REMOVE=[a-zA-Z]*/AUTO_REMOVE=false/g" .env shift ;; -h | --hostname) exit_if_optarg_is_empty "${1}" "${2}" shift SERVER_HOSTNAME=${1} sed -i "s/SERVER_HOSTNAME=\"[a-zA-Z0-9._-]*\"/SERVER_HOSTNAME=\"${SERVER_HOSTNAME}\"/g" .env shift ;; -i | --ipv4) exit_if_optarg_is_empty "${1}" "${2}" shift SERVER_IP=${1} sed -i "s/SERVER_IP=\"[0-9.]*\"/SERVER_IP=\"${SERVER_IP}\"/g" .env shift ;; -p | --production) sed -i "s/ENVIRONMENT=\"[a-zA-Z]*\"/ENVIRONMENT=\"production\"/g" .env shift ;; --admin-email) exit_if_optarg_is_empty "${1}" "${2}" shift LEMPER_ADMIN_EMAIL=${1} sed -i "s/LEMPER_ADMIN_EMAIL=\"[0-9a-zA-Z._-@\ ]*\"/LEMPER_ADMIN_EMAIL=\"${LEMPER_ADMIN_EMAIL}\"/g" .env shift ;; --) shift break ;; *) echo "${PROG_NAME}: '${1}' is not valid argument" echo "See '${PROG_NAME} --help' for more information" exit 1 ;; esac done # Set debug mode. set_debug_mode "${DEBUG_MODE}" set_dryrun_mode "${DRYRUN}" # Include helper functions. if [[ "$(type -t run)" != "function" ]]; then . ./scripts/helper.sh fi # Make sure only supported distribution can run this installer script. preflight_system_check # Go action. case "${CMD}" in --install | install) #./install.sh header_msg lemper_install final_time_result "${START_TIME}" footer_msg exit 0 ;; --uninstall | --remove | uninstall | remove) #./remove.sh header_msg lemper_remove final_time_result "${START_TIME}" footer_msg exit 0 ;; -h | --help | help) echo "For more help please visit https://github.com/joglomedia/LEMPer" exit 0 ;; *) echo "${PROG_NAME}: '${CMD}' is not ${PROG_NAME} command" echo "See '${PROG_NAME} --help' for more information" exit 1 ;; esac } # Start running things from a call at the end so if this script is executed # after a partial download it doesn't do anything. init_lemper_install "$@"