You need to sign in or sign up before continuing.
Commit c1fcf500 authored by Vitaly Lipatov's avatar Vitaly Lipatov

implement local cache for contents index for ALT repos

parent 3ba96cdc
...@@ -17,22 +17,43 @@ ...@@ -17,22 +17,43 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
__local_ercat()
{
local i
for i in $* ; do
case "$i" in
*.xz)
xzcat $i
;;
*.lz4)
lz4cat $i
;;
*)
cat $i
;;
esac
done
}
__alt_local_content_search() __alt_local_content_search()
{ {
load_helper epm-sh-altlinux load_helper epm-sh-altlinux
info "Locate contents index file(s) ..."
local CI="$(get_local_alt_contents_index)" local CI="$(get_local_alt_contents_index)"
# TODO use something like # TODO use something like
[ -n "$CI" ] || fatal "Have no local contents index" [ -n "$CI" ] || fatal "Have no local contents index"
#local OUTCMD="less"
info "Searching in"
echo "$CI"
echo "for $1... "
#[ -n "$USETTY" ] || OUTCMD="cat" #[ -n "$USETTY" ] || OUTCMD="cat"
OUTCMD="cat" # OUTCMD="cat"
{ # {
[ -n "$USETTY" ] && info "Search in $CI for $1..."
# note! tabulation below! # note! tabulation below!
grep -h -- ".*$1.* " $CI | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g" __local_ercat $CI | grep -h -- ".*$1.* " | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g"
} | $OUTCMD # } | $OUTCMD
} }
epm_search_file() epm_search_file()
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2014 Etersoft # Copyright (C) 2014, 2017 Etersoft
# Copyright (C) 2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2014, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -17,19 +17,71 @@ ...@@ -17,19 +17,71 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# TODO: port or rewrite apt-file # apt-file like. See also
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449 # https://bugzilla.altlinux.org/show_bug.cgi?id=14449
# 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
}
get_local_alt_contents_index() get_local_alt_contents_index()
{ {
load_helper epm-repolist load_helper epm-repolist
epm_repolist | grep "rpm.*file:/" | sed -e "s|^rpm.*file:||g" | while read URL ARCH other ; do # print out from local mirror
test -d "$URL/$ARCH" || continue # fatal "Local mirror is not accessible via $URL/$ARCH" epm_repolist | grep "rpm.*file:/" | sed -e "s|^rpm.*file:||g" | while read LOCALPATH ARCH other ; do
FILE="$URL/$ARCH/base/contents_index" test -d "$LOCALPATH/$ARCH" || continue
FILE="$LOCALPATH/$ARCH/base/contents_index"
if [ -r "$FILE" ] ; then if [ -r "$FILE" ] ; then
echo "$FILE" echo "$FILE"
else else
info "TODO for girar server: There is no $(basename $FILE) file in $(dirname $FILE)" info "TODO for girar server: There is no $(basename $FILE) file in $(dirname $FILE)"
fi fi
done done
# 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
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment