Skip to content

Commit

Permalink
[eos-rankmirrors] added option --internal-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-192 committed Sep 21, 2023
1 parent e93561f commit bd6cd29
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
4 changes: 2 additions & 2 deletions eos-rankmirrors/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: EndeavourOS <[email protected]>

pkgname=eos-rankmirrors
pkgver=2.20
pkgver=2.21
pkgrel=1
pkgdesc="EndeavourOS mirror ranking tool"
arch=('any')
Expand All @@ -21,7 +21,7 @@ source=(
$url/eos-rankmirrors.hook
$url/eos-rankmirrors.conf
)
sha512sums=('b1172d065cb6e35a94ab1e8353a8d64f00227b5764bb7862b832d94e605097965c27702cee8d9a75c4bba786aaa2e1de14883f102a8e24d49c4bd0cbd61273c1'
sha512sums=('237bb90e8e5cde11bb1462e3509e7f253f9992e8ed7aa0b4a52f57640fec5a0e8e4f214b1f84aa2f50158f57bc97685014bd123cf806f8e291ab013fe97a7db4'
'476c232dcabdd55f9fd0200e3a428aeb99a867f3b5c475711bd4e0e553c3a4149daa90436f0aaf397c1865888f8746b82deb1d70dff4cfde2b55776359f95c3a'
'580511c676cf56b5b8580d6819e0d1a4c85a40a3cd10f4b4f04fb9c004b14025b56cf4c3048e0fe8f9eef48d924b32b97d1e9669fac39b96f4203e2d68e3bd07'
'f01f6267f624992febfec29c76f2de1c503693086ade5783e2b9cbef359f5155bf6df520ff06299193c842aef2a05cac5078977ee0dabf55cff66f44aec6e44a'
Expand Down
57 changes: 43 additions & 14 deletions eos-rankmirrors/eos-rankmirrors
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,33 @@ verbose() {
}

DeleteTmpFiles() {
if [ -n "$delete_at_end" ] ; then
if [ ${#delete_at_end[@]} -gt 0 ] ; then
echo2 ""
verbose "Deleting temporary files: ${delete_at_end[*]}"
rm -f "${delete_at_end[@]}"
fi
}
export -f DeleteTmpFiles

RemoveFromDelList() {
if [ ${#delete_at_end[@]} -gt 0 ] ; then
echo2 "delete list count = ${#delete_at_end[@]}"
local -r remove_me="$1"
local oldlist=("${delete_at_end[@]}")
local xx
delete_at_end=()
for xx in "${oldlist[@]}" ; do
[ "$xx" != "$remove_me" ] && delete_at_end+=("$xx")
done
fi
}

DIE() {
notif_echo2 "$progname: error: $1"
local msg="$1"
local level="$2" ; [ -n "$level" ] || level=0

notif_echo2 "$progname: error detected at function ${FUNCNAME[$((level+1))]}, line ${BASH_LINENO[$level]}:"
echo2 " $msg"
DeleteTmpFiles
exit 1
}
Expand Down Expand Up @@ -203,23 +220,36 @@ GetReferenceUpdateLevel() {
reference_level=$(echo "$result" | awk '{print $2}')
}

CheckMirrorlist() {
if [ "$internal_testing" = "yes" ] ; then
local file="$1"
if grep "^#[ ]*Server = " "$file" ; then
RemoveFromDelList "$latest_ml"
DIE "endeavouros-mirrorlist (see file $file) has one or more mirrors commented out!" 1 # 1 = level of BASH_LINENO array (which starts from 0)
fi
fi
}

FetchLatestMirrorlist() {
# Grab endeavouros-mirrorlist from the package cache, or fetch it from github/gitlab.

if [ "$use_local_mirrorlist" = "yes" ] ; then
# Use file /etc/pacman.d/endeavouros-mirrorlist. Remove potential ranking results first.
sed -e '/^# Results of mirror ranking at /,$d' -e 's|^#[ ]*Server = |Server = |' /etc/pacman.d/endeavouros-mirrorlist > $latest_ml
CheckMirrorlist "$latest_ml"
return
fi

local pkg=$(ls -1 /var/cache/pacman/pkg/${pkgname}-*.zst 2>/dev/null | tail -n1)
if [ -n "$pkg" ] ; then
local pkg=(/var/cache/pacman/pkg/${pkgname}-*.zst)
if [ ${#pkg[@]} -gt 0 ] ; then
pkg="${pkg[$(( ${#pkg[@]} - 1 ))]}"
# the package exists in the cache
local cachev=$(echo "$pkg" | sed 's|.*list-\(.*\)-any.*|\1|')
local installedv=$(pacman -Q $pkgname | awk '{print $2}')
if [ "$cachev" = "$installedv" ] ; then
notif_echo2 "Info: extracting $pkg ..."
tar --extract -O -f "$pkg" etc/pacman.d/endeavouros-mirrorlist > $latest_ml
CheckMirrorlist "$latest_ml"
return
fi
fi
Expand All @@ -234,6 +264,7 @@ FetchLatestMirrorlist() {
exit 0
;;
esac
CheckMirrorlist "$latest_ml"
}

SimpleRank() {
Expand All @@ -247,7 +278,7 @@ SimpleRank() {
local result IGNORE=""
local xx

latest_ml=$(mktemp /tmp/tmp.dF3784XXXXX) ; delete_at_end+=("$latest_ml")
latest_ml=$(mktemp /tmp/tmp.XXXXX) ; delete_at_end+=("$latest_ml")

FetchLatestMirrorlist

Expand Down Expand Up @@ -449,17 +480,16 @@ EOF
Options() {
local opts

opts=$(getopt -o=$SHORT_OPTIONS --longoptions $LONG_OPTIONS,$LONG_OPTIONS_INTERNAL --name "$progname" -- "$@")
case "$?" in
0) ;;
*) DIE "getopt detected unsupported option, cannot continue." ;;
esac
opts=$(getopt -o=$SHORT_OPTIONS --longoptions $LONG_OPTIONS,$LONG_OPTIONS_INTERNAL --name "$progname" -- "$@") || DIE "getopt detected unsupported option, will not continue."

eval set -- "$opts"

while true ; do
while [ "$1" ] ; do
case "$1" in
# internal tool options:
--internal-testing)
internal_testing=yes
;;
--hook-rank)
hook_rank=yes
;;
Expand Down Expand Up @@ -508,8 +538,6 @@ Options() {
--list-only)
mirrorlist_only=yes # and no other output
;;
--)
shift ; break ;;
esac
shift
done
Expand All @@ -535,7 +563,7 @@ Main()
{
local -r SHORT_OPTIONS="ahnt:"
local -r LONG_OPTIONS="verbose,help,no-save,test-all,timeout:,sort:,ignore:,prefer:,mirror-verbosity:,use-local-mirrorlist"
local -r LONG_OPTIONS_INTERNAL="dump-options::,hook-rank,list-only,mirror-add:"
local -r LONG_OPTIONS_INTERNAL="dump-options::,hook-rank,list-only,mirror-add:,internal-testing"

case "$1" in
--dump-options) DumpOptions ;;
Expand All @@ -562,6 +590,7 @@ Main()
local use_local_mirrorlist=no
local mirrorlist_only=no # 'no' provides rather verbose output, 'yes' provides only the essential list
local added_mirror=""
local internal_testing=no

if [ ! -r "$eos" ] ; then # this test is not really needed...
DIE "no local $eos found, please install package '$pkgname'."
Expand Down

0 comments on commit bd6cd29

Please sign in to comment.