epm-epm_install 4.24 KB
Newer Older
1 2
#!/bin/sh

3
# Copyright (C) 2016, 2020, 2023  Etersoft
4
# Copyright (C) 2016  Danil Mikhailov <danil@etersoft.ru>
5
# Copyright (C) 2016, 2020, 2023  Vitaly Lipatov <lav@etersoft.ru>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#
# 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
# (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
# GNU Affero General Public License for more details.
#
# 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/>.
#

21
load_helper epm-install
22

23 24
# default repo
EPM_KORINF_REPO_URL="https://updates.etersoft.ru/pub/Korinf"
25

26 27
__epm_korinf_site_mask() {
    local MASK="$1"
28
    local archprefix=""
29
    # short hack to install needed package
30
    rhas "$MASK" "[-_]" || MASK="${MASK}[-_][0-9]"
31
    # set arch for Korinf compatibility
32
    [ "$($DISTRVENDOR -a)" = "x86_64" ] && archprefix="x86_64/"
33
    local URL="$EPM_KORINF_REPO_URL/$archprefix$($DISTRVENDOR -e)"
34
    if ! eget --check "$URL" ; then
35
        tURL="$EPM_KORINF_REPO_URL/$archprefix$($DISTRVENDOR --vendor-name)/$($DISTRVENDOR --repo-name)"
36 37
        docmd eget --check "$tURL" && URL="$tURL"
    fi
38
    eget --list --latest "$URL/$MASK*.$PKGFORMAT"
39 40 41 42
}

__epm_korinf_list() {
    local MASK="$1"
43 44 45
    MASK="$(__epm_korinf_site_mask "$MASK")"
    showcmd eget --list "$MASK"
    eget --list "$MASK" | sort
46
}
47

48

49
__epm_korinf_install() {
50

51 52 53 54 55
    local pkg
    local pkg_urls=''
    for pkg in $* ; do
        pkg_urls="$pkg_urls $(__epm_korinf_site_mask "$pkg")"
    done
56 57
    # due Error: Can't use epm call from the piped script
    #epm install $(__epm_korinf_site_mask "$PACKAGE")
58
    pkg_names='' pkg_files='' epm_install
59
}
60

61 62 63
__epm_korinf_install_eepm() {

    # enable interactive for install eepm from console
64
    if inputisatty && [ "$EPMMODE" != "pipe" ] ; then
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        [ -n "$non_interactive" ] || interactive="--interactive"
    fi

    # as now, can't install one package from task (and old apt-repo can't install one package)
    if false && [ "$BASEDISTRNAME" = "alt" ] && [ -z "$direct" ] ; then
        local task="$(docmd eget -O- https://eepm.ru/vendor/alt/task)"
        if [ -n "$task" ] ; then
            docmd epm install $task
            return
        else
            info "Can't get actual task for ALT, fallback to Korinf"
        fi
    fi

    __epm_korinf_install eepm
}

82 83
epm_epm_install_help()
{
84
    echo "epm ei [URL] [packages] - install packages from EPM based Korinf repository"
85 86
            get_help HELPCMD $SHAREDIR/epm-epm_install
    cat <<EOF
87

88
Default Korinf repository: $EPM_KORINF_REPO_URL
89 90

Examples:
91 92 93 94
  epm ei [epm|eepm]                 - install latest eepm (default action)
  epm ei <package1> [<package2>...] - install package(s) from default Korinf repo
  epm http://someurl.ru <package>   - install package(s) from a repo defined by URL
  epm --list <package mask>         - list available packages by mask
95 96 97 98
EOF
}


99 100
epm_epm_install()
{
101

102 103 104 105 106 107 108 109 110
    if [ "$BASEDISTRNAME" = "alt" ] && [ "$DISTRVERSION" != "Sisyphus" ] && [ "$EPMMODE" = "package" ] ; then
        if __epm_check_if_package_from_repo eepm ; then
            warning "Using external (Korinf) repo is forbidden for stable ALT branch $DISTRVERSION."
            info "Check https://bugzilla.altlinux.org/44314 for reasons."
            info "You can install eepm package from Korinf manually, check instruction at https://eepm.ru"
            fatal "Do nothing."
        fi
    fi

111 112 113 114
    if is_url "$1" ; then
        EPM_KORINF_REPO_URL="$1"
        info "Using $EPM_KORINF_REPO_URL repo ..."
        shift
115
    fi
116

117 118 119
    case "$1" in
        ""|epm|eepm)
            # install epm by default
120
            __epm_korinf_install_eepm
121 122 123 124 125 126 127
            return
            ;;
        -h|--help)                     # HELPCMD: help
            epm_epm_install_help
            return
            ;;
        --list)                        # HELPCMD: list only packages
128 129
            shift
            __epm_korinf_list "$1"
130 131 132 133
            return
            ;;
    esac

134
    __epm_korinf_install "$@"
135
}