NBash

Форк
0
225 строк · 6.2 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012-2013, 2016, 2018, 2019, 2022  Etersoft
4
# Copyright (C) 2012-2013, 2016, 2018, 2019, 2022  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-query
21
load_helper epm-print
22

23
__epm_filter_out_base_alt_reqs()
24
{
25
    grep -E -v "(^rpmlib\(|^/bin/sh|^/bin/bash|^rtld\(GNU_HASH\)|ld-linux)"
26
}
27

28
__epm_alt_rpm_requires()
29
{
30
    if [ -n "$short" ] ; then
31
        # TODO see also rpmreqs from etersoft-build-utils
32
        docmd rpm -q --requires "$@" | __epm_filter_out_base_alt_reqs | sed -e "s| .*||"
33
    else
34
        docmd rpm -q --requires "$@" | __epm_filter_out_base_alt_reqs
35
    fi
36
}
37

38
get_linked_shared_libs()
39
{
40
    assure_exists readelf binutils
41
    #is_command readelf || fatal "Can't get required shared library: readelf is missed. Try install binutils package."
42
    #ldd "$exe" | sed -e 's|[[:space:]]*||' | grep "^lib.*[[:space:]]=>[[:space:]]\(/usr/lib\|/lib\)" | sed -e 's|[[:space:]].*||'
43
    LC_ALL=C readelf -d "$1" | grep "(NEEDED)" | grep "Shared library:" | sed -e 's|.*Shared library: \[||' -e 's|\]$||' | grep "^lib"
44
}
45

46
__epm_elf32_requires()
47
{
48
    get_linked_shared_libs "$1"
49
}
50

51
__epm_elf64_requires()
52
{
53
    get_linked_shared_libs "$1" | sed -e 's|$|()(64bit)|'
54
}
55

56
__epm_elf_requires()
57
{
58
    local i
59
    if [ -n "$direct" ] ; then
60
        for i in $* ; do
61
            get_linked_shared_libs $i
62
        done
63
        return
64
    fi
65

66
    for i in $* ; do
67
        if file "$i" | grep -q " ELF 32-bit " ; then
68
            __epm_elf32_requires "$i"
69
        elif file "$i" | grep -q " ELF 64-bit " ; then
70
            __epm_elf64_requires "$i"
71
        else
72
            warning "Unknown ELF binary"
73
        fi
74
    done
75
}
76

77
epm_requires_files()
78
{
79
    local pkg_files="$*"
80
    [ -n "$pkg_files" ] || return
81

82
    # TODO: handle separately
83
    local PKGTYPE="$(get_package_type $pkg_files)"
84

85
    case "$PKGTYPE" in
86
        rpm)
87
            assure_exists rpm >/dev/null
88
            __epm_alt_rpm_requires -p $pkg_files
89
            ;;
90
        deb)
91
            assure_exists dpkg >/dev/null
92
            a='' docmd dpkg -I $pkg_files | grep "^ *Depends:" | sed "s|^ *Depends:||g"
93
            ;;
94
        eopkg)
95
            showcmd eopkg info $pkg_files
96
            LC_ALL=C eopkg info $pkg_files | grep "^Dependencies" | head -n1 | sed -e "s|Dependencies[[:space:]]*: ||"
97
            ;;
98
        ELF)
99
            __epm_elf_requires $pkg_files
100
            ;;
101
        *)
102
            fatal "Have no suitable command for $PKGTYPE"
103
            ;;
104
    esac
105
}
106

107
epm_requires_names()
108
{
109
    local pkg_names="$*"
110
    local CMD
111
    [ -n "$pkg_names" ] || return
112

113
# by package name
114
case $PMTYPE in
115
    apt-rpm)
116
        # FIXME: need fix for a few names case
117
        # FIXME: too low level of requires name (libSOME.so)
118
        if is_installed $pkg_names ; then
119
            assure_exists rpm >/dev/null
120
            __epm_alt_rpm_requires $pkg_names
121
            return
122
        else
123
            if [ -n "$verbose" ] ; then
124
                CMD="apt-cache depends"
125
            else
126
                if [ -n "$short" ] ; then
127
                    LC_ALL=C docmd apt-cache depends $pkg_names | grep "Depends:" | sed -e 's|, |\n|g' -e "s|.*Depends: ||" -e "s|<\(.*\)>|\1|" | __epm_filter_out_base_alt_reqs | sed -e "s| .*||"
128
                else
129
                    LC_ALL=C docmd apt-cache depends $pkg_names | grep "Depends:" | sed -e 's|, |\n|g' -e "s|.*Depends: ||" -e "s|<\(.*\)>|\1|" | __epm_filter_out_base_alt_reqs
130
                fi
131
                return
132
            fi
133
        fi
134
        ;;
135
    packagekit)
136
        CMD="pkcon required-by"
137
        ;;
138
    #zypper-rpm)
139
    #    # FIXME: use hi level commands
140
    #    CMD="rpm -q --requires"
141
    #    ;;
142
    urpm-rpm)
143
        CMD="urpmq --requires"
144
        ;;
145
    yum-rpm)
146
        if is_installed $pkg_names ; then
147
            CMD="rpm -q --requires"
148
        else
149
            CMD="yum deplist"
150
        fi
151
        ;;
152
    dnf-rpm)
153
        if is_installed $pkg_names ; then
154
            CMD="rpm -q --requires"
155
        else
156
            CMD="dnf repoquery --requires"
157
        fi
158
        ;;
159
    pacman)
160
        CMD="pactree"
161
        ;;
162
    apt-dpkg|aptitude-dpkg)
163
        # FIXME: need fix for a few names case
164
        if is_installed $pkg_names ; then
165
            showcmd dpkg -s $pkg_names
166
            a='' dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
167
            return
168
        else
169
            CMD="apt-cache depends"
170
        fi
171
        ;;
172
    emerge)
173
        assure_exists equery
174
        CMD="equery depgraph"
175
        ;;
176
    homebrew)
177
        #docmd brew info $pkg_names | grep "^Required: " | sed -s "|s|^Requires: ||"
178
        docmd brew deps $pkg_names
179
        return
180
        ;;
181
    pkgng)
182
        #CMD="pkg rquery '%dn-%dv'"
183
        CMD="pkg info -d"
184
        ;;
185
    opkg)
186
        CMD="opkg depends"
187
        ;;
188
    eopkg)
189
        showcmd eopkg info $pkg_names
190
        LC_ALL=C eopkg info $pkg_names | grep "^Dependencies" | sed -e "s|Dependencies[[:space:]]*: ||"
191
        return
192
        ;;
193
    xbps)
194
        CMD="xbps-query -x"
195
        ;;
196
    aptcyg)
197
        #CMD="apt-cyg depends"
198
        # print show version
199
        docmd apt-cyg show $pkg_names | grep "^requires: " | sed "s|^requires: ||g"
200
        return
201
        ;;
202
    *)
203
        fatal "Have no suitable command for $PMTYPE"
204
        ;;
205
esac
206

207

208
docmd $CMD $pkg_names
209

210
}
211

212
epm_requires()
213
{
214
    # if possible, it will put pkg_urls into pkg_files or pkg_names
215
    if [ -n "$pkg_urls" ] ; then
216
        load_helper epm-download
217
        __handle_pkg_urls_to_checking
218
    fi
219

220
    [ -n "$pkg_filenames" ] || fatal "Requires: package name is missed"
221

222
    epm_requires_files $pkg_files
223
    # shellcheck disable=SC2046
224
    epm_requires_names $(print_name $pkg_names)
225
}
226

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

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

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

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