NBash

Форк
0
189 строк · 4.5 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2009, 2012, 2016  Etersoft
4
# Copyright (C) 2009, 2012, 2016  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
# copied from etersoft-build-utils/bin/rpmqf
21

22
# TODO: check for lib64/name situations
23
__abs_filename()
24
{
25
    if echo "$1" | grep -q "/" ; then
26
        echo "$1"
27
        return
28
    fi
29
    if [ -e "$1" ] ; then
30
        echo "$(pwd)/$1"
31
        return
32
    fi
33
    echo "$1"
34
}
35

36
__do_query_real_file()
37
{
38
    local TOFILE
39
    
40
    # get canonical path
41
    if [ -e "$1" ] ; then
42
        TOFILE="$(__abs_filename "$1")"
43
    else
44
        TOFILE=$(print_command_path "$1" || echo "$1")
45
        if [ "$TOFILE" != "$1" ] ; then
46
            info " > $1 is placed as $TOFILE"
47
        fi
48
    fi
49

50
    [ -n "$TOFILE" ] || return
51

52
    local RES
53
    if [ -n "$short" ] ; then
54
        __do_short_query "$TOFILE"
55
        RES=$?
56
    else
57
        __do_query "$TOFILE"
58
        RES=$?
59
    fi
60

61
    # get value of symbolic link
62
    if [ -L "$TOFILE" ] ; then
63
        local LINKTO
64
        LINKTO=$(readlink -- "$TOFILE")
65
        info " > $TOFILE is link to $LINKTO"
66
        LINKTO=$(readlink -f -- "$TOFILE")
67
        __do_query_real_file "$LINKTO"
68
        return
69
    else
70
        return $RES
71
    fi
72
}
73

74
dpkg_print_name_version()
75
{
76
    local ver i
77
    for i in "$@" ; do
78
        [ -n "$i" ] || continue
79
        ver=$(dpkg -s "$i" 2>/dev/null | grep "Version:" | sed -e "s|Version: ||g")
80
        if [ -z "$ver" ] ; then
81
            echo "$i"
82
        else
83
            echo "$i-$ver"
84
        fi
85
    done
86
}
87

88

89
__do_query()
90
{
91
    local CMD
92
    case $PMTYPE in
93
        *-dpkg)
94
            showcmd dpkg -S "$1"
95
            dpkg_print_name_version "$(dpkg -S "$1" | grep -v "^diversion by" | sed -e "s|:.*||")"
96
            return ;;
97
        *-rpm)
98
            CMD="rpm -qf"
99
            ;;
100
        emerge)
101
            assure_exists equery
102
            CMD="equery belongs"
103
            ;;
104
        pacman)
105
            CMD="pacman -Qo"
106
            ;;
107
        pkgng)
108
            CMD="pkg which"
109
            ;;
110
        conary)
111
            CMD="conary query --path"
112
            ;;
113
        slackpkg)
114
            # note: need remove leading slash for grep
115
            docmd grep -R -- "$(echo $@ | sed -e 's|^/\+||g')" /var/log/packages | sed -e "s|/var/log/packages/||g"
116
            return
117
            ;;
118
        opkg)
119
            CMD="opkg search"
120
            ;;
121
        eopkg)
122
            CMD="eopkg search-file"
123
            ;;
124
        xbps)
125
            # FIXME: maybe it is search file?
126
            CMD="xbps-query -o"
127
            ;;
128
        aptcyg)
129
            #CMD="apt-cyg packageof"
130
            # is not implemented locally
131
            return 1
132
            ;;
133
        *)
134
            fatal "Have no suitable query command for $PMTYPE"
135
            ;;
136
    esac
137

138
    docmd $CMD $@
139
}
140

141

142
__do_short_query()
143
{
144
    local CMD
145
    case $PMTYPE in
146
        *-rpm)
147
            CMD="rpm -qf --queryformat %{NAME}\n"
148
            ;;
149
        apt-dpkg)
150
            docmd dpkg -S "$1" | sed -e "s|:.*||"
151
            return ;;
152
        NOemerge)
153
            assure_exists equery
154
            CMD="equery belongs"
155
            ;;
156
        NOpacman)
157
            CMD="pacman -Qo"
158
            ;;
159
        NOslackpkg)
160
            # note: need remove leading slash for grep
161
            docmd grep -R "$(echo $@ | sed -e 's|^/\+||g')" /var/log/packages | sed -e "s|/var/log/packages/||g"
162
            return
163
            ;;
164
        *)
165
            fatal "Have no suitable query command for $PMTYPE"
166
            ;;
167
    esac
168

169
    docmd $CMD $@
170
}
171

172

173
epm_query_file()
174
{
175
    # file can exists or not
176
    [ -n "$pkg_filenames" ] || fatal "Run query without file names"
177

178

179
    #load_helper epm-search_file
180

181
    res=0
182
    for pkg in $pkg_filenames ; do
183
        __do_query_real_file "$pkg" || res=$?
184
    done
185

186
    [ "$res" = "0" ] || info "Try epm sf for search file in all packages of the repositories"
187
    #|| pkg_filenames="$FULLFILEPATH" epm_search_file
188
    return $res
189
}
190

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

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

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

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