NBash

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

22
# remove grepped lines
23
__epm_removerepo_alt_grepremove()
24
{
25
    local rl
26
    # ^rpm means full string
27
    if [ "$1" = "all" ] || rhas "$1" "^rpm" ; then
28
        rl="$1"
29
    else
30
        rl="$( epm --quiet repolist 2>/dev/null | grep -F "$1")"
31
        [ -z "$rl" ] && warning "Can't find '$1' in the repos (see '# epm repolist' output)" && return 1
32
    fi
33
    echo "$rl" | while read rp ; do
34
        # TODO: print removed lines
35
        if [ -n "$dryrun" ] ; then
36
            docmd apt-repo $dryrun rm "$rp"
37
            continue
38
        fi
39
        if [ -z "$quiet" ] ; then
40
            sudocmd apt-repo $dryrun rm "$rp"
41
        else
42
            sudorun apt-repo $dryrun rm "$rp"
43
        fi
44
    done
45
}
46

47
__epm_removerepo_alt()
48
{
49
    local repo="$*"
50
    [ -n "$repo" ] || fatal "No such repo or task. Use epm repo remove <regexp|autoimports|archive|tasks|TASKNUMBER>"
51

52
    assure_exists apt-repo
53

54
    if tasknumber "$repo" >/dev/null ; then
55
        local tn
56
        for tn in $(tasknumber "$repo") ; do
57
            __epm_removerepo_alt_grepremove " repo/$tn/"
58
        done
59
        return
60
    fi
61

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

64
    case "$1" in
65
        autoimports)
66
            info "remove autoimports repo"
67
            [ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
68
            repo="autoimports.$branch"
69
            sudocmd apt-repo $dryrun rm "$repo"
70
            ;;
71
        archive)
72
            info "remove archive repos"
73
            __epm_removerepo_alt_grepremove "archive/"
74
            ;;
75
        korinf)
76
            info "remove korinf repo"
77
            __epm_removerepo_alt_grepremove "Korinf/"
78
            ;;
79
        tasks)
80
            info "remove task repos"
81
            __epm_removerepo_alt_grepremove " repo/[0-9]+/"
82
            ;;
83
        task)
84
            shift
85
            __epm_removerepo_alt_grepremove " repo/$1/"
86
            ;;
87
        -*)
88
            fatal "epm removerepo: no options are supported"
89
            ;;
90
        *)
91
# TODO: if return empty for whole line, use grep
92
#            sudocmd apt-repo $dryrun rm "$*"
93
            __epm_removerepo_alt_grepremove "$*"
94
            ;;
95
    esac
96

97
}
98

99
epm_removerepo()
100
{
101

102
case $BASEDISTRNAME in
103
    "alt")
104
        __epm_removerepo_alt "$@"
105
        return
106
        ;;
107
    "astra")
108
        echo "Use workaround for AstraLinux"
109
        [ -n "$*" ] || fatal "empty repo name"
110
        # aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for AstraLinuxCE/orel
111
        sudocmd sed -i -e "s|.*$*.*||" /etc/apt/sources.list
112
        if [ -d /etc/apt/sources.list.d ] && ls /etc/apt/sources.list.d/*.list >/dev/null 2>/dev/null ; then
113
            sudocmd sed -i -e "s|.*$*.*||" /etc/apt/sources.list.d/*.list
114
        fi
115
        return
116
        ;;
117
esac;
118

119
case $PMTYPE in
120
    apt-dpkg)
121
        assure_exists apt-add-repository software-properties-common
122
        # FIXME: it is possible there is troubles to pass the args
123
        sudocmd apt-add-repository --remove "$*"
124
        info "Check file /etc/apt/sources.list if needed"
125
        ;;
126
    aptitude-dpkg)
127
        info "You need remove repo from /etc/apt/sources.list"
128
        ;;
129
    yum-rpm)
130
        assure_exists yum-utils
131
        sudocmd yum-config-manager --disable "$@"
132
        ;;
133
    urpm-rpm)
134
        if [ "$1" = "all" ] ; then
135
            sudocmd urpmi.removemedia -av
136
            return
137
        fi
138
        sudocmd urpmi.removemedia "$@"
139
        ;;
140
    zypper-rpm)
141
        sudocmd zypper removerepo "$@"
142
        ;;
143
    emerge)
144
        sudocmd layman "-d$1"
145
        ;;
146
    pacman)
147
        info "You need remove repo from /etc/pacman.conf"
148
        ;;
149
    npackd)
150
        sudocmd npackdcl remove-repo --url="$*"
151
        ;;
152
    winget)
153
        sudocmd winget source remove "$@"
154
        ;;
155
    eopkg)
156
        sudocmd eopkg remove-repo "$@"
157
        ;;
158
    slackpkg)
159
        info "You need remove repo from /etc/slackpkg/mirrors"
160
        ;;
161
    *)
162
        fatal "Have no suitable command for $PMTYPE"
163
        ;;
164
esac
165

166
}
167

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

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

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

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