%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/lib/dpkg/info/
Upload File :
Create Path :
Current File : /var/lib/dpkg/info/kesl.postrm

#!/bin/sh -u

export LC_ALL=C

readonly VAR_DIRECTORY='/var/opt/kaspersky/kesl/'
readonly LOG_DIRECTORY='/var/log/kaspersky/kesl/'
readonly LOG_USER_DIRECTORY='/var/log/kaspersky/kesl-user/'
readonly LICENSE_KEY_FILEPATH='/var/opt/kaspersky/kesl/common/license'
readonly PCID_FILEPATH='/var/opt/kaspersky/kesl/common/pcid'
readonly SELINUX_POLICY_NAME='kesl'

RmDirIfEmpty()
{
    rmdir "$1" 2>/dev/null || true
}

RmDirAndParentIfEmpty()
{
    rm -rf "$1"
    RmDirIfEmpty "$(dirname "$1")"
}

RemoveFilesByMask()
{
    local dir="${1}"
    local mask="${2}"

    find "${dir}" -maxdepth 1 -name "${mask}" -delete
}

Cleanup()
{
    find "${VAR_DIRECTORY}" \( -type f -o -type l \) -print0 | grep -F -v -Zz "${LICENSE_KEY_FILEPATH}" | grep -F -v -Zz "${PCID_FILEPATH}" | xargs -0 -I '{}' rm -f '{}'
    find "${VAR_DIRECTORY}" -type d -empty -delete

    RmDirIfEmpty "${VAR_DIRECTORY}"
    RmDirIfEmpty "$(dirname "${VAR_DIRECTORY}")"
    RmDirAndParentIfEmpty "${LOG_DIRECTORY}"
    RmDirAndParentIfEmpty "${LOG_USER_DIRECTORY}"
}

IsCommandAvailable()
{
    [ -x "$(command -v ${1})" ]
}

IsSELinuxPolicyInstalled()
{
    [ ! -z "$(semodule --list | grep ${SELINUX_POLICY_NAME})" ]
}

SELinux_RemoveContextRecords()
{
    for file in `semanage fcontext --list | grep ":${1}:" | cut --delimiter ' ' --fields 1`; do
        semanage fcontext --delete ${file} >/dev/null 2>&1
    done
}

Main()
{
    local removeMark='remove'
    if [ "$1" != "${removeMark}" ]; then
        return
    fi

    if IsCommandAvailable semodule && IsCommandAvailable semanage && $(IsSELinuxPolicyInstalled); then
        echo "Attempting to remove module '${SELINUX_POLICY_NAME}'"
        SELinux_RemoveContextRecords "${SELINUX_POLICY_NAME}_exec_t"
        SELinux_RemoveContextRecords "${SELINUX_POLICY_NAME}_control_exec_t"
        semodule --remove ${SELINUX_POLICY_NAME} --priority 100 >/dev/null
    fi

    Cleanup
}

Main "$@"
exit 0


Zerion Mini Shell 1.0