epm-removerepo 5.53 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2017, 2020, 2021  Etersoft
# Copyright (C) 2012, 2017, 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 23 24 25 26 27 28 29 30 31 32 33 34

# like apt-add-repository --remove on deb systems
__epm_removerepo_apt()
{
    [ -n "$*" ] || fatal "empty repo name"
    # aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for AstraLinuxCE/orel
    sudocmd sed -i -e "s|.*$*.*||" /etc/apt/sources.list
    if [ -d /etc/apt/sources.list.d ] && ls /etc/apt/sources.list.d/*.list >/dev/null 2>/dev/null ; then
        sudocmd sed -i -e "s|.*$*.*||" /etc/apt/sources.list.d/*.list
    fi
}


35 36 37 38 39 40 41 42
__epm_grep_repo_list()
{
    while [ -n "$1" ] ; do
        epm --quiet repolist | grep -E "$1"
        shift
    done
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
43 44 45
# remove grepped lines
__epm_removerepo_alt_grepremove()
{
46 47 48 49 50
    local rl
    # ^rpm means full string
    if [ "$1" = "all" ] || rhas "$1" "^rpm" ; then
        rl="$1"
    else
51 52
        rl="$(__epm_grep_repo_list "$@" 2>/dev/null)"
        [ -z "$rl" ] && warning 'Can'\''t find '$*' in the repos (see # epm repolist output)' && return 1
53 54 55 56 57 58 59 60 61 62 63 64 65
    fi
    echo "$rl" | while read rp ; do
        # TODO: print removed lines
        if [ -n "$dryrun" ] ; then
            docmd apt-repo $dryrun rm "$rp"
            continue
        fi
        if [ -z "$quiet" ] ; then
            sudocmd apt-repo $dryrun rm "$rp"
        else
            sudorun apt-repo $dryrun rm "$rp"
        fi
    done
Vitaly Lipatov's avatar
Vitaly Lipatov committed
66 67 68 69
}

__epm_removerepo_alt()
{
70 71
    local repo="$*"
    [ -n "$repo" ] || fatal "No such repo or task. Use epm repo remove <regexp|autoimports|archive|tasks|TASKNUMBER>"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
72

73
    assure_exists apt-repo
Vitaly Lipatov's avatar
Vitaly Lipatov committed
74

75 76 77
    if tasknumber "$repo" >/dev/null ; then
        local tn
        for tn in $(tasknumber "$repo") ; do
78
            __epm_removerepo_alt_grepremove " repo/$tn/" "/tasks/$tn " "/$tn[ /]build/repo"
79 80 81
        done
        return
    fi
Vitaly Lipatov's avatar
Vitaly Lipatov committed
82

83
    local branch="$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
84

85 86 87 88 89 90 91 92 93 94 95
    case "$1" in
        autoimports)
            info "remove autoimports repo"
            [ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
            repo="autoimports.$branch"
            sudocmd apt-repo $dryrun rm "$repo"
            ;;
        archive)
            info "remove archive repos"
            __epm_removerepo_alt_grepremove "archive/"
            ;;
96 97 98 99
        korinf)
            info "remove korinf repo"
            __epm_removerepo_alt_grepremove "Korinf/"
            ;;
100 101
        tasks)
            info "remove task repos"
102
            __epm_removerepo_alt_grepremove " repo/[0-9]+/" "/tasks/[0-9]+ " "/[0-9]+[ /]build/repo"
103 104 105
            ;;
        task)
            shift
106
            __epm_removerepo_alt_grepremove " repo/$1/" "/tasks/$1 " "/$1[ /]build/repo"
107 108 109 110 111
            ;;
        -*)
            fatal "epm removerepo: no options are supported"
            ;;
        *)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
112
# TODO: if return empty for whole line, use grep
113 114 115 116
#            sudocmd apt-repo $dryrun rm "$*"
            __epm_removerepo_alt_grepremove "$*"
            ;;
    esac
Vitaly Lipatov's avatar
Vitaly Lipatov committed
117 118 119

}

120 121
epm_removerepo()
{
122

123
case $BASEDISTRNAME in
124 125 126 127 128 129 130
    "alt")
        __epm_removerepo_alt "$@"
        return
        ;;
    "astra")
        echo "Use workaround for AstraLinux"
        # aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for AstraLinuxCE/orel
131
        __epm_removerepo_apt "$@"
132 133
        return
        ;;
134 135 136
esac;

case $PMTYPE in
137 138 139 140 141 142 143 144 145 146 147 148 149
    apt-dpkg)
        assure_exists apt-add-repository software-properties-common
        # FIXME: it is possible there is troubles to pass the args
        sudocmd apt-add-repository --remove "$*"
        info "Check file /etc/apt/sources.list if needed"
        ;;
    aptitude-dpkg)
        info "You need remove repo from /etc/apt/sources.list"
        ;;
    yum-rpm)
        assure_exists yum-utils
        sudocmd yum-config-manager --disable "$@"
        ;;
150 151 152 153
    dnf-rpm)
        repo_file_name=$(env LC_ALL=C dnf repoinfo "$@" 2>/dev/null | sed -n 's/^Repo-filename\s*:\s*//p')
        sudocmd rm "$repo_file_name"
        ;;
154 155 156 157
    dnf5-rpm)
        repo_file_name=$(env LC_ALL=C dnf repoinfo "$@" 2>/dev/null | sed -n 's/^Config file\s*:\s*//p')
        sudocmd rm "$repo_file_name"
        ;;
158 159 160 161 162 163 164 165 166 167 168
    urpm-rpm)
        if [ "$1" = "all" ] ; then
            sudocmd urpmi.removemedia -av
            return
        fi
        sudocmd urpmi.removemedia "$@"
        ;;
    zypper-rpm)
        sudocmd zypper removerepo "$@"
        ;;
    emerge)
169
        sudocmd layman "-d$1"
170 171 172 173 174 175 176 177 178 179 180 181 182
        ;;
    pacman)
        info "You need remove repo from /etc/pacman.conf"
        ;;
    npackd)
        sudocmd npackdcl remove-repo --url="$*"
        ;;
    winget)
        sudocmd winget source remove "$@"
        ;;
    eopkg)
        sudocmd eopkg remove-repo "$@"
        ;;
183 184 185
    pisi)
        sudocmd pisi remove-repo "$@"
        ;;
186 187 188 189
    slackpkg)
        info "You need remove repo from /etc/slackpkg/mirrors"
        ;;
    *)
190
        fatal 'Have no suitable command for $PMTYPE'
191
        ;;
192 193 194
esac

}