epm-addrepo 16.2 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2017, 2019  Etersoft
# Copyright (C) 2012, 2017, 2019  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
ETERSOFTPUBURL=http://download.etersoft.ru/pub
ALTLINUXPUBURL=http://ftp.altlinux.org/pub/distributions

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

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

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

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

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

76
__epm_addrepo_alt_repo()
77
{
78
    local comp
79
    local sign
80
    local repo="$1"
81 82 83 84 85
    comp="$repo"
    sign="$repo"
    rhas "$repo" "^c" && sign="cert8"
    local baseurl="http://ftp.basealt.ru/pub/distributions/ALTLinux"
    epm repo add "rpm [$sign] $baseurl $comp/branch/$DISTRARCH classic" || return
86
    if [ "$DISTRARCH" = "x86_64" ] ; then
87
        epm repo add "rpm [$sign] $baseurl $comp/branch/x86_64-i586 classic" || return
88
    fi
89
    epm repo add "rpm [$sign] $baseurl $comp/branch/noarch classic" || return
90 91
}

92 93 94 95 96 97 98 99 100 101 102
get_archlist()
{
    echo "noarch"
    echo "$DISTRARCH"
    case $DISTRARCH in
        x86_64)
            echo "i586"
            ;;
    esac
}

103 104 105
# 'rpm protocol:/path/to/repo component'
__epm_addrepo_altlinux_short()
{
106 107 108 109 110 111 112 113
    [ -n "$1" ] || fatal "only for rpm repo"
    local url="$2"
    local REPO_NAME="$3"
    local arch

    arch="$(basename "$url")"
    url="$(dirname "$url")"
    docmd epm repo add "rpm $url $arch $REPO_NAME"
114 115
}

116

117 118
__epm_addrepo_altlinux_url()
{
119 120 121 122 123 124 125 126 127
    local url="$1"
    local arch
    local base

    # URL to path/RPMS.addon
    base="$(basename "$url")"
    if echo "$base" | grep -q "^RPMS\." ; then
        REPO_NAME="$(echo $base | sed -e 's|.*\.||')"
        url="$(dirname $url)"
128
        __epm_addrepo_altlinux_short rpm "$url" "$REPO_NAME"
129 130 131 132 133 134 135 136
        return
    fi

    # TODO: add to eget file:/ support and use here
    # URL to path (where RPMS.addon is exists)
    local baseurl="$(eget --list "$url/RPMS.*")"
    base="$(basename "$baseurl")"
    if echo "$base" | grep -q "^RPMS\." ; then
137 138
        REPO_NAME="$(echo "$base" | sed -e 's|.*\.||')"
        __epm_addrepo_altlinux_short rpm "$url" "$REPO_NAME"
139 140 141 142 143 144 145
        return
    fi

    # URL to {i586,x86_64,noarch}/RPMS.addon
    local res=''
    for arch in $(get_archlist) ; do
        local rd="$(eget --list $url/$arch/RPMS.*)"
146 147 148
        [ -n "$rd" ] || continue
        local REPO_NAME="$(echo "$rd" | sed -e 's|/*$||' -e 's|.*\.||')"
        [ "$REPO_NAME" = "*" ] && continue
149 150 151 152
        docmd epm repo add "rpm $url $arch $REPO_NAME"
        res='1'
    done
    [ -n "$res" ] || warning "There is no arch repos in $url"
153 154
}

155

156 157
__epm_addrepo_altlinux_help()
{
158
    #sudocmd apt-repo $dryrun add branch
159
message '
160 161

epm repo add - add branch repo. Use follow params:
162 163 164 165
    basealt                  - for BaseALT repo
    altsp                    - add ALT SP repo
    yandex                   - for BaseALT repo mirror hosted by Yandex (recommended)
    autoimports              - for BaseALT autoimports repo
Vitaly Lipatov's avatar
Vitaly Lipatov committed
166
    autoports                - for Autoports repo (with packages from Sisyphus rebuilt to the branch)
167 168 169 170 171 172 173 174 175
    altlinuxclub             - for altlinuxclub repo (http://altlinuxclub.ru/)
    deferred                 - for Etersoft Sisyphus Deferred repo
    deferred.org             - for Etersoft Sisyphus Deferred repo (at mirror.eterfund.org)
    etersoft                 - for LINUX@Etersoft repo
    korinf                   - for Korinf repo
    <task number>            - add task repo
    archive 2018/02/09       - add archive of the repo from that date
    /dir/to/repo [component] - add repo dir generated with epm repo index --init
    URL [arch] [component]   - add repo by URL
176 177

Examples:
178
    # epm repo add yandex
179
    # epm repo add "rpm http://somesite/pub/product x86_64 addon
180
    # epm repo add /var/ftp/pub/altlinux/p10
181

182
'
183
    return
184 185
}

186
__epm_addrepo_altlinux()
187
{
188 189
    local repo="$*"

Vitaly Lipatov's avatar
Vitaly Lipatov committed
190
    if [ -z "$repo" ] || [ "$repo" = "-h" ] || [ "$repo" = "--list" ] || [ "$repo" = "--help" ] ; then
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
        __epm_addrepo_altlinux_help
        return
    fi

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

    # /path/to/repo
    if [ -d "$1" ] ; then
        __epm_addrepo_altlinux_url "file:$1"
        return
    fi

    # file:/path/to/repo or http://path/to/repo
    if is_url "$1" ; then
        __epm_addrepo_altlinux_url "$1"
        return
    fi

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

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

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

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

            return 0
            ;;
    esac

    assure_exists apt-repo

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

    case "$repo" in
298 299 300 301 302 303
        c10f2|c10f1|c9f2|c9f1|c9)
            __epm_addrepo_alt_repo "$repo"
            return
            ;;
        p11|p10|p9|p8)
            __epm_addrepo_alt_repo "$repo"
304 305 306 307
            return
            ;;
    esac

308 309 310 311
    if [ -z "$force" ] ; then
        # don't add again
        epm repo list --quiet | grep -q -F "$repo" && return 0
    fi
312

313 314 315 316 317
    if echo "$repo" | grep -q "https://" ; then
        local mh="$(echo /usr/lib*/apt/methods/https)"
        assure_exists $mh apt-https
    fi

318
    sudocmd apt-repo $dryrun add "$repo"
319 320 321

}

322

323 324
__epm_addrepo_astra()
{
325 326 327
    local repo="$*"

    if [ -z "$repo" ] || [ "$repo" = "--help" ]; then
328 329 330 331
        message 'Add repo. You can use follow params:
                    distribution component name
                    full sources list line
                    URL version component'
332 333 334 335 336 337 338 339
        return
    fi

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

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

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

376 377 378 379 380 381 382 383 384
__epm_addrepo_alpine()
{
    local repo="$1"
    is_url "$repo" || fatal "Only URL is supported"
    epm repo list --quiet | grep -q -F "$repo" && return 0

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

385 386
__epm_addrepo_deb()
{
387
    assure_exists apt-add-repository software-properties-common
388
    local ad="$DISTRARCH"
389
    # TODO: move to distro_info
390
    local nd="$(a= lsb_release -cs)"
391 392 393
    local repo="$*"

    if [ -z "$repo" ] || [ "$repo" = "--help" ]; then
394 395 396 397 398 399
        message 'Add repo. You can use follow params:
                  docker - add official docker repo
                  ppa:<user>/<ppa-name> - add PPA repo
                  distribution component name
                  full sources list line
                  URL version component'
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
        return
    fi

    # keywords
    case "$1" in
        docker)
            __epm_addkey_deb https://download.docker.com/linux/$PKGVENDOR/gpg "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
            repo="https://download.docker.com/linux/$PKGVENDOR $nd stable"
            ;;
    esac

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

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

    if [ -d "$repo" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
422
        epm repo add "deb file:$repo ./"
423 424 425 426 427 428 429
        return
    fi

    # FIXME: quotes in showcmd/sudocmd
    showcmd apt-add-repository "$repo"
    sudorun apt-add-repository "$repo"
    info "Check file /etc/apt/sources.list if needed"
430
}
Vitaly Lipatov's avatar
Vitaly Lipatov committed
431

432 433
epm_addrepo()
{
434
local repo="$*"
435

436
case $BASEDISTRNAME in
437
    "alt")
438
        __epm_addrepo_altlinux "$@"
439 440 441
        return
        ;;
    "astra")
442
        __epm_addrepo_astra "$@"
443
        return
444 445 446 447
        ;;
    "apk")
        __epm_addrepo_alpine "$repo" || return
        ;;
448 449 450
esac

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

}