#!/usr/bin/env bash ####################################################################################### # # # A script to install a mainline/stable version of NGINX with custombuild2 # # A version number of NGINX mainline is taken from NGINX's trac site # # # ####################################################################################### # # # Version: 0.4.1 (Fri Dec 16 13:08:32 +07 2022) # # Written by: Alex S Grebenschikov (zEitEr) # # Site: www.poralix.com E-mail: support@poralix.com # # # ####################################################################################### ####################################################################################### ## # ## MIT License # ## # ## Copyright (c) 2016-2022 Alex S Grebenschikov (www.poralix.com) # ## # ## Permission is hereby granted, free of charge, to any person obtaining a copy # ## of this software and associated documentation files (the "Software"), to deal # ## in the Software without restriction, including without limitation the rights # ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # ## copies of the Software, and to permit persons to whom the Software is # ## furnished to do so, subject to the following conditions: # ## # ## The above copyright notice and this permission notice shall be included in all # ## copies or substantial portions of the Software. # ## # ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # ## SOFTWARE. # ## # ####################################################################################### function usage() { echo "########################################################################"; echo "# #"; echo "# A script to install either a mainline or stable version of NGINX #"; echo "# for Directadmin Custombuild2 #"; echo "# A version of NGINX mainline will be installed by default #"; echo "# Version: 0.4.1 (Fri Dec 16 13:08:32 +07 2022) #"; echo "# Written by: Alex S Grebenschikov (zEitEr) #"; echo "# #"; echo "########################################################################"; echo ""; echo "Usage:"; echo " $0 versions - to update information of available mainline version "; echo " $0 download - to download the latest available mainline version "; echo " $0 install - to download and install the latest mainline version"; echo " $0 cron - to run with cron (no installation is done here)"; echo " $0 set-cron - to install a cron-task to run 'cron --${BRANCH}' nightly"; echo ""; echo "Branches (optional):" echo " --mainline - (default value) actively developed, includes new features"; echo " --stable - stabe version, recieves only bug-fixes"; } function update_versions() { update_version_stable; update_version_mainline; cd /usr/local/directadmin/custombuild; cat "custom_versions.txt" | grep -Ev "^nginx:|^nginx_stable:|^nginx_mainline:|^$" > "custom_versions.txt.new"; if [ "${BRANCH}" == "mainline" ]; then NGINX_VER="${NGINX_VER_MAINLINE}"; else NGINX_VER="${NGINX_VER_STABLE}"; fi; [ -n "${NGINX_VER_MAINLINE}" ] && echo "nginx_mainline:${NGINX_VER_MAINLINE}:" >> custom_versions.txt.new; [ -n "${NGINX_VER_STABLE}" ] && echo "nginx_stable:${NGINX_VER_STABLE}:" >> custom_versions.txt.new; [ -n "${NGINX_VER}" ] && echo "nginx:${NGINX_VER}:" >> "custom_versions.txt.new"; mv -f "custom_versions.txt.new" "custom_versions.txt"; } function update_version_mainline() { VERSIONS_FILES=""; VERSIONS_FILES="${VERSIONS_FILES} https://raw.githubusercontent.com/nginx/nginx/master/.hgtags"; # GitHub VERSIONS_FILES="${VERSIONS_FILES} https://trac.nginx.org/nginx/export/HEAD/nginx/.hgtags"; # TRAC VERSIONS_FILES="${VERSIONS_FILES} https://hg.nginx.org/nginx/raw-file/tip/.hgtags"; # Official Mercurial Mirror # Version number of installed NGINX NGINX_INSTALLED_VER=$(nginx -v 2>&1 | cut -d\/ -f2); for VERSIONS_FILE in ${VERSIONS_FILES}; do { NGINX_VER_MAINLINE=$(wget -q ${VERSIONS_FILE} -O - | tail -1 | cut -d\- -f2 | grep -o '[0-9]*\.[0-9]*\.[0-9]*'); [ -n "${NGINX_VER_MAINLINE}" ] && break; } done; } function update_version_stable() { # Version number of installed NGINX NGINX_INSTALLED_VER=$(nginx -v 2>&1 | cut -d\/ -f2); NGINX_VER_STABLE=$(/bin/curl -s http://nginx.org/packages/centos/7/x86_64/RPMS/ | grep -o "nginx-[0-9]*\.[0-9]*\.[0-9]*-[0-9]*\.el7[_0-9]*\.ngx.x86_64.rpm" | cut -d\- -f2 | sort --version-sort | tail -1); } function show_versions() { echo "Latest stable version of Nginx: ${NGINX_VER_STABLE} ${SELECTED_STABLE}"; echo "Latest mainline version of Nginx: ${NGINX_VER_MAINLINE} ${SELECTED_MAINLINE}"; echo "Installed version of Nginx: ${NGINX_INSTALLED_VER}"; } function download_nginx() { cd /usr/local/directadmin/custombuild; wget https://nginx.org/download/nginx-${NGINX_VER}.tar.gz -O nginx-${NGINX_VER}.tar.gz; } function install_nginx() { cd /usr/local/directadmin/custombuild; ./build update; # Custombuild ignores downloaded packages, and tries to download them again # so we need to patch it to use already downloaded package perl -pi -e 's|safeDownloadWithMove "\$\{CWD\}/nginx-|#safeDownloadWithMove "\$\{CWD\}/nginx-|' /usr/local/directadmin/custombuild/build; perl -pi -e 's|safeDownloadWithMove "\$\{WORKDIR\}/nginx-|#safeDownloadWithMove "\$\{WORKDIR\}/nginx-|' /usr/local/directadmin/custombuild/build; ./build nginx; # Bring custombuild script back to the original view after we completed nginx installation perl -pi -e 's|#safeDownloadWithMove "\$\{CWD\}/nginx-|safeDownloadWithMove "\$\{CWD\}/nginx-|' /usr/local/directadmin/custombuild/build; perl -pi -e 's|#safeDownloadWithMove "\$\{WORKDIR\}/nginx-|safeDownloadWithMove "\$\{WORKDIR\}/nginx-|' /usr/local/directadmin/custombuild/build; } function set_cron() { cd /usr/local/directadmin/custombuild/ wget https://raw.githubusercontent.com/poralix/directadmin-utils/master/nginx/build_nginx -O ./build_nginx chmod 755 ./build_nginx touch /etc/cron.d/0build_nginx; chmod 644 /etc/cron.d/0build_nginx; echo "21 4 * * * root /usr/local/directadmin/custombuild/build_nginx cron --${BRANCH}" > /etc/cron.d/0build_nginx; } BRANCH="mainline"; SELECTED_MAINLINE="(selected)"; SELECTED_STABLE=""; for arg in $@; do case ${arg} in --stable) BRANCH="stable"; SELECTED_MAINLINE=""; SELECTED_STABLE="(selected)"; ;; --mainline|*) BRANCH="mainline"; SELECTED_MAINLINE="(selected)"; SELECTED_STABLE=""; ;; esac; done; case "$1" in "download") update_versions; download_nginx; ;; "cron") update_versions >/dev/null 2>&1; download_nginx >/dev/null 2>&1; ;; "versions") update_versions; show_versions; ;; "install") update_versions; download_nginx; install_nginx; ;; "set-cron") set_cron; ;; *) usage; ;; esac; exit 0;