From e3db86ebcdf95f688656a1a4a34e60f5043edbca Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Thu, 1 Jun 2023 16:44:22 -0500 Subject: [PATCH] change: Only ask for sudo access at the end --- get-best-mirrors.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/get-best-mirrors.sh b/get-best-mirrors.sh index 96c95fd..3e95db1 100644 --- a/get-best-mirrors.sh +++ b/get-best-mirrors.sh @@ -6,19 +6,27 @@ # I run it weekly using anacron. update_arch() { + # Create temporary file to output to + TMPFILE_ARCH="$(mktemp)" + # Rank Arch mirrors echo "====================================================================================================" echo "Ranking Arch mirrors" echo "====================================================================================================" rate-mirrors --protocol=https --save=$TMPFILE_ARCH arch + + # Create backup directory if not present already + sudo mkdir -p /etc/pacman.d/mirrorlist-backup + + # Place the new mirrorlist and do a backup sudo mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist-backup/mirrorlist.$TIME sudo mv $TMPFILE_ARCH /etc/pacman.d/mirrorlist } update_eos() { - # Remove files created by eos-rankmirror, if any - sudo find /etc/pacman.d/ -maxdepth 1 -type f -name "endeavouros-mirrorlist\.*" -exec rm -v {} \; + # Create temporary file to output to + TMPFILE_EOS="$(mktemp)" # Rank EndeavourOS mirrors echo $'\n'"====================================================================================================" @@ -26,20 +34,21 @@ update_eos() { echo "====================================================================================================" rate-mirrors --protocol=https --save=$TMPFILE_EOS endeavouros + + # Create backup directory if not present already + sudo mkdir -p /etc/pacman.d/mirrorlist-backup + + # Place the new mirrorlist and do a backup sudo mv /etc/pacman.d/endeavouros-mirrorlist /etc/pacman.d/mirrorlist-backup/endeavouros-mirrorlist.$TIME sudo mv $TMPFILE_EOS /etc/pacman.d/endeavouros-mirrorlist -} -# Create temporary files to output to -TMPFILE_ARCH="$(mktemp)" -TMPFILE_EOS="$(mktemp)" + # Remove files created by eos-rankmirror, if any + sudo find /etc/pacman.d/ -maxdepth 1 -type f -name "endeavouros-mirrorlist\.*" -exec rm -v {} \; +} # Get the current time TIME="$(date '+%Y.%m.%d-%H.%M.%S')" -# Create backup directory if not present already -sudo mkdir -p /etc/pacman.d/mirrorlist-backup - if [ "$1" == "arch" ]; then update_arch elif [ "$1" == "eos" ]; then