epm-sh-altlinux 3.16 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

# 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)
28
    local DN3=$(dirname $DN2)
29 30 31

    local BN0=$(basename "$1") # arch
    local BN1=$(basename $DN1) # branch/Sisyphus
32 33
    local BN2=$(basename $DN2) # p8/ALTLinux
    local BN3=$(basename $DN3) # ALTLinux/
34

35 36 37 38 39 40
    [ "$BN1" = "branch" ] && echo "/tmp/eepm/$BN3/$BN2/$BN1/$BN0" || echo "/tmp/eepm/$BN2/$BN1/$BN0"
}

__local_ercat()
{
   local i
Vitaly Lipatov's avatar
Vitaly Lipatov committed
41
   for i in "$@" ; do
42 43
       case "$i" in
           *.xz)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
44
               a='' xzcat $i
45 46
               ;;
           *.lz4)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
47
               a='' lz4cat $i
48 49 50 51 52 53 54 55 56
               ;;
           *.failed)
               # just ignore
               ;;
           *)
               cat $i
               ;;
       esac
   done
57 58
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
59 60 61 62 63
# something like gzip
compress_file_inplace()
{
    local OFILE="$1"
    if epm assure lz4 </dev/null ; then
64 65
        #docmd lz4 --rm "$OFILE" "$OFILE.lz4" || return
        # due old lz4
66
        docmd lz4 -f "$OFILE" "$OFILE.lz4" || return
67
        rm -fv "$OFILE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
68 69
    else
        epm assure xz </dev/null || return
70
        docmd xz -f "$OFILE" || return
Vitaly Lipatov's avatar
Vitaly Lipatov committed
71 72 73 74
    fi
    return 0
}

75
# args: url/path target_file
76 77 78
# result: will set FILE
download_alt_contents_index()
{
79
    local URL="$1"
80
    local TD="$2"
81 82
    local OFILE="$TD/$(basename "$URL")"

83
    local DONE=$(echo $OFILE*)
84 85 86 87 88 89 90
    # TODO: check if too old
    if [ -r "$DONE" ] ; then
        return
    fi

    mkdir -p "$TD"

91 92 93
    if echo "$URL" | grep -q "^file:/" ; then
        URL=$(echo "$URL" | sed -e "s|^file:||")
        [ -s "$URL" ] || { touch $OFILE.failed ; return 1; }
94
        ln -sf "$URL" "$OFILE" || { touch $OFILE.failed ; return 1; }
95
    else
96
        docmd eget -O "$OFILE" "$URL" || { rm -fv $OFILE ; touch $OFILE.failed ; return 1; }
97
    fi
98

99
    rm -f $OFILE.failed
Vitaly Lipatov's avatar
Vitaly Lipatov committed
100
    compress_file_inplace "$OFILE"
101 102
}

103 104 105 106
get_local_alt_contents_index()
{
    load_helper epm-repolist

107 108
    local LOCALPATH

Vitaly Lipatov's avatar
Vitaly Lipatov committed
109
    epm_repolist | grep -E "rpm.*(ftp://|http://|https://|file:/)" | sed -e "s@^rpm.*\(ftp://\|http://\|https://\|file:\)@\1@g" | while read -r URL ARCH other ; do
110
        LOCALPATH=$(get_local_alt_mirror_path "$URL/$ARCH")
111
        download_alt_contents_index $URL/$ARCH/base/contents_index $LOCALPATH >&2 || continue
112 113 114
        echo "$LOCALPATH/contents_index*"
    done

115
}