NBash

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

20
load_helper epm-install
21
load_helper epm-search
22

23
# for zypper before SUSE/11.0
24
__use_zypper_dry_run()
25
{
26
    a='' zypper install --help 2>&1 | grep -q -- "--dry-run" && echo "--dry-run"
27
}
28

29
__use_yum_assumeno()
30
{
31
    a='' yum --help 2>&1 | grep -q -- "--assumeno"
32
}
33

34

35
__check_yum_result()
36
{
37
    grep -q "^No package" $1 && return 1
38
    grep -q "^Complete!" $1 && return 0
39
    grep -q "Exiting on user [Cc]ommand" $1 && return 0
40
    # dnf issue
41
    grep -q "^Operation aborted." $1 && return 0
42
    # return default result by default
43
    return $2
44
}
45

46
__check_pacman_result()
47
{
48
    grep -q "^error: target not found:" $1 && return 1
49
    grep -q "^Total Installed Size:" $1 && return 0
50
    grep -q "^Total Download Size:" $1 && return 0
51
    # return default result by default
52
    return $2
53
}
54

55

56
_epm_do_simulate()
57
{
58
    local CMD
59
    local RES=0
60
    local filenames="$*"
61

62
    case $PMTYPE in
63
        apt-rpm|apt-dpkg)
64
            CMD="apt-get --simulate install"
65
            ;;
66
        aptitude-dpkg)
67
            CMD="aptitude -s install"
68
            ;;
69
        yum-rpm)
70
            if __use_yum_assumeno ; then
71
                store_output sudocmd yum --assumeno install $filenames
72
                __check_yum_result $RC_STDOUT $?
73
            else
74
                store_output sudocmd yum install $filenames <<EOF
75
n
76
EOF
77
                __check_yum_result $RC_STDOUT $?
78
            fi
79
            RES=$?
80
            clean_store_output
81
            return $RES ;;
82
        dnf-rpm)
83
            store_output sudocmd dnf --assumeno install $filenames
84
            __check_yum_result $RC_STDOUT $?
85
            RES=$?
86
            clean_store_output
87
            return $RES ;;
88
        urpm-rpm)
89
            CMD="urpmi --test --auto"
90
            ;;
91
        eopkg)
92
            CMD="eopkg --dry-run install"
93
            ;;
94
        zypper-rpm)
95
            if ! __use_zypper_dry_run >/dev/null ; then
96
                fatal "zypper is too old: does not support --dry-run"
97
            fi
98
            CMD="zypper --non-interactive install --dry-run"
99
            ;;
100
        emerge)
101
            local res=0
102
            for pkg in $filenames ; do
103
            is_installed $pkg && continue
104
            docmd emerge --pretend $pkg && continue
105
            pkg=1
106
            break
107
            done
108
            return $res ;;
109
        opkg)
110
            docmd --noaction install $filenames
111
            return $res ;;
112
        pacman)
113
            store_output sudocmd pacman -v -S $filenames <<EOF
114
no
115
EOF
116
            __check_pacman_result $RC_STDOUT $?
117
            RES=$?
118
            clean_store_output
119
            return $RES ;;
120
        slackpkg)
121
            #docmd /usr/sbin/slackpkg -batch=on -default_answer=yes download
122
            # just try search every package
123
            # FIXME: epm_search have to return false status code if the package does not found
124
            local pkg res
125
            res=0
126
            for pkg in $filenames ; do
127
                # FIXME: -[0-0] does not work in search!
128
                # FIXME: we need strict search here (not find gst-plugins-base if search for gst-plugins
129
                # TODO: use short?
130
                # use verbose for get package status
131
                #pkg_filenames="$pkg-[0-9]" verbose=--verbose __epm_search_internal | grep -E "(installed|upgrade)" && continue
132
                #pkg_filenames="$pkg" verbose=--verbose __epm_search_internal | grep -E "(installed|upgrade)" && continue
133
                __epm_search_internal "$pkg" | grep -q "^$pkg-[0-9]" && continue
134
                res=1
135
                info "Package '$pkg' does not found in repository."
136
            done
137
            return $res ;;
138
        *)
139
            fatal "Have no suitable simulate command for $PMTYPE"
140
            ;;
141
    esac
142

143
    sudocmd $CMD $filenames
144
}
145

146
epm_simulate()
147
{
148
    [ -z "$pkg_filenames" ] && info "Simulate: Skip empty list" && return 22
149

150
    local filenames="$(echo $pkg_filenames | filter_out_installed_packages)"
151

152
    [ -z "$filenames" ] && info "Simulate: All packages are already installed" && return 0
153

154
    _epm_do_simulate $filenames
155
    local RES=$?
156
    if [ -z "$quiet" ] ; then
157
        if [ "$RES" = 0 ] ; then
158
            info "Simulate result: $filenames package(s) CAN BE installed"
159
        else
160
            info "Simulate result: There are PROBLEMS with install some package(s)"
161
        fi
162
    fi
163
    return $RES
164
}
165

166

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.