epm-packages 5.42 KB
Newer Older
Danil Mikhailov's avatar
Danil Mikhailov committed
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016, 2017, 2020  Etersoft
# Copyright (C) 2012, 2016, 2017, 2020  Vitaly Lipatov <lav@etersoft.ru>
Danil Mikhailov's avatar
Danil Mikhailov committed
5
#
6 7 8
# 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
Danil Mikhailov's avatar
Danil Mikhailov committed
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
Danil Mikhailov's avatar
Danil Mikhailov committed
15
#
16 17
# 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/>.
Danil Mikhailov's avatar
Danil Mikhailov committed
18 19
#

20 21
load_helper epm-sh-warmup

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

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

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

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

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

202
docmd $CMD | __fo_pfn "$@"
203
# FIXME: we print empty lines, but will lost error status
Danil Mikhailov's avatar
Danil Mikhailov committed
204 205

}