NBash

Форк
0
508 строк · 16.1 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012, 2017, 2019  Etersoft
4
# Copyright (C) 2012, 2017, 2019  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
ETERSOFTPUBURL=http://download.etersoft.ru/pub
23
ALTLINUXPUBURL=http://ftp.altlinux.org/pub/distributions
24

25
__epm_addrepo_rhel()
26
{
27
    local repo="$*"
28
    if [ -z "$repo" ] ; then
29
        echo "Add repo."
30
        echo "1. Use with repository URL, f.i. http://www.example.com/example.repo"
31
        echo "2. Use with epel to add EPEL repository"
32
        echo "3. Use with powertools to add PowerTools repository"
33
        echo "4. Use with crb to add Rocky Linux CRB repository"
34
        return 1
35
    fi
36
    case "$1" in
37
        epel)
38
            # dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
39
            epm install epel-release
40
            return 1
41
            ;;
42
        powertools)
43
            # https://serverfault.com/questions/997896/how-to-enable-powertools-repository-in-centos-8
44
            epm install --skip-installed dnf-plugins-core
45
            sudocmd dnf config-manager --set-enabled powertools
46
            return 1
47
            ;;
48
        crb)
49
            # https://wiki.rockylinux.org/rocky/repo/
50
            epm install --skip-installed dnf-plugins-core
51
            sudocmd dnf config-manager --set-enabled crb
52
            return 1
53
            ;;
54
    esac
55
    return 0
56
}
57

58
__epm_addrepo_etersoft_addon()
59
{
60
    epm install --skip-installed apt-conf-etersoft-common apt-conf-etersoft-hold || fatal
61
    # TODO: ignore only error code 22 (skipped) || fatal
62

63
    local pb="$DISTRVERSION/branch"
64
    [ "$DISTRVERSION" = "Sisyphus" ] && pb="$DISTRVERSION"
65

66
    # FIXME
67
    [ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
68

69
    docmd epm repo add "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$pb/noarch addon"
70
    docmd epm repo add "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$pb/$DISTRARCH addon"
71
    if [ "$DISTRARCH" = "x86_64" ] ; then
72
        docmd epm repo add "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$pb/x86_64-i586 addon"
73
    fi
74
}
75

76
__epm_addrepo_altsp()
77
{
78
    local comp
79
    local repo="$1"
80
    case "$repo" in
81
        c10f1)
82
            comp="CF3"
83
            ;;
84
        c9f2)
85
            comp="CF2"
86
            ;;
87
        c9f1)
88
            comp="CF1"
89
            ;;
90
        c9)
91
            comp="cf"
92
            ;;
93
        *)
94
            fatal "Uknown CF comp $repo"
95
            ;;
96
    esac
97

98
    epm repo add "rpm [cert8] http://update.altsp.su/pub/distributions/ALTLinux $comp/branch/$DISTRARCH classic" || return
99
    if [ "$DISTRARCH" = "x86_64" ] ; then
100
        epm repo add "rpm [cert8] http://update.altsp.su/pub/distributions/ALTLinux $comp/branch/x86_64-i586 classic" || return
101
    fi
102
    epm repo add "rpm [cert8] http://update.altsp.su/pub/distributions/ALTLinux $comp/branch/noarch classic" || return
103
}
104

105
get_archlist()
106
{
107
    echo "noarch"
108
    echo "$DISTRARCH"
109
    case $DISTRARCH in
110
        x86_64)
111
            echo "i586"
112
            ;;
113
    esac
114
}
115

116
# 'rpm protocol:/path/to/repo component'
117
__epm_addrepo_altlinux_short()
118
{
119
    [ -n "$1" ] || fatal "only for rpm repo"
120
    local url="$2"
121
    local REPO_NAME="$3"
122
    local arch
123

124
    arch="$(basename "$url")"
125
    url="$(dirname "$url")"
126
    docmd epm repo add "rpm $url $arch $REPO_NAME"
127
}
128

129

130
__epm_addrepo_altlinux_url()
131
{
132
    local url="$1"
133
    local arch
134
    local base
135

136
    # URL to path/RPMS.addon
137
    base="$(basename "$url")"
138
    if echo "$base" | grep -q "^RPMS\." ; then
139
        REPO_NAME="$(echo $base | sed -e 's|.*\.||')"
140
        url="$(dirname $url)"
141
        docmd epm repo add "rpm $url $REPO_NAME"
142
        return
143
    fi
144

145
    # TODO: add to eget file:/ support and use here
146
    # URL to path (where RPMS.addon is exists)
147
    local baseurl="$(eget --list "$url/RPMS.*")"
148
    base="$(basename "$baseurl")"
149
    if echo "$base" | grep -q "^RPMS\." ; then
150
        REPO_NAME="$(echo $base | sed -e 's|.*\.||')"
151
        docmd epm repo add "rpm $url $REPO_NAME"
152
        return
153
    fi
154

155
    # URL to {i586,x86_64,noarch}/RPMS.addon
156
    local res=''
157
    for arch in $(get_archlist) ; do
158
        local rd="$(eget --list $url/$arch/RPMS.*)"
159
        [ -d "$rd" ] || continue
160
        local REPO_NAME="$(echo "$rd" | sed -e 's|.*\.||')"
161
        docmd epm repo add "rpm $url $arch $REPO_NAME"
162
        res='1'
163
    done
164
    [ -n "$res" ] || warning "There is no arch repos in $url"
165
}
166

167

168
__epm_addrepo_altlinux_help()
169
{
170
    #sudocmd apt-repo $dryrun add branch
171
cat <<EOF
172

173
epm repo add - add branch repo. Use follow params:
174
    basealt                  - for BaseALT repo"
175
    altsp                    - add ALT SP repo"
176
    yandex                   - for BaseALT repo mirror hosted by Yandex (recommended)"
177
    autoimports              - for BaseALT autoimports repo"
178
    autoports                - for Autoports repo (with packages from Sisyphus rebuilt to the branch)
179
    altlinuxclub             - for altlinuxclub repo (http://altlinuxclub.ru/)"
180
    deferred                 - for Etersoft Sisyphus Deferred repo"
181
    deferred.org             - for Etersoft Sisyphus Deferred repo (at mirror.eterfund.org)"
182
    etersoft                 - for LINUX@Etersoft repo"
183
    korinf                   - for Korinf repo"
184
    <task number>            - add task repo"
185
    archive 2018/02/09       - add archive of the repo from that date"
186
    /dir/to/repo [component] - add repo dir generated with epm repo index --init"
187
    URL [arch] [component]   - add repo by URL"
188

189
Examples:
190
    # epm repo add yandex
191
    # epm repo add "rpm http://somesite/pub/product x86_64 addon"
192
    # epm repo add /var/ftp/pub/altlinux/p10
193

194
EOF
195
    return
196
}
197

198
__epm_addrepo_altlinux()
199
{
200
    local repo="$*"
201

202
    if [ -z "$repo" ] || [ "$repo" = "-h" ] || [ "$repo" = "--list" ] || [ "$repo" = "--help" ] ; then
203
        __epm_addrepo_altlinux_help
204
        return
205
    fi
206

207
    # 'rpm protocol:/path/to/repo component'
208
    if [ "$1" = "rpm" ] && [ -n "$2" ] && [ -n "$3" ] && [ -z "$4" ] ; then
209
        __epm_addrepo_altlinux_short "$@"
210
        return
211
    fi
212

213
    # /path/to/repo
214
    if [ -d "$1" ] ; then
215
        __epm_addrepo_altlinux_url "file:$1"
216
        return
217
    fi
218

219
    # file:/path/to/repo or http://path/to/repo
220
    if is_url "$1" ; then
221
        __epm_addrepo_altlinux_url "$1"
222
        return
223
    fi
224

225
    local branch="$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
226
    [ -n "$branch" ] || fatal "Empty DISTRVERSION"
227

228
    case "$1" in
229
        etersoft)
230
            # TODO: return when Etersoft improved its repos
231
            #info "add Etersoft's addon repo"
232
            #__epm_addrepo_etersoft_addon
233
            epm repo add $branch
234
            epm repofix etersoft
235
            return 0
236
            ;;
237
        basealt|alt|altsp)
238
            repo="$branch"
239
            ;;
240
        yandex)
241
            epm repo add $branch
242
            epm repofix yandex
243
            return 0
244
            ;;
245
        autoimports)
246
            repo="autoimports.$branch"
247
            ;;
248
        autoports)
249
            local http="http"
250
            epm installed apt-https && http="https"
251
            case $branch in
252
                p10|p9|p8)
253
                    ;;
254
                *)
255
                    fatal "Autoports is not supported for $DISTRNAME $branch. Check https://www.altlinux.org/Autoports ."
256
                    ;;
257
            esac
258
            epm repo addkey cronbuild "DE73F3444C163CCD751AC483B584C633278EB305" "Cronbuild Service <cronbuild@altlinux.org>"
259
            epm repo add "rpm [cronbuild] $http://autoports.altlinux.org/pub ALTLinux/autoports/$DISTRVERSION/$DISTRARCH autoports"
260
            epm repo add "rpm [cronbuild] $http://autoports.altlinux.org/pub ALTLinux/autoports/$DISTRVERSION/noarch autoports"
261
            return 0
262
            ;;
263
        altlinuxclub)
264
            repo="altlinuxclub.$branch"
265
            ;;
266
        autoimports.*|altlinuxclub.*)
267
            repo="$1"
268
            ;;
269
        korinf)
270
            local http="http"
271
            epm installed apt-https && http="https"
272
            epm repo add "rpm $http://download.etersoft.ru/pub Korinf/ALTLinux/$DISTRVERSION main"
273
            return 0
274
            ;;
275
        deferred)
276
            [ "$DISTRVERSION" = "Sisyphus" ] || fatal "Etersot Sisyphus Deferred supported only for ALT Sisyphus."
277
            epm repo add "http://download.etersoft.ru/pub Etersoft/Sisyphus/Deferred"
278
            return 0
279
            ;;
280
        deferred.org)
281
            [ "$DISTRVERSION" = "Sisyphus" ] || fatal "Etersot Sisyphus Deferred supported only for ALT Sisyphus."
282
            epm repo add "http://mirror.eterfund.org/download.etersoft.ru/pub Etersoft/Sisyphus/Deferred"
283
            return 0
284
            ;;
285
        archive)
286
            datestr="$2"
287
            echo "$datestr" | grep -Eq "^20[0-2][0-9]/[01][0-9]/[0-3][0-9]$" || fatal "use follow date format: 2017/01/31"
288

289
            local rpmsign='[alt]'
290
            [ "$branch" != "sisyphus" ] && rpmsign="[$branch]"
291

292
            epm repo add "rpm $rpmsign $ALTLINUXPUBURL archive/$branch/date/$datestr/$DISTRARCH classic"
293
            if [ "$DISTRARCH" = "x86_64" ] ; then
294
                epm repo add "rpm $rpmsign $ALTLINUXPUBURL archive/$branch/date/$datestr/x86_64-i586 classic"
295
            fi
296
            epm repo add "rpm $rpmsign $ALTLINUXPUBURL archive/$branch/date/$datestr/noarch classic"
297

298
            return 0
299
            ;;
300
    esac
301

302
    assure_exists apt-repo
303

304
    if tasknumber "$repo" >/dev/null ; then
305
        sudocmd_foreach "apt-repo $dryrun add" $(tasknumber "$repo")
306
        return
307
    fi
308

309
    case "$repo" in
310
        c10f*|c9f*|c9)
311
            __epm_addrepo_altsp "$repo"
312
            return
313
            ;;
314
    esac
315

316
    if [ -z "$force" ] ; then
317
        # don't add again
318
        epm repo list --quiet | grep -q -F "$repo" && return 0
319
    fi
320

321
    if echo "$repo" | grep -q "https://" ; then
322
        local mh="$(echo /usr/lib*/apt/methods/https)"
323
        assure_exists $mh apt-https
324
    fi
325

326
    sudocmd apt-repo $dryrun add "$repo"
327

328
}
329

330

331
__epm_addrepo_astra()
332
{
333
    local repo="$*"
334

335
    if [ -z "$repo" ] || [ "$repo" = "--help" ]; then
336
        info "Add repo. You can use follow params:"
337
        echo "  distribution component name"
338
        echo "  full sources list line"
339
        echo "  URL version component"
340
        return
341
    fi
342

343
    local reponame="$(epm print info --repo-name)"
344

345
    # keywords
346
    # https://wiki.astralinux.ru/pages/viewpage.action?pageId=3276859
347
    case "$1-$reponame" in
348
        astra-1.7_x86-64)
349
            # TODO epm repo change http / https
350
            epm install --skip-installed apt-transport-https ca-certificates || fatal
351
            if epm repo list | grep "dl.astralinux.ru/astra/stable/1.7_x86-64" ; then
352
                fatal "Astra repo is already in the list"
353
            fi
354
            # https://wiki.astralinux.ru/pages/viewpage.action?pageId=158598882
355
            epm repo add "deb [arch-=i386] https://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-main/     1.7_x86-64 main contrib non-free"
356
            epm repo add "deb [arch-=i386] https://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-update/   1.7_x86-64 main contrib non-free"
357
            epm repo add "deb [arch-=i386] https://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-base/     1.7_x86-64 main contrib non-free"
358
            epm repo add "deb [arch-=i386] https://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-extended/ 1.7_x86-64 main contrib non-free"
359
            epm repo add "deb [arch-=i386] https://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-extended/ 1.7_x86-64 astra-ce"
360
            return
361
            ;;
362
        astra-orel)
363
            # TODO epm repo change http / https
364
            epm install --skip-installed apt-transport-https ca-certificates || fatal
365
            # https://wiki.astralinux.ru/pages/viewpage.action?pageId=158605543
366
            epm repo add "deb [arch=amd64] https://dl.astralinux.ru/astra/frozen/$(epm print info -v)_x86-64/$(epm print info --full-version)/repository stable main contrib non-free"
367
            #epm repo add "deb https://download.astralinux.ru/astra/stable/orel/repository/ orel main contrib non-free"
368
            return
369
            ;;
370
        astra-*)
371
            fatal "Unsupported distro version $1-$reponame, see '# epm print info' output."
372
            ;;
373
    esac
374

375
    echo "Use workaround for AstraLinux ..."
376
    # aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for AstraLinuxCE/orel
377
    # don't add again
378
    epm repo list --quiet | grep -q -F "$repo" && return 0
379
    [ -z "$(tail -n1 /etc/apt/sources.list)" ] || echo "" | sudocmd tee -a /etc/apt/sources.list
380
    echo "$repo" | sudocmd tee -a /etc/apt/sources.list
381
    return
382
}
383

384
__epm_addrepo_alpine()
385
{
386
    local repo="$1"
387
    is_url "$repo" || fatal "Only URL is supported"
388
    epm repo list --quiet | grep -q -F "$repo" && return 0
389

390
    echo "$repo" | sudocmd tee -a /etc/apk/repositories
391
}
392

393
__epm_addrepo_deb()
394
{
395
    assure_exists apt-add-repository software-properties-common
396
    local ad="$DISTRARCH"
397
    # TODO: move to distro_info
398
    local nd="$(lsb_release -cs)"
399
    local repo="$*"
400

401
    if [ -z "$repo" ] || [ "$repo" = "--help" ]; then
402
        info "Add repo. You can use follow params:"
403
        echo "  docker - add official docker repo"
404
        echo "  ppa:<user>/<ppa-name> - add PPA repo"
405
        echo "  distribution component name"
406
        echo "  full sources list line"
407
        echo "  URL version component"
408
        return
409
    fi
410

411
    # keywords
412
    case "$1" in
413
        docker)
414
            __epm_addkey_deb https://download.docker.com/linux/$PKGVENDOR/gpg "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
415
            repo="https://download.docker.com/linux/$PKGVENDOR $nd stable"
416
            ;;
417
    esac
418

419
    # if started from url, use heroistic
420
    if echo "$repo" | grep -E -q "^https?://" ; then
421
        repo="deb [arch=$ad] $repo"
422
    fi
423

424
    if echo "$repo" | grep -q "https://" ; then
425
        assure_exists /usr/share/doc/apt-transport-https apt-transport-https
426
        assure_exists /usr/sbin/update-ca-certificates ca-certificates 
427
    fi
428

429
    if [ -d "$repo" ] ; then
430
        epm repo add "deb file:$repo ./"
431
        return
432
    fi
433

434
    # FIXME: quotes in showcmd/sudocmd
435
    showcmd apt-add-repository "$repo"
436
    sudorun apt-add-repository "$repo"
437
    info "Check file /etc/apt/sources.list if needed"
438
}
439

440
epm_addrepo()
441
{
442
local repo="$*"
443

444
case $BASEDISTRNAME in
445
    "alt")
446
        __epm_addrepo_altlinux "$@"
447
        return
448
        ;;
449
    "astra")
450
        __epm_addrepo_astra "$@"
451
        return
452
        ;;
453
    "apk")
454
        __epm_addrepo_alpine "$repo" || return
455
        ;;
456
esac
457

458
case $PMTYPE in
459
    apt-dpkg)
460
        __epm_addrepo_deb "$@"
461
        ;;
462
    aptitude-dpkg)
463
        info "You need manually add repo to /etc/apt/sources.list (TODO)"
464
        ;;
465
    yum-rpm)
466
        assure_exists yum-utils
467
        __epm_addrepo_rhel "$repo" || return
468
        sudocmd yum-config-manager --add-repo "$repo"
469
        ;;
470
    dnf-rpm)
471
        __epm_addrepo_rhel "$repo" || return
472
        sudocmd dnf config-manager --add-repo "$repo"
473
        ;;
474
    urpm-rpm)
475
        sudocmd urpmi.addmedia "$@"
476
        ;;
477
    zypper-rpm)
478
        sudocmd zypper ar "$repo"
479
        ;;
480
    emerge)
481
        sudocmd layman -a "$repo"
482
        ;;
483
    pacman)
484
        info "You need manually add repo to /etc/pacman.conf"
485
        # Only for alone packages:
486
        #sudocmd repo-add $pkg_filenames
487
        ;;
488
    npackd)
489
        sudocmd npackdcl add-repo --url="$repo"
490
        ;;
491
    winget)
492
        sudocmd winget source add "$repo"
493
        ;;
494
    nix)
495
        sudocmd nix-channel --add "$repo"
496
        ;;
497
    termux-pkg)
498
        sudocmd pkg install "$repo"
499
        ;;
500
    slackpkg)
501
        info "You need manually add repo to /etc/slackpkg/mirrors"
502
        ;;
503
    *)
504
        fatal "Have no suitable command for $PMTYPE"
505
        ;;
506
esac
507

508
}
509

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

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

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

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