You are not logged in.

#1 2011-05-31 03:21:24

Archieman
Member
Registered: 2011-01-09
Posts: 25

Script to update your mirrorlist based on up2date mirrors

I got tired of manually updating my mirrorlist file so I wrote a small script today to update my mirrorlist, you might find it useful as well:

NOTE: I assume ZERO responsibility whatsoever for any harm caused by this script and by using it you agree to these terms and conditions. The script assumes you are based in the US, if you are in another country, adjust your URL below.

#!/bin/bash

# Define tmpfile
tmpfile=/tmp/mirrorlisttmp

# Determine architecture type
archtype=$(uname -m)

# Get latest mirror list and save to tmpfile 
wget -O $tmpfile "http://www.archlinux.org/mirrorlist/?country=United+States&protocol=ftp&protocol \
=http&ip_version=4&use_mirror_status=on" >/dev/null 2>&1

# Wrangle txt in saved file
sed -i -e "s/^#Server/Server/g" -e "s/\$arch/"$archtype"/g" $tmpfile

# Backup and replace current mirrorlist file 
if [[ ! -f /etc/pacman.d/mirrorlist.orig ]]; then
  mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig && echo "Successfully backed up original mirrorlist!"
  cp $tmpfile /etc/pacman.d/mirrorlist && echo "Successfully applied new mirrorlist!"
else
  mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak && echo "Successfully backed up current mirrorlist!"
  cp $tmpfile /etc/pacman.d/mirrorlist && echo "Successfully applied new mirrorlist!"
fi

exit

NOTE: You will need to copy the text above, place it into a file (call it updatemirrors.sh), run chmod +x on the file and then run it with sudo/root privileges.

Last edited by Archieman (2011-06-01 01:03:22)


A good solution applied with vigor now is better than a perfect solution applied ten minutes later. - George S. Patton

Offline

#2 2011-05-31 03:32:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Script to update your mirrorlist based on up2date mirrors

You can use [ code ] tags when pasting code https://bbs.archlinux.org/help.php#bbcode
For it to really auto-update the mirrorlist it has to be put in a cronjob :-)

If I run it twice, will the original mirrorlist (moved to mirrorlist.bak after the first run) be irrevocably lost?
Just nitpicking: you don't have to use 'g' for global changes in the sed substitutions as there is only one occurrence per line.

Last edited by karol (2011-05-31 03:43:47)

Offline

#3 2011-05-31 03:52:22

Archieman
Member
Registered: 2011-01-09
Posts: 25

Re: Script to update your mirrorlist based on up2date mirrors

karol wrote:

You can use [ code ] tags when pasting code https://bbs.archlinux.org/help.php#bbcode
For it to really auto-update the mirrorlist it has to be put in a cronjob :-)

If I run it twice, will the original mirrorlist (moved to mirrorlist.bak after the first run) be irrevocably lost?
Just nitpicking: you don't have to use 'g' for global changes in the sed substitutions as there is only one occurrence per line.

Thanks Karol - I made the adjustments above to address both comments. The 'g' for sed I think is OK to leave in :-)

Last edited by Archieman (2011-05-31 04:00:55)


A good solution applied with vigor now is better than a perfect solution applied ten minutes later. - George S. Patton

Offline

#4 2011-08-14 07:12:06

amindamok
Member
Registered: 2011-08-13
Posts: 7

Re: Script to update your mirrorlist based on up2date mirrors

Just wanted to say thank you for this script.  It worked exactly as you described it.  Unlike the script listed in the Beginners Guide.  Thank you, thank you, thank you.


------------------------------------------------------------------------------------------------------------
"Computers are useless.  They can only give you answers."  Pablo Picasso

Offline

#5 2011-08-14 08:04:56

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Script to update your mirrorlist based on up2date mirrors

One minor comment - you don't need to replace the $arch variable with the actual architecture. Just make sure Architecture is set correctly in pacman.conf.

Last edited by tomk (2011-08-14 08:05:22)

Offline

#6 2011-08-14 15:03:57

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,652

Re: Script to update your mirrorlist based on up2date mirrors

Moderator comment: 
Archieman,
"My first inclination is to move this thread to community contributions -- Although I understand why you opened it and concur this sub-forum may be a more appropriate location.  I'll leave it here for now, but give me your thoughts


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#7 2011-08-14 23:44:27

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: Script to update your mirrorlist based on up2date mirrors

@Archieman - Thanks for this script. Makes a simple replacement for reflector smile

Offline

Board footer

Powered by FluxBB