Skip to content

Commit

Permalink
[eos-rankmirrors] added options --list-only and --mirror-add
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-192 committed Sep 26, 2023
1 parent 785ea23 commit 4b69d04
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 92 deletions.
6 changes: 3 additions & 3 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.23
pkgver=2.24
pkgrel=1
pkgdesc="EndeavourOS mirror ranking tool"
arch=('any')
Expand All @@ -22,8 +22,8 @@ source=(
$url/eos-rankmirrors.conf
$url/eos-rankmirrors.disabled
)
sha512sums=('2f75eb0367350ae9392907964ee8b2795c38b36e0815e882fb22cd471c1642294b633ce779e15a44d2215004ea4a5c4d691333a7f6c610cc6a9c800154b789cd'
'476c232dcabdd55f9fd0200e3a428aeb99a867f3b5c475711bd4e0e553c3a4149daa90436f0aaf397c1865888f8746b82deb1d70dff4cfde2b55776359f95c3a'
sha512sums=('bdf831bc647980beb10b5363661554e22936ace76c5df53d3b8371ace1f5d6fc89e117ab8eadd2cce7849a5d3592cb84f628afd8895373e264a296dbdcaebc77'
'07c4be1c228840104d3a8b3324a3a248ec82ad0204cb93b7d86ebb2768cd71a047e7e0204da10b1102bc13dfe26b7050a4257ed7e51dfac6bb499b46f5f406f7'
'580511c676cf56b5b8580d6819e0d1a4c85a40a3cd10f4b4f04fb9c004b14025b56cf4c3048e0fe8f9eef48d924b32b97d1e9669fac39b96f4203e2d68e3bd07'
'f01f6267f624992febfec29c76f2de1c503693086ade5783e2b9cbef359f5155bf6df520ff06299193c842aef2a05cac5078977ee0dabf55cff66f44aec6e44a'
'226111836a42e3540c714105813f64b285b3c48d41ea058e7339ba5b2de530a691d753b8f6d10984d260ed3288b01539715b00ad9bef4d808d21303c936837e7'
Expand Down
81 changes: 30 additions & 51 deletions eos-rankmirrors/eos-rankmirrors
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ Options:
--verbose
Show more detailed output.
Advanced options:
--list-only
Save only the mirrorlist without the ranking statistics.
--mirror-add
Temporarily add a mirror URL for ranking (for testing purposes only).
EOF
}

Expand All @@ -483,61 +490,33 @@ Options() {

eval set -- "$opts"

while [ "$1" ] ; do
while true ; do
case "$1" in
# internal tool options:
--internal-testing)
internal_testing=yes
;;
--hook-rank)
hook_rank=yes
;;
--dump-options)
DumpOptions
;;
--dump-options=all)
DumpOptions --all
;;
--mirror-add)
# --mirror-add <mirror-url>
# Manually adds a non-existing mirror for ranking.
# Meant for testing unlisted mirrors only.
added_mirror="$2"
;;
--internal-testing) internal_testing=yes ;;
--hook-rank) hook_rank=yes ;;
--dump-options) DumpOptions ;;
--dump-options=all) DumpOptions --all ;;
--mirror-add) added_mirror="$2" ;;

# all user options
--help | -h)
Usage
exit 0
;;

--sort)
sort="$2" ; shift ;;
--ignore)
ignored_mirrors="$2" ; shift ;;
--prefer)
preferred_mirrors="$2" ; shift ;;
--use-local-mirrorlist)
use_local_mirrorlist=yes ;;
--timeout | -t)
timeout="$2" ; shift ;;
--verbose)
verbose=yes ;;
--mirror-verbosity)
mirror_verbosity="$2" ; shift ; Check-mirror_verbosity option ;;
--no-save | -n)
save=no
;;
--test-all | -a)
save=no
test_all=yes
EOS_IGNORED_MIRRORS=()
ignored_mirrors=""
[ $timeout -lt $timeout_default ] && timeout=$timeout_default
;;
--list-only)
mirrorlist_only=yes # and no other output
;;
--help | -h) Usage; exit 0 ;;
--sort) sort="$2" ; shift ;;
--ignore) ignored_mirrors="$2" ; shift ;;
--prefer) preferred_mirrors="$2" ; shift ;;
--use-local-mirrorlist) use_local_mirrorlist=yes ;;
--timeout | -t) timeout="$2" ; shift ;;
--verbose) verbose=yes ;;
--mirror-verbosity) mirror_verbosity="$2" ; shift ; Check-mirror_verbosity option ;;
--no-save | -n) save=no ;;
--list-only) mirrorlist_only=yes ;; # and no other output
--test-all | -a) save=no
test_all=yes
EOS_IGNORED_MIRRORS=()
ignored_mirrors=""
[ $timeout -lt $timeout_default ] && timeout=$timeout_default
;;
--) shift; break ;;
esac
shift
done
Expand Down
70 changes: 32 additions & 38 deletions eos-rankmirrors/eos-rankmirrors.completion
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
# bash completion for eos-rankmirrors -*- shell-script -*-

FilterMirrorUrls() { grep -E "^[ \t]*Server[ \t]+=[ \t]+" | awk '{print $3}' | sed -E "s|^(.*)$|'\1'|" ; }
_eos-rankmirrors_FilterMirrorUrls() {
grep -E "^[ \t]*Server[ \t]+=[ \t]+" | awk '{print $3}' | sed -E "s|^(.*)$|'\1'|"
}

GetMirrors() {
_eos-rankmirrors_GetMirrors() {
# Grab endeavouros-mirrorlist from the latest package.
# First try the package cache. If no luck, fetch it from github/gitlab.

local tmp_mirrorlist=/tmp/tmp.ml172549udf8 # save the list here for performance

if [ -r $tmp_mirrorlist ] ; then
cat $tmp_mirrorlist
return 0
fi

local -r pkgname=endeavouros-mirrorlist
local -r pkg=$(ls -1 /var/cache/pacman/pkg/${pkgname}-*.zst 2>/dev/null | tail -n1)

if [ -n "$pkg" ] ; then
# The package exists in the cache.
# Check if the installed version is the same as in the cache.
#
# local cachev=$(echo "$pkg" | sed 's|.*list-\(.*\)-any.*|\1|')
# local installedv=$(expac -Q %v $pkgname)
# if [ $(vercmp "$installedv" "$cachev") -ge 0 ] ; then
tar --extract -O -f "$pkg" etc/pacman.d/endeavouros-mirrorlist | FilterMirrorUrls
return 0
# fi
tar --extract -O -f "$pkg" etc/pacman.d/endeavouros-mirrorlist | _eos-rankmirrors_FilterMirrorUrls > $tmp_mirrorlist
_eos-rankmirrors_GetMirrors
return 0
fi

# Package not in cache # or installed package version is not the same as in cache.
# Package not in cache, or installed package version is not the same as in cache.
# Fetch it.
local -r url="$(eos-github2gitlab --keep-master "https://raw.githubusercontent.com/endeavouros-team/PKGBUILDS/master/$pkgname/$pkgname")"
local -r timeout=5 # not too long...
curl --fail -Lsm $timeout -o- "$url" | FilterMirrorUrls
curl --fail -Lsm $timeout -o- "$url" | _eos-rankmirrors_FilterMirrorUrls > $tmp_mirrorlist
_eos-rankmirrors_GetMirrors
}

_eos-rankmirrors_() {
local cur prev #words cword split
_init_completion -s || return

local -r opts="$(eos-rankmirrors --dump-options)" # alternative, slower
local -r opts="$(eos-rankmirrors --dump-options=all)"
local -r verbosities=( all code show none )

# Handle options that need sub-options.
# Each option "case" should return immediately.

case "$prev" in
--sort)
COMPREPLY=($(compgen -W "age rate" -- "$cur"))
;;
--timeout | -t)
COMPREPLY=($(compgen -P "$cur" -W "{1..60}"))
compopt -o nospace
compopt -o nosort
;;
--ignore | --prefer)
COMPREPLY=($(compgen -P "'" -S "'" -W "$(GetMirrors)" -- "$cur"))
;;
--mirror-verbosity)
COMPREPLY=($(compgen -W "${verbosities[*]}" -- "$cur"))
;;
--sort) COMPREPLY=($(compgen -W "age rate" -- "$cur")) ;;
--timeout | -t) COMPREPLY=($(compgen -P "$cur" -W "{0..9}")); compopt -o nospace; compopt -o nosort ;;
--ignore | --prefer) COMPREPLY=($(compgen -P "'" -S "'" -W "$(_eos-rankmirrors_GetMirrors)" -- "$cur")) ;;
--mirror-verbosity) COMPREPLY=($(compgen -W "${verbosities[*]}" -- "$cur")) ;;
*)
# Handle all top-level parameters.
case "$cur" in
-* | "")
# Any option or nothing yet.
COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
;;
*)
# Non-option parameters.
;;
esac
;;
case "$cur" in # Handle all top-level parameters.
-* | "")
# Any option or nothing yet.
COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
;;
*)
# Non-option parameters.
;;
esac
;;
esac
} &&
complete -F _eos-rankmirrors_ eos-rankmirrors

0 comments on commit 4b69d04

Please sign in to comment.