1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-26 05:08:36 -06:00

change: Only ask for sudo access at the end

This commit is contained in:
Sayantan Santra 2023-06-01 16:44:22 -05:00
parent a9a52f6ebe
commit e3db86ebcd
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F

View file

@ -6,19 +6,27 @@
# I run it weekly using anacron. # I run it weekly using anacron.
update_arch() { update_arch() {
# Create temporary file to output to
TMPFILE_ARCH="$(mktemp)"
# Rank Arch mirrors # Rank Arch mirrors
echo "====================================================================================================" echo "===================================================================================================="
echo "Ranking Arch mirrors" echo "Ranking Arch mirrors"
echo "====================================================================================================" echo "===================================================================================================="
rate-mirrors --protocol=https --save=$TMPFILE_ARCH arch 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 /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist-backup/mirrorlist.$TIME
sudo mv $TMPFILE_ARCH /etc/pacman.d/mirrorlist sudo mv $TMPFILE_ARCH /etc/pacman.d/mirrorlist
} }
update_eos() { update_eos() {
# Remove files created by eos-rankmirror, if any # Create temporary file to output to
sudo find /etc/pacman.d/ -maxdepth 1 -type f -name "endeavouros-mirrorlist\.*" -exec rm -v {} \; TMPFILE_EOS="$(mktemp)"
# Rank EndeavourOS mirrors # Rank EndeavourOS mirrors
echo $'\n'"====================================================================================================" echo $'\n'"===================================================================================================="
@ -26,20 +34,21 @@ update_eos() {
echo "====================================================================================================" echo "===================================================================================================="
rate-mirrors --protocol=https --save=$TMPFILE_EOS endeavouros 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 /etc/pacman.d/endeavouros-mirrorlist /etc/pacman.d/mirrorlist-backup/endeavouros-mirrorlist.$TIME
sudo mv $TMPFILE_EOS /etc/pacman.d/endeavouros-mirrorlist sudo mv $TMPFILE_EOS /etc/pacman.d/endeavouros-mirrorlist
}
# Create temporary files to output to # Remove files created by eos-rankmirror, if any
TMPFILE_ARCH="$(mktemp)" sudo find /etc/pacman.d/ -maxdepth 1 -type f -name "endeavouros-mirrorlist\.*" -exec rm -v {} \;
TMPFILE_EOS="$(mktemp)" }
# Get the current time # Get the current time
TIME="$(date '+%Y.%m.%d-%H.%M.%S')" 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 if [ "$1" == "arch" ]; then
update_arch update_arch
elif [ "$1" == "eos" ]; then elif [ "$1" == "eos" ]; then