epm-sh-altlinux 4.21 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; }
Vitaly Lipatov's avatar
Vitaly Lipatov committed
95 96
# TODO rsync
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449#c22
97
    else
98
        docmd eget -O "$OFILE" "$URL" || { rm -fv $OFILE ; touch $OFILE.failed ; return 1; }
99
    fi
100

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

105 106 107 108
get_local_alt_contents_index()
{
    load_helper epm-repolist

109 110
    local LOCALPATH

Vitaly Lipatov's avatar
Vitaly Lipatov committed
111
    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
112
        LOCALPATH=$(get_local_alt_mirror_path "$URL/$ARCH")
113
        download_alt_contents_index $URL/$ARCH/base/contents_index $LOCALPATH >&2 </dev/null || continue
114 115 116
        echo "$LOCALPATH/contents_index*"
    done

117
}
118 119 120

tasknumber()
{
121 122
    local num="$(echo "$1" | sed -e "s| *#*||g")"
    isnumber "$num" && echo "$*"
123
}
124

125 126 127
# todo: improve apt-repo
get_task_arepo_packages()
{
128
    local res
129 130 131 132 133
    epm assure apt-repo
    epm assure curl

    info "TODO: please, improve apt-repo to support arepo (i586-) packages for apt-repo list task"
    showcmd "curl -s -f http://git.altlinux.org/tasks/$tn/plan/arepo-add-x86_64-i586 | cut -f1"
134
    # TODO: retrieve one time
135 136
    res="$(a='' curl -s -f http://git.altlinux.org/tasks/$tn/plan/arepo-add-x86_64-i586 2>/dev/null)" || { warning "There is a download error for x86_64-i586 arepo." ; return ; }
    echo "$res" | cut -f1
137 138
}

139 140 141
# use assure apt-repo before
get_task_packages()
{
142
    local arch="$($DISTRVENDOR -a)"
143 144
    local tn
    for tn in $(tasknumber "$@") ; do
145
        showcmd apt-repo list task "$tn"
146
        a='' apt-repo list task "$tn" >/dev/null || continue
147
        a='' apt-repo list task "$tn"
148
        [ "$arch" = "x86_64" ] && get_task_arepo_packages "$tn"
149 150
    done
}