%PDF- %PDF-
Mini Shell

Mini Shell

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

#!/bin/sh -u

export LC_ALL=C

ContainSubstr()
{
    printf '%s' "$1" | grep -F "$2" >/dev/null
}

IContainSubstr()
{
    printf '%s' "$1" | grep -iF "$2" >/dev/null
}

IStartsWith()
{
    awk -v "_input=$1" -v "_test=$2" -- 'BEGIN { exit(index(tolower(_input), tolower(_test)) == 1 ? 0 : 1); }'
    return $?
}

IsNo()
{
    [ -n "$1" ] && IStartsWith 'no' "$1"
}

IsYes()
{
    [ -n "$1" ] && IStartsWith 'yes' "$1"
}

ReplaceAllByRegex()
{

    local _out=''
    local rc=0
    _out=$(awk -v _ere="$2" -v _repl="$3" -v _in="$1" -- 'BEGIN { num = gsub(_ere, _repl, _in); print _in; exit(10 + num); }' 2>/dev/null) || rc=$?

    if [ ${rc} -lt 10 ]; then
        return 1
    fi

    if [ -n "${4:-}" ]; then
        eval "${4#@}=\"\${_out}\""
    fi

    if [ -n "${5:-}" ]; then
        eval "${5#@}=$((${rc}-10))"
    fi

    return 0
}

ParseVersionString()
{
    local _ver="$1"
    shift

    local _cmd=''
    _cmd=$(cat <<'AWK_PROGRAM'
BEGIN {
    n = split(version, a, ".");
    if (n > num)
        n = num;
    for (i = 1; i <= n; ++i)
    {
        printf("${%s:+eval \"${%s#@}='%s'\"};", i, i, a[i]);
    }
    exit;
}
AWK_PROGRAM
)
    local _code=''
    _code="$(awk -v version="${_ver}" -v num="$#" -- "${_cmd}" 2>/dev/null)" || return $?
    eval "${_code}"
    return $?
}

CompareVersions()
{
    local _v1="$1"
    local _v2="$2"

    local _v1_major=''
    local _v1_minor=''
    local _v1_fix=''
    local _v1_build=''
    if ! ParseVersionString "${_v1}" @_v1_major @_v1_minor @_v1_fix @_v1_build; then
        return 1
    fi

    local _v2_major=''
    local _v2_minor=''
    local _v2_fix=''
    local _v2_build=''
    if ! ParseVersionString "${_v2}" @_v2_major @_v2_minor @_v2_fix @_v2_build; then
        return 1
    fi

    test "${_v1_major}" -eq "${_v1_major}" 2>/dev/null || return 1
    test "${_v1_minor}" -eq "${_v1_minor}" 2>/dev/null || return 1
    test "${_v1_fix}"   -eq "${_v1_fix}"   2>/dev/null || return 1
    test "${_v1_build}" -eq "${_v1_build}" 2>/dev/null || return 1

    test "${_v2_major}" -eq "${_v2_major}" 2>/dev/null || return 1
    test "${_v2_minor}" -eq "${_v2_minor}" 2>/dev/null || return 1
    test "${_v2_fix}"   -eq "${_v2_fix}"   2>/dev/null || return 1
    test "${_v2_build}" -eq "${_v2_build}" 2>/dev/null || return 1

    local _res='='

    while :; do
        if [ "${_v1_major}" -ne "${_v2_major}" ]; then
            [ "${_v1_major}" -lt "${_v2_major}" ] && _res='<' || _res='>'
            break
        fi

        if [ "${_v1_minor}" -ne "${_v2_minor}" ]; then
            [ "${_v1_minor}" -lt "${_v2_minor}" ] && _res='<' || _res='>'
            break
        fi

        if [ "${_v1_fix}" -ne "${_v2_fix}" ]; then
            [ "${_v1_fix}" -lt "${_v2_fix}" ] && _res='<' || _res='>'
            break
        fi

        if [ "${_v1_build}" -ne "${_v2_build}" ]; then
            [ "${_v1_build}" -le "${_v2_build}" ] && _res='<' || _res='>'
            break
        fi

        break
    done

    eval "${3#@}=\"\${_res}\""
    return $?
}

DeleteFromList()
{

    local _cmd=''
    _cmd=$(cat <<'AWK_PROGRAM'
function ltrim(s) { sub(/^\s+/, "", s); return s; }
function rtrim(s) { sub(/\s+$/, "", s); return s; }
function trim(s) { return rtrim(ltrim(s)); }
BEGIN {
    re = "\\s*" rmItem "\\s*";
    n = split(lst, a);
    k = 0;
    for (i = 1; i <= n; i++)
    {
        if (a[i] ~ re)
            continue;

        if (k > 0)
            printf("%s ", FS);

        printf("%s", trim(a[i]));
        k++;
    }
    exit;
}
AWK_PROGRAM
)
    local _s=''
    _s="$(awk -v lst="${1}" -v FS="${2}" -v rmItem="${3}" -- "${_cmd}")" || return $?

    eval "${4#@}=\"\${_s}\""
    return $?
}


readonly PACKAGE_TYPE=deb

readonly KESL_USE_KSN="${KESL_USE_KSN:-}"
readonly KESL_ASYNCHRONOUS_RESTART="${KESL_ASYNCHRONOUS_RESTART:-}"
readonly VAR_DIRECTORY='/var/opt/kaspersky/kesl/'
readonly VAR_OPT_KASPERSKY_DIRECTORY='/var/opt/kaspersky/'
readonly PACKAGE_INSTALL_DIRECTORY='/var/opt/kaspersky/kesl/install_12.0.0.6672/'
readonly LAUNCHER_FILEPATH='/opt/kaspersky/kesl/libexec/launcher'
readonly TIMESTAMP="$(date '+%s')"

Main()
{
    if [ "$1" != "configure" ]; then
        exit 0
    fi

    local ksn=''
    if IsYes "${KESL_USE_KSN}"; then
        ksn='--ksn-on'
    elif IsNo "${KESL_USE_KSN}"; then
        ksn='--ksn-off'
    fi

    local async_restart=''
    if IsYes "${KESL_ASYNCHRONOUS_RESTART}"; then
        async_restart='--async-restart'
    fi

    local parsec_caps=''
    if lsmod | fgrep -q 'parsec'; then
        parsec_caps='/usr/sbin/execaps -c 0x20000 -- '
    fi

    chmod a+X "${VAR_OPT_KASPERSKY_DIRECTORY}"
    chmod a+X "${VAR_DIRECTORY}"

    ${parsec_caps} ${PACKAGE_INSTALL_DIRECTORY}/${LAUNCHER_FILEPATH} "--install" "${TIMESTAMP}" "--package-type" "${PACKAGE_TYPE}" "${ksn}" "${async_restart}"
}

Main "$@"
exit 0


Zerion Mini Shell 1.0