epm-repolist 4.22 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016, 2019, 2020, 2021  Etersoft
# Copyright (C) 2012, 2016, 2019, 2020, 2021  Vitaly Lipatov <lav@etersoft.ru>
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
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.
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/>.
18 19
#

20 21
load_helper epm-sh-altlinux

22
__print_apt_sources_list()
23
{
24
    local i
25 26
    for i in $@ ; do
        test -r "$i" || continue
27
        grep -v -- "^.*#" $i
28
    done | grep -v -- "^ *\$"
29 30
}

31 32 33 34 35 36 37 38 39 40
__print_apt_sources_list_full()
{
    local i
    for i in $@ ; do
        test -r "$i" || continue
        grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i
    done | grep -v -- "^ *\$"
}

# TODO: remove
41 42 43 44 45 46 47 48 49 50 51
__print_apt_sources_list_list()
{
    local i
    for i in $@ ; do
        test -r "$i" || continue
        grep -v -- "^.*#" $i | grep -v -- "^ *\$" | grep -q . && echo "$i"
    done
}

__info_cyan()
{
52 53 54
        set_boldcolor $CYAN
        echo "$*" >&2
        restore_color
55 56 57 58 59 60 61 62 63 64 65 66
}

__print_apt_sources_list_verbose()
{
    local i
    for i in $@ ; do
        test -r "$i" || continue
        grep -v -- "^.*#" $i | grep -v -- "^ *\$" | grep -q . && __info_cyan "$i:" || continue
        grep -v -- "^.*#" $i | grep -v -- "^ *\$" | sed -e 's|^|    |'
    done
}

67 68 69 70 71 72 73 74 75 76
__print_apt_sources_list_verbose_full()
{
    local i
    for i in $@ ; do
        test -r "$i" || continue
        grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i | grep -v -- "^ *\$" | grep -q . && echo && __info_cyan "$i:" || continue
        grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i | grep -v -- "^ *\$" | sed -e 's|^|    |' -e "s|\(.*#.*\)|$(set_color $WHITE)\1$(restore_color)|"
    done
}

77 78 79
print_apt_sources_list()
{
    local LISTS='/etc/apt/sources.list /etc/apt/sources.list.d/*.list'
80 81 82 83 84 85 86 87 88 89

    if [ "$1" = "-a" ] || [ "$1" = "--all" ] ; then
        if [ -n "$quiet" ] ; then
            __print_apt_sources_list_full $LISTS
        else
            __print_apt_sources_list_verbose_full $LISTS
        fi
        return
    fi

90 91 92
    if [ -n "$quiet" ] ; then
        __print_apt_sources_list $LISTS
    else
93
        __print_apt_sources_list_verbose $LISTS
94
    fi
95 96 97
}


98 99
epm_repolist()
{
100

101 102
# TODO
[ -z "$*" ] || [ "$PMTYPE" = "apt-rpm" ] || [ "$PMTYPE" = "apt-dpkg" ]  || fatal "No arguments are allowed here"
103

104
case $PMTYPE in
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    apt-rpm)
        #assure_exists apt-repo
        if tasknumber "$1" >/dev/null ; then
            get_task_packages "$@"
        else
            print_apt_sources_list "$@"
            #docmd apt-repo list
        fi
        ;;
    deepsolver-rpm)
        docmd ds-conf
        ;;
    apt-dpkg|aptitude-dpkg)
        print_apt_sources_list "$@"
        ;;
    yum-rpm)
        docmd yum repolist $verbose
        [ -n "$verbose" ] || info "Use --verbose if you need detail information."
        ;;
    dnf-rpm)
        docmd dnf repolist $verbose
        [ -n "$verbose" ] || info "Use --verbose if you need detail information."
        ;;
    urpm-rpm)
        docmd urpmq --list-media active --list-url
        ;;
131 132 133
    apk)
        cat /etc/apk/repositories
        ;;
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    zypper-rpm)
        docmd zypper sl -d
        ;;
    packagekit)
        docmd pkcon repo-list
        ;;
    emerge)
        docmd eselect profile list
        docmd layman -L
        ;;
    xbps)
        docmd xbps-query -L
        ;;
    winget)
        docmd winget source list
        ;;
    eoget)
        docmd eoget list-repo
        ;;
    pacman)
154 155 156 157 158
        if [ -f /etc/pacman.d/mirrorlist ] ; then
            docmd grep -v -- "^#\|^$" /etc/pacman.d/mirrorlist | grep "^Server =" | sed -e 's|^Server = ||'
        else
            docmd grep -v -- "^#\|^$" /etc/pacman.conf
        fi
159 160 161 162 163
        ;;
    slackpkg)
        docmd grep -v -- "^#\|^$" /etc/slackpkg/mirrors
        ;;
    *)
164
        fatal 'Have no suitable command for $PMTYPE'
165
        ;;
166 167 168
esac

}