From 89c4a0375ccd29d37db33ba59dc630276abff2ba Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 18 Jul 2024 17:41:04 +0300 Subject: [PATCH] [reflector-simple] by default prefer age over rate; small fixes for additional options; some code reorganization --- reflector-simple/PKGBUILD | 4 +- reflector-simple/reflector-simple | 252 ++++++++++++++++-------------- 2 files changed, 141 insertions(+), 115 deletions(-) diff --git a/reflector-simple/PKGBUILD b/reflector-simple/PKGBUILD index b89240aa..2595fe4b 100644 --- a/reflector-simple/PKGBUILD +++ b/reflector-simple/PKGBUILD @@ -2,7 +2,7 @@ pkgname=reflector-simple pkgdesc="Simple GUI wrapper for 'reflector'." -pkgver=2024 +pkgver=2024.7 pkgrel=1 arch=('any') license=('GPL') @@ -33,7 +33,7 @@ source=( $_url/mirrorlist-rank-info $_url/eos-latest-arch-mirrorlist ) -sha512sums=('e13ac2cdb1196b90d713b5ac614647f7840e38555d651dea247c0fbc37dca43170952cbebb10d3c2b09660a870dcc1bdae56d1e7531b5809df931206d901f441' +sha512sums=('073d390cff6842aec69e79875718425982bcc2049f3084bd352e9a4a5a31a94bf3989e61004fcdfc1b980ca1135b1e10c4505e5ec0f968773cf1a3dbb74be117' '3435d083e8df72f17a291cca4c3cc62ac7824d1f528e746bf689f8962159fbdd97b6a57d45b3b379a2191e2e49536b77040b13d704a58753fbed00017f4403d0' 'aa149c8fc273e6a9fb5ddc38bde8a37b8fb095ec8877a324b957be57e156ef583adbed5988f0184ef06d5d09ec13e01e4a58b81fffef5d6d316405a3881895c3' '8b101caac9f38238d30f293176a09f1bb483ec1cdc474ef126ec087a8b548b50eee5c35617f0616dd1618e4dce72e14b70270f47658577e20e04a133405510aa' diff --git a/reflector-simple/reflector-simple b/reflector-simple/reflector-simple index a6649986..7bb3d3d9 100755 --- a/reflector-simple/reflector-simple +++ b/reflector-simple/reflector-simple @@ -198,8 +198,9 @@ _config_country() { GetListToken() { local -n __lista__=$1 local -n __token__=$2 - __token__="$(echo "$__lista__" | cut -d ',' -f 1)" - __lista__="$(echo "$__lista__" | sed 's|^[^,]*[,]*||')" + __token__=${__lista__%%,*} # first token + __lista__=${__lista__#$__token__} # remove first token from list + __lista__=${__lista__#,} # remove first , from list } Destructor() { @@ -209,6 +210,82 @@ Destructor() { # Conf limitations: # - nothing known! +Usage() { + if true ; then + cat < "$free_params_file" - local prev="" - local item items=() + local free_pars=() + local next="" while true ; do xx="${reflector_info[$((ix++))]}" + + [ "$xx" ] || break + + reflector_cmd+=("$xx") + free_pars+=("$xx") + case "$xx" in - "") break ;; - -c) prev="-c" ;; - *) case "$prev" in - -c) - # $xx may need some adjustment - readarray -t items <<< $(echo "$xx" | tr ',' '\n') - for item in "${items[@]}" ; do - conf_selected_countries+=("$(ToCountryName "$item")") - done - prev="" - ;; - esac + -c | --country) + next="${reflector_info[$((ix++))]}" + reflector_cmd+=("$next") + free_pars+=("$next") + AdjustCountries + ;; + -c=* | --country=*) + next=${xx#*=} + AdjustCountries + ;; + -c*) + next=${xx:2} + AdjustCountries ;; esac - reflector_cmd+=("$xx") - echo "$xx" >> "$free_params_file" done - - # echo "${reflector_cmd[*]}" > /tmp/foobar + echo "${free_pars[@]}" > "$free_params_file" +} +AdjustCountries() { # put countries in $next to $conf_selected_countries + local items=() item + readarray -t items <<< $(echo "$next" | tr ',' '\n') + for item in "${items[@]}" ; do + conf_selected_countries+=("$(ToCountryName "$item")") + done + next="" } ShowMirrorlistSaved() { @@ -600,19 +630,12 @@ AddCountryNamesToMirrors() { local full_list=$(mktemp) Verbose "Fetching Arch mirror list..." - if [ 0 -eq 1 ] ; then - curl -Lsm 10 -o $full_list $ARCH_SITE/mirrorlist/all || { - WARN "cannot fetch Arch mirror list." - rm -f $full_list - return 1 - } - else - eos-latest-arch-mirrorlist $full_list || { - WARN "cannot fetch Arch mirror list." - rm -f $full_list - return 1 - } - fi + eos-latest-arch-mirrorlist $full_list || { + WARN "cannot fetch Arch mirror list." + rm -f $full_list + return 1 + } + Verbose "done." local selected_mirrors=$(grep "^Server = " $tmpfile | awk '{print $3}') @@ -793,6 +816,7 @@ Main() { local conf_protocol=() local worldwide_selected=0 local use_number_instead_of_latest="$REFLECTOR_SIMPLE_PREFER_NUMBER" # from exported env var + local threads="" local https_selected=0 local http_selected=0 local rsync_selected=0 @@ -849,23 +873,7 @@ Main() { ) Verbose "Starting ranking..." - "${reflector_cmd[@]}" 2>&1 > $tmpfile | tee $ranklog | { - local line="" - local max_lines="$_MAX_MIRROR_LINES_TO_SHOW" - local value=0 - local line_count=-2 - while read line ; do - if [[ "$line" != *"WARNING:"* ]]; then - ((line_count++)) - fi - echo "#$line" - if [ "$line_count" -ge 0 ]; then - value=$(( line_count*100/max_lines )) - echo "$(( value < 100 ? value : 99 ))" - fi - done - echo 100 - } | "${progress_cmd[@]}" + "${reflector_cmd[@]}" 2>&1 > $tmpfile | tee $ranklog | RankProgress "$_MAX_MIRROR_LINES_TO_SHOW" | "${progress_cmd[@]}" Verbose "done." if [ "$use_pulsating_indicator" = "yes" ] ; then @@ -884,4 +892,22 @@ Main() { fi } +RankProgress() { + local max_lines="$1" + local line="" + local value=0 + local line_count=-2 + while read line ; do + if [[ "$line" != *"WARNING:"* ]]; then + ((line_count++)) + fi + echo "#$line" + if [ "$line_count" -ge 0 ]; then + value=$(( line_count*100/max_lines )) + echo "$(( value < 100 ? value : 99 ))" + fi + done + echo 100 +} + Main "$@"