Skip to content

Commit

Permalink
[reflector-simple] supporting option --threads; optimizing some defau…
Browse files Browse the repository at this point in the history
…lt parameters
  • Loading branch information
EndeavourOS committed Sep 13, 2023
1 parent 047ed7d commit 23aa003
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
4 changes: 2 additions & 2 deletions reflector-simple/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pkgname=reflector-simple
pkgdesc="Simple GUI wrapper for 'reflector'."
pkgver=2023
pkgrel=3
pkgrel=4
arch=('any')
license=('GPL')
depends=(
Expand Down Expand Up @@ -33,7 +33,7 @@ source=(
$_url/mirrorlist-rank-info
$_url/eos-latest-arch-mirrorlist
)
sha512sums=('e484f00529cc65f4f76ae7bcb88628ae4b76e6ac8f1d914d3f21a919d8c165dd9ade74ecc35608a3490e780fc22348b7c589c9c7975512d78d8d8eee7e9d6fe6'
sha512sums=('957e5c8967083d031a032f870edbdd36b34f2149d5cbaa10452a3fbdc3f4d42523b8c1e5a5222d36a12922a70ef804699c03f669e33148484c107cc0eb091825'
'3435d083e8df72f17a291cca4c3cc62ac7824d1f528e746bf689f8962159fbdd97b6a57d45b3b379a2191e2e49536b77040b13d704a58753fbed00017f4403d0'
'aa149c8fc273e6a9fb5ddc38bde8a37b8fb095ec8877a324b957be57e156ef583adbed5988f0184ef06d5d09ec13e01e4a58b81fffef5d6d316405a3881895c3'
'8b101caac9f38238d30f293176a09f1bb483ec1cdc474ef126ec087a8b548b50eee5c35617f0616dd1618e4dce72e14b70270f47658577e20e04a133405510aa'
Expand Down
64 changes: 47 additions & 17 deletions reflector-simple/reflector-simple
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,27 @@ ChangeNamesToCodes() {
FixCountryName() { # simple fix to country name to be the same as in 'reflector --list-countries'
local name="$1"

if [ -z "$(CountryToCode "$name")" ] ; then
local official_name
name=${name,,} # make lowercase
for official_name in "${countrynames[@]}" ; do
if [ "$name" = "${official_name,,}" ] ; then
name="$official_name"
break
fi
done
if [ -n "$(CountryToCode "$name")" ] ; then
echo "$name"
return 0
fi
echo "$name"
local official_name
name=${name,,} # make lowercase
for official_name in "${countrynames[@]}" ; do
if [ "$name" = "${official_name,,}" ] ; then
echo "$official_name"
return 0
fi
done
return 1 # country name not found!
}

ToCountryName() {
local item="$1"
case "$item" in
[a-zA-Z][a-zA-Z]) CodeToCountry "$item" ;;
*) FixCountryName "$item" ;;
esac
}

IsInSelectedCountries() {
Expand Down Expand Up @@ -382,10 +392,9 @@ IsPositiveNumber() {

AskCountriesAndOptions() {
local tips=(
"Select countries to include in mirror ranking"
" - select one or more countries"
" - closest locations are usually the fastest"
" - https is the preferred protocol"
"Mirror ranking preferences"
" - select one or more <i>countries</i>"
" - select <i>features</i> based on your preferences"
)
if [ -r "$REFLECTOR_X_CONF" ] ; then
tips+=("\nNote: configuration file <b>$REFLECTOR_X_CONF</b> options are in use.")
Expand All @@ -396,7 +405,7 @@ AskCountriesAndOptions() {
local command
local default_age=2
local default_sort='age!^rate!country!score!delay'
local default_number=10
local default_number=20
local use_saved=""

Verbose "Creating the yad command..."
Expand Down Expand Up @@ -459,6 +468,8 @@ AskCountriesAndOptions() {
fi
command+=(--field="Download timeout in seconds":num 5) # --download-timeout

command+=(--field="Threads":num 5) # --threads

local free_params=""
if [ -r "$free_params_file" ] ; then
free_params="$(/usr/bin/cat "$free_params_file" | tr '\n' ' ')"
Expand Down Expand Up @@ -545,15 +556,34 @@ BuildReflectorCommand() {
fi
((ix++))
reflector_cmd+=(--download-timeout "${reflector_info[$((ix++))]}")
reflector_cmd+=(--threads "${reflector_info[$((ix++))]}")

# add optional free parameters to the command and save free params to file
printf "" > "$free_params_file"
local prev=""
local item items=()
while true ; do
xx="${reflector_info[$((ix++))]}"
[ -n "$xx" ] || break
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
;;
esac
reflector_cmd+=("$xx")
echo "$xx" >> "$free_params_file"
done

# echo "${reflector_cmd[*]}" > /tmp/foobar
}

ShowMirrorlistSaved() {
Expand Down Expand Up @@ -751,7 +781,7 @@ Main() {
local countrynames
local countrycodes
local reflector_info
local reflector_cmd
local reflector_cmd=()
local ml=/etc/pacman.d/mirrorlist
local conf_selected_countries=()
local conf_dropped_countries=()
Expand Down

0 comments on commit 23aa003

Please sign in to comment.