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

3
# Copyright (C) 2016, 2020  Etersoft
4
# Copyright (C) 2016  Danil Mikhailov <danil@etersoft.ru>
5
# Copyright (C) 2016, 2020  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 25 26 27
# copied from play.d/common.sh

check_url_is_accessible()
{
    local res
28
    eget --check "$1"
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
}

# update URL variable
update_url_if_need_mirrored()
{
    local MIRROR="$1"
    local SECONDURL
    check_url_is_accessible "$URL" && return
    if [ -n "$MIRROR" ] ; then
        check_url_is_accessible "$MIRROR" && URL="$MIRROR"
        return
    fi

    MIRROR="https://mirror.eterfund.ru"
    SECONDURL="$(echo "$URL" | sed -e "s|^.*://|$MIRROR/|")"
    check_url_is_accessible "$SECONDURL" && URL="$SECONDURL" && return

    MIRROR="https://mirror.eterfund.org"
    SECONDURL="$(echo "$URL" | sed -e "s|^.*://|$MIRROR/|")"
    check_url_is_accessible "$SECONDURL" && URL="$SECONDURL" && return

}


53 54
__epm_korinf_site_mask() {
    local MASK="$1"
55
    local archprefix=""
56 57
    # short hack to install needed package
    rhas "$MASK" "[-_]" || MASK="$MASK[-_][0-9]"
58
    # set arch for Korinf compatibility
59
    [ "$($DISTRVENDOR -a)" = "x86_64" ] && archprefix="x86_64/"
60 61 62
    URL="http://updates.etersoft.ru/pub/Korinf"
    update_url_if_need_mirrored
    echo "$URL/$archprefix$($DISTRVENDOR -e)/$MASK*.$($DISTRVENDOR -p)"
63 64 65 66
}

__epm_korinf_list() {
    local MASK="$1"
67 68 69
    MASK="$(__epm_korinf_site_mask "$MASK")"
    showcmd eget --list "$MASK"
    eget --list "$MASK" | sort
70
}
71

72

73
__epm_korinf_install() {
74 75 76 77 78

    # skip interactive for install eepm from stdin
    if inputisatty && [ -n "$PROGDIR" ] && [ "$1" != "eepm" ] ; then
        [ -n "$non_interactive" ] || interactive="--interactive"
    fi
79 80 81 82 83 84

    local pkg
    local pkg_urls=''
    for pkg in $* ; do
        pkg_urls="$pkg_urls $(__epm_korinf_site_mask "$pkg")"
    done
85 86
    # due Error: Can't use epm call from the piped script
    #epm install $(__epm_korinf_site_mask "$PACKAGE")
87
    pkg_names='' pkg_files='' epm_install
88
}
89

90
epm_epm_install() {
91
    local i
92 93
    local pkglist="$*"

94
    # install epm by default
95
    if [ -z "$pkglist" ] || [ "$pkglist" = "epm" ] || [ "$pkglist" = "eepm" ]; then
96 97 98
#        if [ "$($DISTRVENDOR -s)" = "alt" ] ; then
#            pkglist="distro_info eepm"
#        else
99
            pkglist="eepm"
100
#        fi
101
    fi
102 103 104

    case "$pkglist" in
        --list*)
105 106
            shift
            __epm_korinf_list "$1"
107 108 109 110
            return
            ;;
    esac

111
    __epm_korinf_install $pkglist
112
}