NBash

Форк
0
/
epm-sh-altlinux-contents-index 
151 строка · 5.5 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2014, 2017, 2021  Etersoft
4
# Copyright (C) 2014, 2017, 2021  Vitaly Lipatov <lav@etersoft.ru>
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#
19

20
# apt-file like. See also
21
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
22

23
# convert "http://download.etersoft.ru/pub/ALTLinux/p8/branch x86_64" to ALTLinux/p8/branch/x86_64
24
get_alt_repo_path()
25
{
26
    local DN1=$(dirname "$1")
27
    local DN2=$(dirname $DN1)
28
    local DN3=$(dirname $DN2)
29

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

35
    [ "$BN1" = "branch" ] && echo "$BN3/$BN2/$BN1/$BN0" || echo "$BN2/$BN1/$BN0"
36
}
37

38
# convert "http://download.etersoft.ru/pub/ALTLinux/p8/branch x86_64" to /tmp/epm/ALTLinux/p8/branch/x86_64
39
get_local_alt_mirror_path()
40
{
41
    echo "$epm_cachedir/contents_index/$(get_alt_repo_path "$1")"
42
}
43

44
ALT_CONTENTS_INDEX_LIST=$epm_cachedir/contents_index/contents_index_list
45

46
__rsync_check()
47
{
48
    a= rsync -n "$1" >/dev/null 2>/dev/null
49
}
50

51
# URL TARGETDIR OPTIONS
52
rsync_alt_contents_index()
53
{
54
    local URL="$1"
55
    local TD="$2"
56
    local res
57
    assure_exists rsync
58

59
    __rsync_check "$URL" || return
60

61
    mkdir -p "$(dirname "$TD")"
62
    if [ -z "$quiet" ] ; then
63
        docmd rsync --partial --inplace $3 -a --progress "$URL" "$TD"
64
    else
65
        a= rsync --partial --inplace $3 -a --progress "$URL" "$TD" >/dev/null
66
    fi
67
    res=$?
68
    [ -f "$TD" ] && sudorun chmod a+rw "$TD"
69
    return $res
70
}
71

72
# URL
73
get_url_to_etersoft_mirror()
74
{
75
    local REPOPATH
76
    local ETERSOFT_MIRROR="rsync://download.etersoft.ru/pub"
77
    local ALTREPO=$(get_alt_repo_path "$1")
78
    echo "$ALTREPO" | grep -q "^ALTLinux" || return
79
    echo "$ETERSOFT_MIRROR/$(get_alt_repo_path "$1" | sed -e "s|^ALTLinux/|ALTLinux/contents_index/|")"
80
}
81

82
# "comment" "file"
83
__add_to_contents_index_list()
84
{
85
    [ -n "$verbose" ] && echo " $1 -> $2"
86
    echo "$2" >>$ALT_CONTENTS_INDEX_LIST
87
}
88

89
# "comment" file file2
90
__add_better_to_contents_index_list()
91
{
92
    if [ -s "$2" ] && [ -s "$3" ] ; then
93
        [ "$2" -ot "$3" ] && __add_to_contents_index_list "$1" "$3" && return
94
        __add_to_contents_index_list "$1" "$2" && return
95
    fi
96
    [ -s "$2" ] && __add_to_contents_index_list "$1" "$2" && return
97
    [ -s "$3" ] && __add_to_contents_index_list "$1" "$3" && return
98
}
99

100

101
check_alt_contents_index()
102
{
103
    [ -f "$ALT_CONTENTS_INDEX_LIST" ]
104
}
105

106
# TODO: use special user for this files?
107
init_alt_contents_index()
108
{
109
    sudocmd mkdir -p "$(dirname $ALT_CONTENTS_INDEX_LIST)"
110
    sudocmd chmod a+rw "$(dirname $ALT_CONTENTS_INDEX_LIST)"
111
    sudocmd truncate -s0 $ALT_CONTENTS_INDEX_LIST
112
    sudocmd chmod a+rw $ALT_CONTENTS_INDEX_LIST
113
    update_alt_contents_index
114
}
115

116
# fills ALT_CONTENTS_INDEX_LIST
117
update_alt_contents_index()
118
{
119
    load_helper epm-repolist
120
    check_alt_contents_index || return
121

122
    truncate -s0 "$ALT_CONTENTS_INDEX_LIST"
123
    # TODO: fix for Etersoft/LINUX@Etersoft
124
    # TODO: fix for rsync
125
    info "Retrieving contents_index ..."
126
    (quiet=1 epm_repolist) | grep -v " task$" | grep -E "rpm.*(ftp://|http://|https://|rsync://|file:/)" | sed -e "s@^rpm.*\(ftp://\|http://\|https://\)@rsync://@g" | sed -e "s@^rpm.*\(file:\)@@g" | while read -r URL1 URL2 component ; do
127
        [ "$component" = "debuginfo" ] && continue
128
        URL="$URL1/$URL2"
129
        if is_abs_path "$URL" ; then
130
            # first check for local mirror
131
            local LOCALPATH="$(echo "$URL/base")"
132
            local LOCALPATHGZIP="$(echo "$LOCALPATH" | sed -e "s|/ALTLinux/|/ALTLinux/contents_index/|")"
133
            __add_better_to_contents_index_list "$URL" "$LOCALPATHGZIP/contents_index.gz" "$LOCALPATH/contents_index"
134
        else
135
            local LOCALPATH="$(get_local_alt_mirror_path "$URL")"
136
            local REMOTEURL="$(get_url_to_etersoft_mirror "$URL")"
137
            if [ -n "$REMOTEURL" ] ; then
138
                rsync_alt_contents_index $REMOTEURL/base/contents_index.gz $LOCALPATH/contents_index.gz && __add_to_contents_index_list "$REMOTEURL" "$LOCALPATH/contents_index.gz" && continue
139
                [ -n "$verbose" ] && info "Note: Can't retrieve $REMOTEURL/base/contents_index.gz, fallback to $URL/base/contents_index"
140
            fi
141
            # we don't know if remote server has rsync
142
            # fix rsync URL firstly
143
            #local RSYNCURL="$(echo "$URL" | sed -e "s|rsync://\(ftp.basealt.ru\|basealt.org\|altlinux.ru\)/pub/distributions/ALTLinux|rsync://\1/ALTLinux|")" #"
144
            #rsync_alt_contents_index $RSYNCURL/base/contents_index $LOCALPATH/contents_index -z && __add_to_contents_index_list "$RSYNCURL" "$LOCALPATH/contents_index" && continue
145
            #mkdir -p "$LOCALPATH"
146
            #eget -O $LOCALPATH/contents_index $URL/base/contents_index && __add_to_contents_index_list "$RSYNCURL" "$LOCALPATH/contents_index" && continue
147

148
            #__add_better_to_contents_index_list "(cached)" "$LOCALPATH/contents_index.gz" "$LOCALPATH/contents_index"
149
        fi
150
    done
151
}
152

153

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.