giladh

Arch Linux Pacman Mirror Updater

Jul 6th, 2011
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.97 KB | None | 0 0
  1. #!/bin/bash -e
  2. #
  3. #This script automatically updates the mirrorlist for Arch Linux based on the most responsive and up-to-date mirrors available
  4.  
  5. # Define TMPFILE
  6. TMPFILE="/tmp/mirrorlisttmp"
  7.  
  8. # Determine architecture type
  9. ARCHTYPE=$(uname -m)
  10.  
  11. # Get latest mirror list and save to TMPFILE
  12. 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
  13.  
  14. # Wrangle txt in saved file
  15. sed -i -e "s/^#Server/Server/g" -e "s/\$arch/"$ARCHTYPE"/g" "$TMPFILE"
  16.  
  17. # Backup and replace current mirrorlist file
  18. if [[ ! -f "/etc/pacman.d/mirrorlist.orig" ]]; then
  19.   mv "/etc/pacman.d/mirrorlist" "/etc/pacman.d/mirrorlist.orig"
  20.   cp "$TMPFILE" "/etc/pacman.d/mirrorlist"
  21. else
  22.   mv "/etc/pacman.d/mirrorlist" "/etc/pacman.d/mirrorlist.bak" && echo "Successfully backed up mirrorlist!"
  23.   cp "$TMPFILE" "/etc/pacman.d/mirrorlist" && echo "Successfully applied new mirrorlist!"
  24. fi
  25.  
  26. exit
Advertisement
Add Comment
Please, Sign In to add comment