epm-sh-altlinux 2.68 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2014, 2017  Etersoft
# Copyright (C) 2014, 2017  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# 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/>.
#

20
# apt-file like. See also
21
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

# convert "http://download.etersoft.ru/pub/ALTLinux/p8/branch x86_64" to /tmp/epm/ALTLinux/p8/branch/x86_64
get_local_alt_mirror_path()
{
    local DN1=$(dirname "$1")
    local DN2=$(dirname $DN1)

    local BN0=$(basename "$1") # arch
    local BN1=$(basename $DN1) # branch/Sisyphus
    local BN2=$(basename $DN2)

    [ "$BN1" = "branch" ] && echo "/tmp/eepm/$BN2/$BN1/$BN0" || echo "/tmp/eepm/$BN1/$BN0"
}

# args: url target_file
# result: will set FILE
download_alt_contents_index()
{
    local TD="$2"
    local OFILE="$TD/$(basename "$1")"
    local DONE="$TD/done.$(basename "$1")"
    # TODO: check if too old
    if [ -r "$DONE" ] ; then
        return
    fi

    mkdir -p "$TD"

    docmd eget -O "$OFILE" "$1" || return
    # plain file by default
    echo "" >$DONE

    # try compress
    if epm assure lz4 ; then
        docmd lz4 --rm "$OFILE" "$OFILE.lz4" || return
        echo "lz4" >$DONE
    else
        epm assure xz || return
        docmd xz "$ofile" || return
        echo "xz" >$DONE
    fi
}

65 66 67 68
get_local_alt_contents_index()
{
    load_helper epm-repolist

69 70 71 72
    # print out from local mirror
    epm_repolist | grep "rpm.*file:/" | sed -e "s|^rpm.*file:||g" | while read LOCALPATH ARCH other ; do
        test -d "$LOCALPATH/$ARCH" || continue
        FILE="$LOCALPATH/$ARCH/base/contents_index"
73 74 75 76 77 78
        if [ -r "$FILE" ] ; then
            echo "$FILE"
        else
            info "TODO for girar server: There is no $(basename $FILE) file in $(dirname $FILE)"
        fi
    done
79 80 81 82 83 84 85 86

    # print out from mirrored contents_index
    epm_repolist | grep -E "rpm[[:space:]]*(ftp|http|https)://" | sed -e "s@^rpm.*\(ftp\|http\|https://\)@\1@g" | while read URL ARCH other ; do
        LOCALPATH=$(get_local_alt_mirror_path "$URL/$ARCH")
        download_alt_contents_index $URL/$ARCH/base/contents_index $LOCALPATH
        echo "$LOCALPATH/contents_index*"
    done

87
}