From 1a26a0a2b162f2b0b43a0aac404ad45d22157038 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Mon, 2 Nov 2015 23:01:08 +0100 Subject: [PATCH] Add a script to update pacman's mirror list. --- .zshrc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.zshrc b/.zshrc index ed3f7e6..84b5232 100644 --- a/.zshrc +++ b/.zshrc @@ -106,3 +106,29 @@ clean() unfunction clean_dir } + +if hash rankmirrors 2>/dev/null; then + update_mirrorlist() + { + local pacman_dir="/etc/pacman.d" + local mirror_file="$pacman_dir/mirrorlist" + local mirror_pacnew="$mirror_file.pacnew" + local mirror_orig="$mirror_file.orig" + local mirror_tmp="/tmp/mirrorlist.tmp" + + if [ -f "$mirror_pacnew" ]; then + echo "Using $mirror_file" + mv "$mirror_pacnew" "$mirror_orig" + fi + + if [ ! -f "$mirror_orig" ]; then + echo "$mirror_orig: file not found" >&2 + exit 1 + fi + + /usr/bin/grep 'Server' "$mirror_orig" | tr -d "#" > "$mirror_tmp" + rankmirrors -n 6 "$mirror_tmp" > "$mirror_file" + rm -f "$mirror_tmp" + pacman -Syy + } +fi