Kerala Cyber Warriors
KCW Uploader V1.1

Path : /var/lib/dpkg/info/
File Upload :
Current File : //var/lib/dpkg/info/alt-php-internal.postinst

#!/bin/bash

major_ver=8
minor_ver=2
patch_ver=13
php_version="${major_ver}${minor_ver}"
php_version_dot="${major_ver}.${minor_ver}"
php_version_slash="${major_ver}\.${minor_ver}"
name='alt-php'
version="${major_ver}.${minor_ver}.${patch_ver}"
altdir="/opt/alt/php${php_version}"
_prefix='/usr'
_sysconfdir='/etc'
_bindir="${_prefix}/bin"
_sbindir="${_prefix}/sbin"

__imunify=1

if [ -n "${__imunify}" ]; then
    altdir="/opt/alt/php-internal"
fi

echo "${name}-${version}" >> /opt/alt/alt_php.status

if [ -n "${__imunify}" ]; then
    find ${altdir} -type f -exec chmod 700 {} \;
    chmod 700 ${altdir}${_sysconfdir}/php.d
    chmod 700 ${altdir}/link
    chmod 5700 ${altdir}/var/lib/php/session
    chmod 600 ${altdir}${_sysconfdir}/php.d/default.ini
    chmod 700 ${altdir}${_libdir}/php
    chmod 700 ${altdir}${_libdir}/php/modules
    chmod 700 ${altdir}${_includedir}/php
    chmod 700 ${altdir}${_includedir}/php/ext
else
    [ -x /usr/bin/cl-linksafe-apply-group ] && /usr/bin/cl-linksafe-apply-group ${name}${php_version}
    chmod 5733 ${altdir}/var/lib/php/session
fi

if [ -z "${__imunify}" ]; then
    echo "${name}-${version}" >> /opt/alt/alt_php.status
    if [ -x /opt/alt/alt-php-config/multiphp_reconfigure.py ]; then
        /opt/alt/alt-php-config/multiphp_reconfigure.py --php ${php_version}
    fi

    # Enable nd_mysqli driver instead mysqli
    if [ -x /usr/sbin/cloudlinux-selector ]; then
        if [ $(/usr/sbin/cloudlinux-selector --help | grep 'make-defaults-config' > /dev/null) ]; then
            /usr/sbin/cloudlinux-selector make-defaults-config --json --interpreter=php
        fi
    fi
    # for yum update
    # if add some extensions in default.ini -> update plesk handlers
    recreate_php_handlers=0
    for i in $(cat ${altdir}${_sysconfdir}/php.d.all/* | grep "^[zend_]*extension.*=.*" | sort | uniq | sed -e 's#^#;#;s#[ "]##g'); do
        match=$(echo $i | sed -e 's#.*=##')
        if [ ! $(grep "$match" ${altdir}${_sysconfdir}/php.d/default.ini > /dev/null) ]; then
            echo $i >> ${altdir}${_sysconfdir}/php.d/default.ini
            recreate_php_handlers=1
        fi
    done
    # in the default.ini file ioncube_loader should be the first among zend extensions
    zend_ext=$(grep 'zend_extension'  ${altdir}${_sysconfdir}/php.d/default.ini | sort | uniq)
    if [ -n "$zend_ext" ]; then
        recreate_php_handlers=1
        sed -i '/zend_extension/d'  ${altdir}${_sysconfdir}/php.d/default.ini
        for str in $zend_ext; do
            echo $str >> ${altdir}${_sysconfdir}/php.d/default.ini
        done
    fi

    if [ -x /usr/local/psa/bin/php_handler -a $recreate_php_handlers -eq 1 ]; then
        /usr/local/psa/bin/php_handler --update -id alt-php${php_version}-cgi
    fi
fi

if [ -x /opt/alt/alt-php-config/alt-php-panel-configuration.py ]; then
    /opt/alt/alt-php-config/alt-php-panel-configuration.py --mode=install --php=${php_version}
fi
CONF_DIR='/etc/cl.selector'
CONF_PATH="$CONF_DIR/selector.conf"
BIN_DIR=${altdir}${_bindir}
SBIN_DIR=${altdir}${_sbindir}
VERS=${php_version_dot}
VERS2=${php_version_slash}

if [ ! -e $CONF_DIR ]; then
    mkdir -m 755 -p $CONF_DIR
fi

if [ ! -e $CONF_PATH ]; then
    echo -n '' > $CONF_PATH
fi
VERSION="`echo ${version} | awk -F '(alpha|beta|RC[0-9]+)' '{print $1}'`"
if [ -z "${__imunify}" ]; then
    if [ -e $CONF_PATH ]; then
        sed -i -e "/\s$VERS2/d" $CONF_PATH
        echo "php $VERS $VERSION $BIN_DIR/php-cgi" >> $CONF_PATH
        echo "php-cli $VERS $VERSION $BIN_DIR/php" >> $CONF_PATH
        echo "php-fpm $VERS $VERSION $SBIN_DIR/php-fpm" >> $CONF_PATH
        echo "lsphp $VERS $VERSION $BIN_DIR/lsphp" >> $CONF_PATH
        echo "php.ini $VERS $VERSION ${altdir}/etc/php.ini" >> $CONF_PATH
    else
        echo "Failed to create $CONF_PATH"
    fi

    if [ -e /opt/alt/alt_php.status ]; then
            sed -i "/${name}-${version}/d" /opt/alt/alt_php.status
        if [ ! -s /opt/alt/alt_php.status ]; then
            rm -f /opt/alt/alt_php.status
            if [ -x /usr/sbin/cagefsctl -a -e /usr/share/cagefs-skeleton/bin ]; then
                if [ -e "${CONF_PATH}" ]; then
                    /usr/sbin/cagefsctl --wait-lock --setup-cl-alt
                fi
                /usr/sbin/cagefsctl --wait-lock --rebuild-alt-php-ini
                if [ -e /usr/share/cagefs/need.remount ]; then
                    /usr/sbin/cagefsctl --wait-lock --remount-all
                fi
            fi
            # ALTPHP-420: update phpNN.dat files while installing alt-php
            if [ ! -e /var/lve/php${php_version_dot}.dat ]; then
                touch /var/lve/php${php_version_dot}.dat
            fi
            if [ -x /usr/share/l.v.e-manager/utils/cache_phpdata.py ]; then
                /usr/bin/flock -n /var/run/cloudlinux_cache_php.cronlock /usr/share/l.v.e-manager/utils/cache_phpdata.py
            fi
        fi
    fi

    # ALTPHP-925: Remove alt-php74-imunify handlers from Plesk
    if [ -x /usr/local/psa/bin/php_handler ]; then
        if [ "$(/usr/local/psa/bin/php_handler --list | grep 'alt-php74-imunify')" ]; then
            /usr/local/psa/bin/php_handler --remove -id alt-php74-imunify-fastcgi
            /usr/local/psa/bin/php_handler --remove -id alt-php74-imunify-cgi
            /usr/local/psa/bin/php_handler --remove -id alt-php74-imunify-fpm
        fi
        if [ "$(/usr/local/psa/bin/php_handler --list | grep 'alt-php-internal')" ]; then
            /usr/local/psa/bin/php_handler --remove -id alt-php-internal-fastcgi
            /usr/local/psa/bin/php_handler --remove -id alt-php-internal-cgi
            /usr/local/psa/bin/php_handler --remove -id alt-php-internal-fpm
        fi
    fi
fi

-=[ KCW uplo4d3r c0ded by cJ_n4p573r ]=-
Ⓒ2017 ҠЄГѦLѦ СүѣЄГ ЩѦГГіѺГՏ