NBash

Форк
0
205 строк · 5.4 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012, 2016, 2017, 2020  Etersoft
4
# Copyright (C) 2012, 2016, 2017, 2020  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-sh-warmup
21

22
__epm_packages_sort()
23
{
24
# FIXME: sort depends on --sort value
25
case $PMTYPE in
26
    *-rpm)
27
        # FIXME: space with quotes problems, use point instead
28
        warmup_rpmbase
29
        docmd rpm -qa --queryformat "%{size}@%{name}-%{version}-%{release}\n" "$@" | sed -e "s|@| |g" | sort -n -k1
30
        ;;
31
    *-dpkg)
32
        warmup_dpkgbase
33
        docmd dpkg-query -W --showformat="\${Installed-Size}@\${Package}-\${Version}:\${Architecture}\n" "$@" | sed -e "s|@| |g" | sort -n -k1
34
        ;;
35
    *)
36
        fatal "Sorted package list function is not implemented for $PMTYPE"
37
        ;;
38
esac
39
}
40

41
__aptcyg_print_full()
42
{
43
    #showcmd apt-cyg show
44
    local VERSION=$(apt-cyg show "$1" | grep -m1 "^version: " | sed -e "s|^version: ||g")
45
    echo "$1-$VERSION"
46
}
47

48
__fo_pfn()
49
{
50
    grep -v "^$" | grep -- "$*"
51
}
52

53
# TODO: we have a problem with error status here
54
epm_packages()
55
{
56
    local CMD
57
    [ -n "$sort" ] && __epm_packages_sort "$@" && return
58

59
case $PMTYPE in
60
    *-dpkg)
61
        warmup_dpkgbase
62
        # FIXME: strong equal
63
        #CMD="dpkg -l $pkg_filenames"
64
        CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}-\${Version}:\${Architecture}\n"
65
        # TODO: ${Architecture}
66
        [ -n "$short" ] && CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}\n"
67
        showcmd $CMD "$@"
68
        $CMD "$@" | grep "^i" | sed -e "s|.* ||g" | __fo_pfn "$@"
69
        return ;;
70
    *-rpm)
71
        warmup_rpmbase
72
        # FIXME: strong equal
73
        CMD="rpm -qa"
74
        [ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n"
75
        docmd $CMD "$@" | __fo_pfn "$@"
76
        return ;;
77
    packagekit)
78
        docmd pkcon get-packages --filter installed
79
        ;;
80
    snappy)
81
        CMD="snappy info"
82
        ;;
83
    snap)
84
        CMD="snap list"
85
        ;;
86
    flatpak)
87
        CMD="flatpak list --app"
88
        ;;
89
    emerge)
90
        CMD="qlist -I -C"
91
        # print with colors for console output
92
        isatty && CMD="qlist -I"
93
        ;;
94
    pkgsrc)
95
        CMD="pkg_info"
96
        showcmd $CMD
97
        $CMD | sed -e "s| .*||g" | __fo_pfn "$@"
98
        return ;;
99
    pkgng)
100
        if [ -n "$@" ] ; then
101
            CMD="pkg info -E $@"
102
        else
103
            CMD="pkg info"
104
        fi
105
        showcmd $CMD
106
        if [ -n "$short" ] ; then
107
            $CMD | sed -e "s| .*||g" | sed -e "s|-[0-9].*||g" | __fo_pfn "$@"
108
        else
109
            $CMD | sed -e "s| .*||g" | __fo_pfn "$@"
110
        fi
111
        return ;;
112
    pacman)
113
        CMD="pacman -Qs $@"
114
        showcmd $CMD
115
        if [ -n "$short" ] ; then
116
            $CMD | sed -e "s| .*||g" -e "s|.*/||g" | __fo_pfn "$@"
117
            return
118
        fi
119
        ;;
120
    npackd)
121
        CMD="npackdcl list --status=installed"
122
        # TODO: use search if pkg_filenames is not empty
123
        ;;
124
    conary)
125
        CMD="conary query"
126
        ;;
127
    eopkg)
128
        CMD="eopkg list-installed"
129
        ;;
130
    choco)
131
        CMD="choco list"
132
        ;;
133
    slackpkg)
134
        CMD="ls -1 /var/log/packages/"
135
        if [ -n "$short" ] ; then
136
            # FIXME: does not work for libjpeg-v8a
137
            # TODO: remove last 3 elements (if arch is second from the last?)
138
            # FIXME this hack
139
            docmd ls -1 /var/log/packages/ | sed -e "s|-[0-9].*||g" | sed -e "s|libjpeg-v8a.*|libjpeg|g" | __fo_pfn "$@"
140
            return
141
        fi
142
        ;;
143
    homebrew)
144
        docmd brew list | xargs -n1 echo
145
        ;;
146
    opkg)
147
        CMD="opkg list-installed"
148
        ;;
149
    apk)
150
        CMD="apk list --installed"
151
        ;;
152
    nix)
153
        CMD="nix-env -q"
154
        ;;
155
    tce)
156
        CMD="ls -1 /usr/local/tce.installed"
157
        ;;
158
    guix)
159
        CMD="guix package -I"
160
        ;;
161
    appget)
162
        CMD="appget list"
163
        ;;
164
    winget)
165
        CMD="winget list"
166
        ;;
167
    termux-pkg)
168
        docmd pkg list-installed
169
        ;;
170
    xbps)
171
        CMD="xbps-query -l"
172
        showcmd $CMD
173
        if [ -n "$short" ] ; then
174
            $CMD | sed -e "s|^ii ||g" -e "s| .*||g" -e "s|\(.*\)-.*|\1|g" | __fo_pfn "$@"
175
        else
176
            $CMD | sed -e "s|^ii ||g" -e "s| .*||g" | __fo_pfn "$@"
177
        fi
178
        return 0
179
        ;;
180
    android)
181
        CMD="pm list packages"
182
        showcmd $CMD
183
        $CMD | sed -e "s|^package:||g" | __fo_pfn "$@"
184
        return
185
        ;;
186
    aptcyg)
187
        CMD="apt-cyg list $@"
188
        if [ -z "$short" ] ; then
189
            showcmd $CMD
190
            # TODO: fix this slow way
191
            for i in $($CMD) ; do
192
                __aptcyg_print_full $i
193
            done
194
            return
195
        fi
196
        ;;
197
    *)
198
        fatal "Have no suitable query command for $PMTYPE"
199
        ;;
200
esac
201

202
docmd $CMD | __fo_pfn "$@"
203
# FIXME: we print empty lines, but will lost error status
204

205
}
206

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

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

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

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