Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Paste Description for pacmrr

Pacman ranked mirror script

pacmrr
Saturday, June 22nd, 2013 at 2:55:44am UTC 

  1. #!/bin/bash
  2. # Download pacman ranked mirror list
  3.  
  4. # Country codes: AU AT BY BE BR BG CA CL CN CO CZ DK EE FI FR DE GR HU IN IE IL
  5. # IT JP KZ KR LV LU MK NL NC NZ NO PL PT RO RU RS SG SK ZA ES LK SE CH TW TR
  6. # UA GB US UZ VN
  7. country='US'
  8. url="https://www.archlinux.org/mirrorlist/?country=US&protocol=http&ip_version=4&use_mirror_status=on"
  9.  
  10. # Download
  11. tmp_ml=$(mktemp --suffix=-mirrorlist)  # temporary mirrorlist
  12. if curl -s "$url" -o "$tmp_ml"; then
  13.   if ! grep "^## Arch Linux repository mirrorlist" "$tmp_ml" > /dev/null; then
  14.     echo " Error: Download invalid"
  15.     exit 1
  16.   fi
  17. else
  18.   echo " Error: Download failed"
  19.   exit 1
  20. fi
  21.  
  22. # Edit
  23. sed -i 's/^#Server/Server/g'          "$tmp_ml"
  24.  
  25. # View
  26. while true; do
  27.   read -p " View the downloaded mirrorlist? (y/n): " yn
  28.   case $yn in
  29.     [Yy] )  if hash vim 2>&- ; then # use vim if available
  30.               editor=vim
  31.               editop=$(printf '%s' +"set syn=sh");
  32.             else
  33.               editor=nano; fi
  34.             "$editor" "$editop" "$tmp_ml"
  35.             break 2 ;;
  36.     [Nn] )  break 2 ;;
  37.     [*]  )  true
  38.   esac
  39. done
  40.  
  41. # Permission test
  42. prm_tst () {
  43. if [ "$UID" != 0 ] && [ ! hash sudo 2>&- ] ; then
  44.   echo " Program "sudo" required for regular user"
  45.   exit 1
  46. else
  47.   sudo=sudo
  48. fi ; }
  49.  
  50. # Backup and Install
  51. bck_ml () {
  52. if [ -f /etc/pacman.d/mirrorlist ]; then
  53.   $sudo mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist_$(date +%Y%m%d%H%M)
  54. else
  55.   echo " Warning: no /etc/pacman.d/mirrorlist"
  56. fi ; }
  57.  
  58. while true; do
  59.   read -p " Install new mirrorlist and backup previous? (y/n): " yn
  60.   case $yn in
  61.     [Yy] )  prm_tst
  62.             bck_ml
  63.             $sudo install -Dm644 "$tmp_ml" /etc/pacman.d/mirrorlist
  64.             break 2 ;;
  65.     [Nn] )  break 2 ;;
  66.     [*]  )  true
  67.   esac
  68. done

Paste Details

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right