Skip to content

Commit

Permalink
[eos-bash-shared] eos-update: if --check-mirrors detects a bad mirror…
Browse files Browse the repository at this point in the history
…, move cursor to the faulty line when editing the list
  • Loading branch information
manuel-192 committed Aug 10, 2024
1 parent 8edec09 commit 96edbd9
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions eos-update
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ MirrorCheckResult() {
local ret=0

echo2 "==> $ml contains:"
echo2 " known mirrors: ${#supported[@]}"
if [ ${#unsupported[@]} -eq 0 ] ; then
echo2 " unknown mirrors: 0"
else
echo2 " unknown or offline mirrors: ${#unsupported[@]}"
printf "%s\n" "${unsupported[@]}" | sed 's|^| Server = |'
fi
echo2 " available mirrors: ${#supported[@]}"
echo2 " unavailable mirrors: ${#unsupported[@]}"
[ ${#unsupported[@]} -gt 0 ] && printf "%s\n" "${unsupported[@]}" | sed 's|^[0-9]*:| -> Server = |' >&2

if [ ${#unsupported[@]} -eq 0 ] && [ ${#supported[@]} -gt 0 ] ; then # create the return code, 0=success, 1=fail
return 0
else
EditMirrorlist $ml
if [ ${#unsupported[@]} -gt 0 ] ; then
EditMirrorlist $ml "${unsupported[0]%%:*}" # second parameter is the line number
else
EditMirrorlist $ml
fi
return 1
fi
}
Expand All @@ -58,13 +59,13 @@ CheckYourArchMirrorlist() {
readarray -t all_working_mirrors <<< $(echo "$all_working_mirrors" | tail -n +7 | grep "^#Server = " | awk '{print $NF}')

# get mirrors from local mirrorlist
readarray -t local_mirrors <<< $(grep "^[ \t]*Server[ \t]*=[ \t]*" $aml | awk '{print $NF}')
readarray -t local_mirrors <<< $(grep -n "^[ \t]*Server[ \t]*=[ \t]*" $aml | sed 's|[ \t]*Server[ \t]*=[ \t]*||')

for lm in "${local_mirrors[@]}" ; do
if printf "%s\n" "${all_working_mirrors[@]}" | grep "$lm" >/dev/null ; then
supported+=("$lm")
if printf "%s\n" "${all_working_mirrors[@]}" | grep "${lm#*:}" >/dev/null ; then
supported+=("${lm#*:}")
else
unsupported+=("$lm")
unsupported+=("$lm") # includes the line number: "nr:https://..."
fi
done
MirrorCheckResult $aml
Expand Down Expand Up @@ -105,13 +106,13 @@ CheckYourEndeavourosMirrorlist() {

good_mirrors=$(tar xvf $tmpfile ${eml:1} -O 2>/dev/null | grep "^Server = " | sed 's|^Server = ||')
rm -f $tmpfile
local_mirrors=$(grep "^[ \t]*Server[ \t]*=[ \t]*" $eml | sed 's|^Server = ||')
local_mirrors=$(grep -n "^[ \t]*Server[ \t]*=[ \t]*" $eml | sed 's|[ \t]*Server[ \t]*=[ \t]*||')

for lm in $local_mirrors ; do
if [ "$(echo "$good_mirrors" | grep "$lm")" ] ; then
supported+=($lm)
if [ "$(echo "$good_mirrors" | grep "${lm#*:}")" ] ; then
supported+=(${lm#*:})
else
unsupported+=($lm)
unsupported+=($lm) # includes the line number: "nr:https://..."
fi
done
MirrorCheckResult $eml
Expand All @@ -124,16 +125,25 @@ CheckYourEndeavourosMirrorlist() {
}

EditMirrorlist() {
local list="$1" # arch, endeavouros, or the full path of the mirrorlist
local editor=$(EosSudoEditor)
local ml
[ "$editor" ] || DIE "suitable editor (for root) not found, please check variable EOS_SUDO_EDITORS in /etc/eos-script-lib-yad.conf"
local list="$1" # arch, endeavouros, or the full path of the mirrorlist
local linenr="$2" # for the editor; may be empty
local editor=/usr/bin/rnano
[ -x $editor ] || { WARN "package 'nano' is required for editing $list"; return 1; }

case "$list" in
arch | $aml) ml="$aml" ;;
endeavouros | $eml) ml="$eml" ;;
arch | $aml) list="$aml" ;;
endeavouros | $eml) list="$eml" ;;
"") DIE "supported mirrorlists: arch, endeavouros" ;;
esac
RunInTerminal "echo 'Starting to edit $ml:'; sudo $editor $ml"
if [ "$linenr" ] ; then
if [ -z "${linenr//[0-9]/}" ] ; then
linenr="+$linenr"
else
WARN "detected line number '$linenr' in $list is flawed!"
linenr=""
fi
fi
RunInTerminal "echo 'Starting to edit $list:'; sudo $editor $linenr $list"
}

ResetKeyrings() {
Expand Down

0 comments on commit 96edbd9

Please sign in to comment.