#!/bin/bash
# postinst script for #PACKAGE#
#
# see: dh_installdeb(1)

set -e

# Begin vars.sh
#!/bin/bash
# DO NOT EDIT
# This file is regenerated each run.
# If you want to add or change a variable, edit debify/settings.json and the vars hashref

source /etc/os-release
export OBS_REPO="x${NAME}_${VERSION_ID}"
if ls debian/*.install &> /dev/null; then
    perl -pi -e 's/\${env:OBS_REPO}/$ENV{OBS_REPO}/' debian/*.install
fi

export DEB_INSTALL_ROOT="/usr/src/packages/BUILD/debian/tmp"
export DEB_SOURCE_ROOT="/usr/src/packages/BUILD/debian/SOURCES_FROM_SPEC"
export BASE_CONFIGURE_ARGS="$(echo "--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nobody --group=nobody --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-openssl-opt=enable-tls1_3 --with-openssl-opt=no-nextprotoneg")"
export BASE_WITH_CC_OPT=""
export BASE_WITH_LD_OPT=""
export RPM_SOURCE_DIR="/usr/src/packages/BUILD/debian/SOURCES_FROM_SPEC"
export WITH_CC_OPT="$(echo "")"
export WITH_LD_OPT="$(echo "")"
export __isa_bits="64"
export __isa_name="x86"
export __sourcedir=""
export _bindir="/opt/cpanel//root/usr/bin"
export _builddir=""
export _datadir="/usr/share"
export _defaultdocdir="/usr/share/doc"
export _docdir="/usr/share/doc"
export _exec_prefix="/opt/cpanel//root/usr"
export _group="Productivity/Networking/Web/Servers"
export _includedir="/opt/cpanel//root/usr/include"
export _infodir="/usr/share/info"
export _isa=""
export _lib="lib64"
export _libdir="/usr/lib64"
export _libexecdir="/usr/libexec"
export _localstatedir="/var"
export _mandir="/usr/share/man"
export _prefix="/opt/cpanel//root/usr"
export _root_bindir="/opt/cpanel//root/usr/bin"
export _root_datadir="/opt/cpanel//root/usr/share"
export _root_exec_prefix="/opt/cpanel//root/usr"
export _root_includedir="/opt/cpanel//root/usr/include"
export _root_infodir="/usr/share/info"
export _root_initddir="/etc/rc.d/init.d"
export _root_libdir="/opt/cpanel//root/usr/lib64"
export _root_libexecdir="/opt/cpanel//root/usr/libexec"
export _root_localstatedir="/var"
export _root_mandir="/usr/share/man"
export _root_prefix="/opt/cpanel//root/usr"
export _root_sbindir="/opt/cpanel//root/usr/sbin"
export _root_sharedstatedir="/opt/cpanel//root/usr/com"
export _root_sysconfdir="/etc"
export _sbindir="/usr/sbin"
export _scl_prefix="/opt/cpanel"
export _scl_root="/opt/cpanel//root"
export _sysconfdir="/etc"
export _unitdir="/usr/lib/systemd/system"
export bdir="/nginx-1.25.3"
export buildroot="/usr/src/packages/BUILD"
export dist=".el8"
export ea_openssl_ver="1.1.1d-1"
export epoch="1"
export full_package_name="ea-nginx-1.25.3"
export ix86="i386"
export main_version="1.25.3"
export name="ea-nginx"
export nginx_group="nobody"
export nginx_home="/var/cache/nginx"
export nginx_loggroup="adm"
export nginx_user="nobody"
export nil="0"
export ns_name="ea"
export os_minor="%(lsb_release -rs | cut -d '.' -f 2)"
export pkg=""
export pkg_name=""
export pkgname=""
export previous_version="1.25.2"
export release="1"
export release_prefix="1"
export ruby_version="ea-ruby27"
export scl=""
export scl_name=""
export scl_name_base=""
export scl_name_version=""
export scl_prefix=""
export upstream_name="nginx"
export use_systemd="1"
export version="1.25.3"
export version_with_debian_revision="1.25.3-1"
export SOURCE0="$DEB_SOURCE_ROOT/nginx-1.25.3.tar.gz"
export SOURCE1="$DEB_SOURCE_ROOT/logrotate"
export SOURCE2="$DEB_SOURCE_ROOT/nginx.init.in"
export SOURCE3="$DEB_SOURCE_ROOT/nginx.sysconf"
export SOURCE4="$DEB_SOURCE_ROOT/nginx.conf"
export SOURCE5="$DEB_SOURCE_ROOT/nginx.vh.default.conf"
export SOURCE7="$DEB_SOURCE_ROOT/nginx-debug.sysconf"
export SOURCE8="$DEB_SOURCE_ROOT/nginx.service"
export SOURCE9="$DEB_SOURCE_ROOT/nginx.upgrade.sh"
export SOURCE11="$DEB_SOURCE_ROOT/nginx-debug.service"
export SOURCE12="$DEB_SOURCE_ROOT/COPYRIGHT"
export SOURCE13="$DEB_SOURCE_ROOT/nginx.check-reload.sh"
export SOURCE14="$DEB_SOURCE_ROOT/cpanel.tar.gz"
export SOURCE15="$DEB_SOURCE_ROOT/cpanel-chksrvd"
export SOURCE16="$DEB_SOURCE_ROOT/cpanel-scripts-ea-nginx"
export SOURCE17="$DEB_SOURCE_ROOT/FPM_50x.html"
export SOURCE18="$DEB_SOURCE_ROOT/Nginx.pm"
export SOURCE19="$DEB_SOURCE_ROOT/cpanel-scripts-ea-nginx-userdata"
export SOURCE20="$DEB_SOURCE_ROOT/ngx_http_pipelog_module-ngx_http_pipelog_module.c"
export SOURCE21="$DEB_SOURCE_ROOT/ngx_http_pipelog_module-config"
export SOURCE22="$DEB_SOURCE_ROOT/NginxHooks.pm"
export SOURCE23="$DEB_SOURCE_ROOT/NginxTasks.pm"
export SOURCE24="$DEB_SOURCE_ROOT/nginx-adminbin"
export SOURCE25="$DEB_SOURCE_ROOT/nginx-adminbin.conf"
export SOURCE27="$DEB_SOURCE_ROOT/007-restartsrv_nginx"
export SOURCE28="$DEB_SOURCE_ROOT/whm_feature_addon"
export SOURCE29="$DEB_SOURCE_ROOT/set_NGINX_CONFIGURE_array.sh"
# End vars.sh

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    configure)
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# Contents of SOURCES/pkg.postinst
#!/bin/bash

if test -x "/usr/bin/apt"; then
    # Dir needs to exist

    mkdir -p /etc/nginx/conf.d/modules

    # Register the nginx service
    /usr/bin/systemctl preset nginx.service >/dev/null 2>&1 ||:
    /usr/bin/systemctl preset nginx-debug.service >/dev/null 2>&1 ||:
    /usr/bin/systemctl enable nginx.service >/dev/null 2>&1 ||:
    /usr/bin/systemctl disable nginx-debug.service >/dev/null 2>&1 ||:
    # print site info
    cat <<BANNER
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
BANNER

    # Touch and set permisions on default log files on installation

    if [ -d ${_localstatedir}/log/nginx ]; then
        if [ ! -e ${_localstatedir}/log/nginx/access.log ]; then
            touch ${_localstatedir}/log/nginx/access.log
            chmod 640 ${_localstatedir}/log/nginx/access.log
            chown ${nginx_user}:${nginx_loggroup} ${_localstatedir}/log/nginx/access.log
        fi

        if [ ! -e ${_localstatedir}/log/nginx/error.log ]; then
            touch ${_localstatedir}/log/nginx/error.log
            chmod 640 ${_localstatedir}/log/nginx/error.log
            chown ${nginx_user}:${nginx_loggroup} ${_localstatedir}/log/nginx/error.log
        fi
    fi

    /usr/local/cpanel/scripts/restartsrv_httpd --stop
        ${_sysconfdir}/nginx/ea-nginx/meta/apache move_apache_to_alt_ports
        echo "nginx:1" >> /etc/chkserv.d/chkservd.conf

    /usr/bin/systemctl start nginx.service >/dev/null 2>&1 ||:

    # I move this to here, to deal with the craziness of the order of operations
    # on yum upgrade and downgrades.
    # No need to restart nginx here since that is handled in the universal-hook
    /usr/local/cpanel/scripts/ea-nginx config --all --no-reload

    /usr/local/cpanel/bin/manage_hooks prune; /bin/true;
    /usr/local/cpanel/bin/manage_hooks add module NginxHooks

    # Go ahead and enable fileprotect if we disabled it via this package and the
    # ea-nginx-standlone package is not installed
    # Note, ea-nginx-standalone owns /etc/nginx/ea-nginx/enable.standalone so it
    # should only exist if that package is installed
    if [[ -e /etc/nginx/ea-nginx/meta/fileprotect && ! -e /etc/nginx/ea-nginx/enable.standalone ]]; then
        rm -f /etc/nginx/ea-nginx/meta/fileprotect
        /usr/local/cpanel/bin/whmapi1 set_tweaksetting key=enablefileprotect value=1
    fi

    # also ensure that queueprocd is kicked so that it reads in the custom task
    # processor that we wrote for it
    /usr/local/cpanel/scripts/restartsrv queueprocd

    # hook is not run for the transaction that installs it, so for good measure (ZC-7669)
    /etc/apt/universal-hooks/multi_pkgs/Post-Invoke/ea-__WILDCARD__nginx__WILDCARD__/007-restartsrv_nginx
fi

# End SOURCES/pkg.postinst


exit 0
