Skip to content

Commit

Permalink
[eos-rankmirrors] added option --mirror-add for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
EndeavourOS committed Aug 26, 2023
1 parent b86fd26 commit e55d403
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 75 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 <info@endeavouros.com>

pkgname=eos-rankmirrors
pkgver=2.16
pkgver=2.17
pkgrel=1
pkgdesc="EndeavourOS mirror ranking tool"
arch=('any')
Expand All @@ -21,8 +21,8 @@ source=(
$url/eos-rankmirrors.hook
$url/eos-rankmirrors.conf
)
sha512sums=('bbebae66df3a853a62b5acc46240ef72c44de33f913c2f2f4c61f73bd604139e70f9b264ffbc20571b7f0f975704d6fd3a984e42a440a750dd8d02523cf7855d'
'e0cc7bbd4644574810c19b18cb57098f62011aeb2f5b115a16d78489efbf7f74eab411bd31eaf233e4380916b4890472dd23e17ccc0ef4a0f456321c414dc9e2'
sha512sums=('b5f2772ea00eff6bc59d3d1a708f491ee28a4db4ad88bed4fe01b9e74b62849810fa0e22e517a38527b2512d88505c13f987f49f930e3b0bfe714b7f1579f67c'
'476c232dcabdd55f9fd0200e3a428aeb99a867f3b5c475711bd4e0e553c3a4149daa90436f0aaf397c1865888f8746b82deb1d70dff4cfde2b55776359f95c3a'
'580511c676cf56b5b8580d6819e0d1a4c85a40a3cd10f4b4f04fb9c004b14025b56cf4c3048e0fe8f9eef48d924b32b97d1e9669fac39b96f4203e2d68e3bd07'
'f01f6267f624992febfec29c76f2de1c503693086ade5783e2b9cbef359f5155bf6df520ff06299193c842aef2a05cac5078977ee0dabf55cff66f44aec6e44a'
'226111836a42e3540c714105813f64b285b3c48d41ea058e7339ba5b2de530a691d753b8f6d10984d260ed3288b01539715b00ad9bef4d808d21303c936837e7')
Expand Down
135 changes: 76 additions & 59 deletions eos-rankmirrors/eos-rankmirrors
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ SortMirrors() {

readarray -t marr <<< $(grep "^Server = " $latest_ml)

[ -n "$added_mirror" ] && marr+=("Server = $added_mirror") # for test-ranking a mirror

lastix=${#marr[@]}
while [ $lastix -gt 0 ] ; do
((lastix--))
Expand Down Expand Up @@ -360,63 +362,31 @@ WriteSystemMirrorlist() {
esac
}

#MakeShortOptions() { echo "$1" | sed -E -e 's|([a-zA-Z])|-\1 |g' -e 's| :|:|g' ; }
#MakeLongOptions() { $(echo "--""$LONG_OPTIONS" | sed -E 's|,| --|g') ; }

DumpOptions() {
local all_user_options=(
--help -h
--ignore
--mirror-verbosity
--no-save -n
--prefer
--sort
--timeout -t
--use-local-mirrorlist
--verbose
local user_options=(
$(echo "$SHORT_OPTIONS" | sed -E -e 's|([a-zA-Z])|-\1 |g' -e 's| :|:|g')
$(echo "--""$LONG_OPTIONS" | sed -E 's|,| --|g')
)
local internal_options=(
$(echo "--""$LONG_OPTIONS_INTERNAL" | sed -E 's|,| --|g')
)
echo "${all_user_options[*]}"
case "$1" in
--all) echo "${user_options[*]} ${internal_options[*]}" ;;
*) echo "${user_options[*]}"
esac
exit 0
}

Options() {
local opts
local longopts="verbose,help,_help_,no-save,timeout:,sort:,hook-rank,ignore:,prefer:,mirror-verbosity:,dump-options,use-local-mirrorlist,list-only"

opts=$(getopt -o=hnt: --longoptions $longopts --name "$progname" -- "$@")
case "$?" in
0) ;;
*) DIE "getopt detected unsupported option, cannot continue." ;;
esac

eval set -- "$opts"

while true ; do
case "$1" in
# internal tool options:
--hook-rank)
hook_rank=yes
;;
--dump-options)
DumpOptions
;;
--_help_)
cat <<EOF
Usage() {
cat <<EOF
Usage: $progname [options]
Options:
--sort <value>
Primary key for sorting the mirrors.
Supported key values:
age (latest first)
rate (fastest first)
Default: $sort_default.
--timeout <value>
-t <value>
Set the timeout value (in seconds) for checking a mirror.
Default: $timeout_default.
--no-save
-n
Don't save the generated mirrorlist.
--help, -h
This help.
--ignore '<wordlist>'
Mirrors to be ignored from the result.
Expand All @@ -428,6 +398,14 @@ Options:
Example:
eos-rankmirrors --ignore='funami|pizza'
--mirror-verbosity <value>
How much information will be shown when a mirror fails.
Supported values: see file /etc/eos-rankmirrors.conf, setting
EOS_RANKMIRRORS_EXIT_CODE_VERBOSITY.
--no-save, -n
Don't save the generated mirrorlist.
--prefer '<list-of-mirrors>'
List of preferred mirror addresses.
Adds given mirror addresses as the first in the EndeavourOS mirrorlist.
Expand All @@ -436,27 +414,60 @@ Options:
Note that the list must be enclosed in single quotes.
Example:
eos-rankmirrors --prefer='https://endeavour.remi.lu/repo/\$repo/\$arch'
--sort <value>
Primary key for sorting the mirrors.
Supported key values:
age (latest first)
rate (fastest first)
Default: $sort_default.
--timeout, -t <value>
Set the timeout value (in seconds) for checking a mirror.
Default: $timeout_default.
--use-local-mirrorlist
For testing purposes.
Uses information in local $mlfolder/$pkgname as the base for ranking.
--verbose
Show more detailed output.
EOF
}

--mirror-verbosity <value>
How much information will be shown when a mirror fails.
Supported values: see file /etc/eos-rankmirrors.conf, setting
EOS_RANKMIRRORS_EXIT_CODE_VERBOSITY.
Options() {
local opts

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

eval set -- "$opts"

while true ; do
case "$1" in
# internal tool options:
--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"
;;

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

Expand Down Expand Up @@ -505,11 +516,16 @@ Check-mirror_verbosity() {

Main()
{
local -r SHORT_OPTIONS="hnt:"
local -r LONG_OPTIONS="verbose,help,no-save,timeout:,sort:,ignore:,prefer:,mirror-verbosity:,use-local-mirrorlist"
local -r LONG_OPTIONS_INTERNAL="dump-options::,hook-rank,list-only,mirror-add:"

case "$1" in
--dump-options) DumpOptions ;;
--dump-options=all) DumpOptions --all ;;
esac

local -r progname="$(basename "$0")"
local -r progname="${0##*/}"
local -r pkgname=endeavouros-mirrorlist
local -r mlfolder=/etc/pacman.d
local eos=$mlfolder/$pkgname
Expand All @@ -528,6 +544,7 @@ Main()
local mirror_verbosity=""
local use_local_mirrorlist=no
local mirrorlist_only=no # 'no' provides rather verbose output, 'yes' provides only the essential list
local added_mirror=""

if [ ! -r "$eos" ] ; then # this test is not really needed...
DIE "no local $eos found, please install package '$pkgname'."
Expand Down
25 changes: 12 additions & 13 deletions eos-rankmirrors/eos-rankmirrors.completion
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,34 @@ GetMirrors() {
# Grab endeavouros-mirrorlist from the latest package.
# First try the package cache. If no luck, fetch it from github/gitlab.

local pkgname=endeavouros-mirrorlist
local pkg=$(ls -1 /var/cache/pacman/pkg/${pkgname}-*.zst 2>/dev/null | tail -n1)
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=$(pacman -Q $pkgname | awk '{print $2}')
if [ "$cachev" = "$installedv" ] ; then
#
# 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
# fi
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 url="$(eos-github2gitlab --keep-master "https://raw.githubusercontent.com/endeavouros-team/PKGBUILDS/master/$pkgname/$pkgname")"
local timeout=5 # not too long...
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
}

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

# local opts=( --help -h --sort --ignore --prefer --timeout -t --verbose --mirror-verbosity --no-save -n )
local opts="$(eos-rankmirrors --dump-options)" # alternative, slower

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

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

0 comments on commit e55d403

Please sign in to comment.