epm-sh-install 5.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/bin/sh
#
# Copyright (C) 2012-2020  Etersoft
# Copyright (C) 2012-2020  Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

load_helper epm-sh-altlinux
load_helper epm-query

__fast_hack_for_filter_out_installed_rpm()
{
25
    LC_ALL=C xargs -n1 rpm -q 2>&1 | grep 'is not installed' |
26
        sed -e 's|^.*package \(.*\) is not installed.*|\1|g'
27 28 29 30 31
}

# pass only uninstalled packages
filter_out_installed_packages()
{
32
    [ -z "$skip_installed" ] && cat && return
33

34 35
    case $PMTYPE in
        yum-rpm|dnf-rpm)
36
            if [ "$DISTRARCH" = "x86_64" ] && [ "$DISTRNAME" != "ROSA" ] ; then
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
                # shellcheck disable=SC2013
                for i in $(cat) ; do
                    is_installed "$(__print_with_arch_suffix $i .x86_64)" && continue
                    is_installed "$(__print_with_arch_suffix $i .noarch)" && continue
                    echo $i
                done
            else
                __fast_hack_for_filter_out_installed_rpm
            fi
            ;;
        *-rpm)
            __fast_hack_for_filter_out_installed_rpm
            ;;
        # dpkg -l lists some non ii status (un, etc)
        #"deb")
        #    LANG=C LC_ALL=C xargs -n1 dpkg -l 2>&1 | grep -i 'no packages found matching' |
        #        sed -e 's|\.\+$||g' -e 's|^.*[Nn]o packages found matching \(.*\)|\1|g'
        #    ;;
        *)
            # shellcheck disable=SC2013
            for i in $(cat) ; do
                is_installed $i || echo $i
            done
            ;;
    esac | sed -e "s|rpm-build-altlinux-compat[^ ]*||g" | filter_strip_spaces
62 63 64 65 66 67 68 69
}

get_only_installed_packages()
{
    local installlist="$*"
    estrlist exclude "$(echo "$installlist" | (skip_installed='yes' filter_out_installed_packages))" "$installlist"
}

70

71 72
__epm_print_warning_for_nonalt_packages()
{
73
    [ -n "$dryrun" ] && return 0
74 75 76
    # only ALT
    [ "$BASEDISTRNAME" = "alt" ] || return 0

77 78 79
    # download only
    [ -n "$save_only$download_only" ] && return 0

80 81
    load_helper epm-status

82 83
    local i
    for i in $* ; do
84
        if epm_status_repacked "$i" ; then
85
            warning '%%% You are trying install package $i repacked from third-party software source. Use it at your own risk. %%%'
86 87
            continue
        fi
88

89
        if epm_status_thirdparty "$i" ; then
90
            warning '%%% You are trying install package $i from third-party software source. Use it at your own risk. %%%'
91 92 93 94
            continue
        fi

        if ! epm_status_original "$i" ; then
95
            warning '%%% You are trying install package $i not from official $DISTRNAME/$DISTRVERSION repository. Use it at your own risk. %%%'
96 97
            continue
        fi
98 99 100
    done
}

101 102 103 104 105
# Args: package names. Set noscripts for outside packages.
__epm_check_vendor()
{
    # don't check vendor if there are forced script options
    [ -n "$scripts$noscripts" ] && return
106
    [ -n "$dryrun" ] && return 0
107

108
    # only ALT
109
    [ "$BASEDISTRNAME" = "alt" ] || return 0
110

111 112
    load_helper epm-status

113 114
    local i
    for i in $* ; do
115
        bi="$(basename $i)"
116
        if ! epm_status_validate "$i" ; then
117
            # it is missed package probably (package remove case)
118
            if is_installed "$i" ; then
119
                warning 'Can'\''t get any info for $i package. Scripts are DISABLED for package $bi. Use --scripts if you need run scripts from such packages.'
120
                noscripts="--noscripts"
121
            fi
122
            # don't set --noscripts for non existent packages (will run scripts when remove by provides, see https://github.com/Etersoft/eepm/issues/236)
123 124 125
            continue
        fi

126
        local vendor
127
        vendor="$(epm print field Vendor for "$i")"
128

129
        if [ -z "$vendor" ] ; then
130
            warning 'Can'\''t get info about vendor for $i package. Scripts are DISABLED for package $bi. Use --scripts if you need run scripts from such packages.'
131 132 133
            noscripts="--noscripts"
            continue
        fi
134

135
        epm_status_original "$i" && continue
136
        epm_status_repacked "$i" && continue
137 138

        if __epm_vendor_ok_scripts "$vendor" ; then
139
            warning 'Scripts are ENABLED for package $bi from outside vendor $vendor (this vendor is listed in $CONFIGDIR/vendorallowscripts.list).  Use --noscripts if you need disable scripts in such packages.'
140 141 142
            continue
        fi

143
        if __epm_package_ok_scripts "$i" ; then
144
            warning 'Scripts are ENABLED for package $bi from outside vendor $vendor (the package is listed in $CONFIGDIR/pkgallowscripts.list).  Use --noscripts if you need disable scripts in such packages.'
145 146
            continue
        fi
147
        warning 'Scripts are DISABLED for package $bi from outside vendor $vendor. Use --scripts if you need run scripts from such packages.'
148 149 150
        noscripts="--noscripts"
    done
}
151