3
# Copyright (C) 2014, 2017, 2021 Etersoft
4
# Copyright (C) 2014, 2017, 2021 Vitaly Lipatov <lav@etersoft.ru>
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.
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.
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/>.
20
# apt-file like. See also
21
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
23
# convert "http://download.etersoft.ru/pub/ALTLinux/p8/branch x86_64" to ALTLinux/p8/branch/x86_64
26
local DN1=$(dirname "$1")
27
local DN2=$(dirname $DN1)
28
local DN3=$(dirname $DN2)
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/
35
[ "$BN1" = "branch" ] && echo "$BN3/$BN2/$BN1/$BN0" || echo "$BN2/$BN1/$BN0"
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()
41
echo "$epm_cachedir/contents_index/$(get_alt_repo_path "$1")"
44
ALT_CONTENTS_INDEX_LIST=$epm_cachedir/contents_index/contents_index_list
48
a= rsync -n "$1" >/dev/null 2>/dev/null
51
# URL TARGETDIR OPTIONS
52
rsync_alt_contents_index()
59
__rsync_check "$URL" || return
61
mkdir -p "$(dirname "$TD")"
62
if [ -z "$quiet" ] ; then
63
docmd rsync --partial --inplace $3 -a --progress "$URL" "$TD"
65
a= rsync --partial --inplace $3 -a --progress "$URL" "$TD" >/dev/null
68
[ -f "$TD" ] && sudorun chmod a+rw "$TD"
73
get_url_to_etersoft_mirror()
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/|")"
83
__add_to_contents_index_list()
85
[ -n "$verbose" ] && echo " $1 -> $2"
86
echo "$2" >>$ALT_CONTENTS_INDEX_LIST
90
__add_better_to_contents_index_list()
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
96
[ -s "$2" ] && __add_to_contents_index_list "$1" "$2" && return
97
[ -s "$3" ] && __add_to_contents_index_list "$1" "$3" && return
101
check_alt_contents_index()
103
[ -f "$ALT_CONTENTS_INDEX_LIST" ]
106
# TODO: use special user for this files?
107
init_alt_contents_index()
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
116
# fills ALT_CONTENTS_INDEX_LIST
117
update_alt_contents_index()
119
load_helper epm-repolist
120
check_alt_contents_index || return
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
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"
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"
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
148
#__add_better_to_contents_index_list "(cached)" "$LOCALPATH/contents_index.gz" "$LOCALPATH/contents_index"