#!/bin/bash
# postrm 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:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <overwriter>
#          <overwriter-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;

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

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

if test -x "/usr/bin/apt"; then
    /usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||:

    # /etc/nginx/conf.d/modules/ngx_http_pipelog_module.conf is a %ghost so will get removed
    # /etc/nginx/conf.d/global-logging.conf will be left behind and, if it has
    #   piped logging enabled then its an invalid configuraiton *but* we don't have nginc
    #  at this point and reinstalling should regen config so do we care?
    rm -rf  /etc/nginx/conf.d/global-logging.conf

    rm -rf /etc/nginx/ea-nginx/cpanel_localhost_header.json

    if [ "$1" = "upgrade" ]; then
        /sbin/service nginx status  >/dev/null 2>&1 || exit 0
        /sbin/service nginx upgrade >/dev/null 2>&1 || echo "Binary upgrade failed, please check nginx's error.log"

        exit 0
    fi

    rm -f /etc/nginx/conf.d/modules/ngx_http_pipelog_module.conf
    rm -f /etc/nginx/conf.d/passenger.conf
fi

# End SOURCES/pkg.postrm


exit 0
