From 13bbb5e4d26656013b791b58ccac1a017f6695ca Mon Sep 17 00:00:00 2001 From: Edi Septriyanto Date: Sun, 29 Dec 2024 23:05:57 +0700 Subject: [PATCH] Improve LEMPer CLI tool --- lib/lemper-bench.sh | 2 +- lib/lemper-create.sh | 93 ++++++++++++++++++++++++---------------- lib/lemper-manage.sh | 45 +++++++++++-------- scripts/install_tools.sh | 32 +++++++------- 4 files changed, 99 insertions(+), 73 deletions(-) diff --git a/lib/lemper-bench.sh b/lib/lemper-bench.sh index 4d2a775..3899f2d 100755 --- a/lib/lemper-bench.sh +++ b/lib/lemper-bench.sh @@ -28,7 +28,7 @@ tram=$( free -m | awk '/^Mem:/ { print $2 }' ) echo "Total RAM size: $tram MB" swap=$( free -m | awk '/^Swap:/ { print $2 }' ) echo "Total Swap size: $swap MB" -up=$(uptime|awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }') +up=$(uptime | awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }') echo "System uptime: $up" load=$(uptime | awk -F: '{ print $5 }') echo "Load average: $load" diff --git a/lib/lemper-create.sh b/lib/lemper-create.sh index fb8afba..f6b39bd 100755 --- a/lib/lemper-create.sh +++ b/lib/lemper-create.sh @@ -797,6 +797,19 @@ function validate_ipv6() { echo ${return} } +## +# Validate FQDN domain. +## +function validate_fqdn() { + local FQDN=${1} + + if grep -qP "(?=^.{4,253}\.?$)(^((?!-)[a-zA-Z0-9-]{1,63}(? "${WEBROOT}/index.html" fi fi - + # Fix ownership. run chown -hR "${USERNAME}:${USERNAME}" "${WEBROOT}" @@ -1600,9 +1615,8 @@ EOL fi fi - echo "Fix files ownership and permission..." - # Fix document root ownership. + echo "Fix file ownership and permissions..." run chown -hR "${USERNAME}:${USERNAME}" "${WEBROOT}" # Fix document root permission. @@ -1614,7 +1628,7 @@ EOL info "New domain ${SERVERNAME} added in dry run mode." fi - echo "Enable ${SERVERNAME} virtual host." + echo "Enable the ${SERVERNAME} virtual host." # Enable site. if [[ ! -f "/etc/nginx/sites-enabled/${SERVERNAME}.conf" ]]; then @@ -1628,32 +1642,35 @@ EOL # Validate config, reload when validated. if nginx -t 2>/dev/null > /dev/null; then run systemctl restart nginx - echo "Nginx server reloaded with new configuration." + echo "Nginx server reloaded with the new configuration." else - info "Something went wrong with Nginx configuration." + info "Something went wrong with the Nginx configuration." fi if [[ -f "/etc/nginx/sites-enabled/${SERVERNAME}.conf" && -e /var/run/nginx.pid ]]; then - success "Your ${SERVERNAME} successfully added to Nginx virtual host." + success "Your ${SERVERNAME} was successfully added to the Nginx virtual host." # Enable HTTPS. + APP_HTTP_PROTO="http" + if [[ ${ENABLE_SSL} == true ]]; then - echo "Enable HTTPS protocol utilizing Let's Encrypt SSL for ${SERVERNAME}..." + echo "Enabling HTTPS protocol using Let's Encrypt SSL for ${SERVERNAME}..." #echo "You can enable HTTPS from lemper-cli after this setup!" #echo "command: lemper-cli site mod --enable-ssl ${SERVERNAME}" - run lemper-cli site mod --enable-ssl "${SERVERNAME}" + run lemper-cli site mod --enable-ssl "${SERVERNAME}" && \ + APP_HTTP_PROTO="https" fi # WordPress MS notice. if [[ "${FRAMEWORK}" == "wordpress-ms" ]]; then - echo "" - info -e "You're installing Wordpress Multisite.\nYou should activate Nginx Helper plugin to work properly." + info -e "\nYou're installing Wordpress Multisite.\nYou should activate the Nginx Helper plugin for it to work properly." fi # Save app installation details. if [[ ${INSTALL_APP} == true ]]; then - echo -e "\nYour application login details:\nAdmin user: ${APP_ADMIN_USER}\nAdmin pass: ${APP_ADMIN_PASS}\nAdmin email: ${APP_ADMIN_EMAIL}" - echo -e "Database user: ${APP_DB_USER}\nDatabase pass: ${APP_DB_PASS}\nDatabase name: ${APP_DB_NAME}" + echo -e "\nYour application's login details:\nAdmin Username: ${APP_ADMIN_USER}\nAdmin Password: ${APP_ADMIN_PASS}\nAdmin Email : ${APP_ADMIN_EMAIL}" + echo -e "DB Username: ${APP_DB_USER}\nDB Password: ${APP_DB_PASS}\nDB Name : ${APP_DB_NAME}" + echo -e "Site Address: ${APP_HTTP_PROTO}://${SERVERNAME}" cat > "/etc/lemper/vhost.d/${SERVERNAME}.conf" < HTTPS redirection block. cat >> "/etc/nginx/sites-available/${DOMAIN}.conf" <" > /usr/share/nginx/html/lcp/phpinfo.php83' # Install Adminer for Web-based MySQL Administration Tool. + echo -n "Installing database AdminerEVO..." [ ! -d /usr/share/nginx/html/lcp/dbadmin ] && run mkdir -p /usr/share/nginx/html/lcp/dbadmin # Overwrite existing files. - run wget -q https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1.php \ - -O /usr/share/nginx/html/lcp/dbadmin/index.php - run wget -q https://github.com/vrana/adminer/releases/download/v4.8.1/editor-4.8.1.php \ - -O /usr/share/nginx/html/lcp/dbadmin/editor.php + run curl -sSL -o /usr/share/nginx/html/lcp/dbadmin/index.php \ + https://github.com/adminerevo/adminerevo/releases/download/v4.8.4/adminer-4.8.4.php + run curl -sSL -o /usr/share/nginx/html/lcp/dbadmin/editor.php \ + https://github.com/adminerevo/adminerevo/releases/download/v4.8.4/editor-4.8.4.php \ [ -f /usr/share/nginx/html/lcp/dbadmin/index.php ] && echo_ok "OK" @@ -112,8 +112,7 @@ function init_tools_install() { # Install File Manager. # Experimental: Tinyfilemanager https://github.com/joglomedia/tinyfilemanager # Clone custom TinyFileManager. - - echo -n "Installing file manager..." + echo -n "Installing file manager TinyFileManager..." if [ ! -d /usr/share/nginx/html/lcp/filemanager/config ]; then run git clone -q --depth=1 --branch=lemperfm_1.3.0 https://github.com/joglomedia/tinyfilemanager.git \ @@ -122,8 +121,8 @@ function init_tools_install() { local CURRENT_DIR && \ CURRENT_DIR=$(pwd) run cd /usr/share/nginx/html/lcp/filemanager && \ - run wget -q https://raw.githubusercontent.com/joglomedia/tinyfilemanager/lemperfm_1.3.0/index.php \ - -O /usr/share/nginx/html/lcp/filemanager/index.php && \ + run curl -sSL -o /usr/share/nginx/html/lcp/filemanager/index.php \ + https://raw.githubusercontent.com/joglomedia/tinyfilemanager/lemperfm_1.3.0/index.php && \ run cd "${CURRENT_DIR}" || return 1 fi @@ -136,12 +135,11 @@ function init_tools_install() { [[ -f /usr/share/nginx/html/lcp/filemanager/index.php && -x /etc/lemper/cli-plugins/lemper-tfm ]] && \ echo_ok "OK" - # Install Zend OpCache Web Admin. echo -n "Installing phpOpCacheStatus panel..." - run wget -q https://raw.github.com/rlerdorf/opcache-status/master/opcache.php \ - -O /usr/share/nginx/html/lcp/opcache.php + run curl -sSL -o /usr/share/nginx/html/lcp/opcache.php \ + https://raw.github.com/rlerdorf/opcache-status/master/opcache.php [ -f /usr/share/nginx/html/lcp/opcache.php ] && echo_ok "OK" # Install phpMemcachedAdmin Web Admin.