You are not logged in.

#1 2017-10-19 19:06:51

handy
Member
Registered: 2011-11-03
Posts: 505

Allservers2: menu, rank/sync mirrors/d'bases upgrade pkgcacheclean

Hi all, I've spent some hours modifying & testing a script I started about ~5 years ago.

It was made for Manjaro & evolved with the upgrade system over there (pacman-mirrors -g). I've modified it to work with the 2 sets of mirrors - Arch & Artix.

From my small amount of testing, it seems to be working fine. (I've used this simple script most everyday since it was born with only a couple of exceptions, so it is just this new bit that I expect can be refined a little & I am always open to suggestions.)

Here is the wiki page for the original allservers - it has an image & plenty of details:

https://wiki.manjaro.org/index.php?titl … .sh_Script

This forum page will detail the differences between the old allservers & the new Arch/Artix based allservers2 :


The way I have my mirrors setup in /etc/pacman.d is as follows:

mirrorlist-artix-original = this currently has all of the artix mirrors in it.
mirrorlist-arch-original = this has only the mirrors for my country & a couple of other countries close by - I'm in Oz.

It is a good idea not to have too many mirrors (just use the typically fastest & perhaps a couple of alternatives to help out if your country's servers are having problems or something...), I'm sure that I will cull the Artix mirrors, though as I write this, Artix is still very much in a process of flux.

What the script does, if any menu option is chosen that is, or includes Option [1]. is to:

(Whether they need it or not) go through each of the 2 mirrorslists mentioned above & remove any quotes from in front of each of the server lines in the lists, & then run the rankmirrors command on them & create 2 new mirrorlists called:

/etc/pacman.d/mirrorlist
/etc/pacman.d/mirrorlist-arch

These guys have the 6 fastest mirrors chosen from the two "-original" mirrorlists. They are listed in order of their speed - fastest first of course.

Then the pacman -Syy command is run to synchronise the systems.

That lot above (apart from the pacman -Syy) is the new part of the script.

This is what that section looks like:

"1")
 echo
 msg "Processing mirrors:"
 echo
 echo
 #wget https://www.archlinux.org/mirrorlist/all/https/ -O /etc/pacman.d/allservers >& /dev/null
 #msg "Editing allservers file"
 #sudo sed -i 's/^#Server/Server/' /etc/pacman.d/allservers
 msg "Removing comments from server lines in mirrorlist-arch-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-arch-original
 msg "Running rankmirrors on mirrorlist-arch(-original)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-arch-original > /etc/pacman.d/mirrorlist-arch
 msg "Removing comments from server lines in mirrorlist-artix-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-artix-original
 msg "Running rankmirrors on mirrorlist(-artix)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-artix-original > /etc/pacman.d/mirrorlist
 msg "Updating your pacman databases"
 echo
 msg "Your mirrors have been ranked &"
 msg "the mirrorlist(s) have now been refreshed."
 echo
 msg "Refreshing your pacman database:"
 sudo pacman -Syy
 echo
 msg "Your mirrors & package database are now synchronised."
 echo
 ;;
 # Note double semicolon to terminate each option.

Choosing other options from the menu, which holds 6 Options alltogether, will allow you to include Option [1], in a couple of them. Each of which will after processing Option [1], do a pacman -Syu --noconfirm or a pacman -Syua --noconfirm followed by a pkgcacheclean which is setup by default to leave 2 versions of packages in your /var/cache/pacman/pkg directory - the one you are using & the previous version (if any). Which is great if you happen to upgrade into trouble (as we all have).

The script (which will follow) needs to be executable (the example is suitable if you have put the script into your /home/<user>/ directory. The other good place to put it is in /usr/bin/ ) :

[handy@notebang ~]$ chmod -v +x ~/allservers2

The script also won't work if the mirrorlists are owned by root (mine weren't - but maybe I changed them & forgot? Do I need to take care of this in the script?).

Here is the script (almost), take it, put it in a text editor, save it to ~/allservers2 (at least at first), make it executable as mentioned above, then copy the following line into your ~/.bashrc so you can call this script by just typing the two keys as into the terminal:

alias as="~/allservers2"
 #!/bin/bash
 ##
 ## 19-10-2017 - handy.
 ## This is a new version of the allserver script that I initially
 ## started building in late ~2012 for Manjaro. This version is for
 ## Arch & Artix based distros. 
 ## The great Manjaro specific "pacman-mirrors -g" command has been
 ## replaced by some messy script to do the same-ish job, in a more
 ## clumsy fashion.
 ##
 ## If your mirrorlists become owned by root, they won't be able to
 ## be operated on by this script. Do I need to cover that in this
 ## script?
 ## 
 ## Run this script from your user $ account as it uses sudo where
 ## required. I use a ~/.bashrc alias to call it, like so:
 ## alias as="~/allservers2"
 ## Then all you have to do is type in the 2 letters "as" without
 ## the quotes, to run the script. :)
 ## It is easiest to put the script in /usr/bin or in ~/ 
 ## & be sure that it has been made executable, like so:
 ## [handy@notebang ~]$ chmod -v +x ~/allservers2
 ##################################################################
 
 err() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    RED="${BOLD}\e[1;31m"
     local mesg=$1; shift
     printf "${RED}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 msg() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    GREEN="${BOLD}\e[1;32m"
     local mesg=$1; shift
     printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
 
 
 # The menu:
 
 clear # Clear the screen.
 
 echo
 echo -e "\e[1;32m                             allservers\e[1;37m2"
 echo
 echo -e " \e[0;33m   Enter Your chosen Option's number \e[0;32m[\e[1;37m?\e[0;32m] \e[4;37mOR\e[0m\e[0;32m hit \e[0;31mReturn\e[0;32m to \e[0;31mexit\e[0;32m. "
 echo
 echo
 echo -e "    [\e[1;37m1\e[0;32m] Rank Mirrors & update mirrorlist\e[0;33m(s)\e[0;32m: \033[0mrank both Arch & Artix mirrors" 
 echo -e "       \e[0;33m &\e[0;32m then sync/refresh package lists: \033[0mpacman -Syy "
 echo
 echo -e "   \e[0;32m [\e[1;37m2\e[0;32m] Option \e[1;37m1\e[0;32m. \e[0;33mplus\e[0;32m Upgrade the System: \033[0mpacman -Syu --noconfirm "
 echo -e "       \e[0;33m &\e[0;32m then run pkgCacheClean: \033[0mpkgcacheclean "
 echo
 echo -e "   \e[0;32m [\e[1;37m3\e[0;32m] Option \e[1;37m1\e[0;32m. \e[0;33mplus\e[0;32m Upgrade the System & AUR: \033[0myaourt -Syua --noconfirm "
 echo -e "       \e[0;33m &\e[0;32m then run pkgCacheClean: \033[0mpkgcacheclean "
 echo
 echo -e "   \e[0;32m [\e[1;37m4\e[0;32m] Upgrade the System only: \033[0mpacman -Syu "
 echo -e "       \e[0;33m &\e[0;32m then run pkgCacheClean: \033[0mpkgcacheclean "
 echo
 echo -e "   \e[0;32m [\e[1;37m5\e[0;32m] Upgrade the System & AUR only: \033[0myaourt -Syua "
 echo -e "       \e[0;33m &\e[0;32m then run pkgCacheClean: \033[0mpkgcacheclean "
 echo
 echo -e "   \e[0;32m [\e[1;37m6\e[0;32m] Delete \e[0;33mdb.lck\e[0;32m after interupted upgrade: \033[0mrm /var/lib/pacman/db.lck "
 echo -e "       \e[0;32m this should remedy the unable to lock database error. "
 echo 
 echo -e "\e[0;33m    Enter the Number of Your Choice: \033[0m"
 echo    
 
 read option
 
 case "$option" in
 # Note variable is quoted.
 
 "1")
 echo
 msg "Processing mirrors:"
 echo
 echo
 #wget https://www.archlinux.org/mirrorlist/all/https/ -O /etc/pacman.d/allservers >& /dev/null
 #msg "Editing allservers file"
 #sudo sed -i 's/^#Server/Server/' /etc/pacman.d/allservers
 msg "Removing comments from server lines in mirrorlist-arch-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-arch-original
 msg "Running rankmirrors on mirrorlist-arch(-original)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-arch-original > /etc/pacman.d/mirrorlist-arch
 msg "Removing comments from server lines in mirrorlist-artix-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-artix-original
 msg "Running rankmirrors on mirrorlist(-artix)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-artix-original > /etc/pacman.d/mirrorlist
 msg "Updating your pacman databases"
 echo
 msg "Your mirrors have been ranked &"
 msg "the mirrorlist(s) have now been refreshed."
 echo
 msg "Refreshing your pacman database:"
 sudo pacman -Syy
 echo
 msg "Your mirrors & package database are now synchronised."
 echo
 ;;
 # Note double semicolon to terminate each option.
 
 "2")
 echo
 msg "Processing mirrors:"
 echo
 echo
 #wget https://www.archlinux.org/mirrorlist/all/https/ -O /etc/pacman.d/allservers >& /dev/null
 #msg "Editing allservers file"
 #sudo sed -i 's/^#Server/Server/' /etc/pacman.d/allservers
 msg "Removing comments from server lines in mirrorlist-arch-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-arch-original
 msg "Running rankmirrors on mirrorlist-arch(-original)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-arch-original > /etc/pacman.d/mirrorlist-arch
 msg "Removing comments from server lines in mirrorlist-artix-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-artix-original
 msg "Running rankmirrors on mirrorlist(-artix)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-artix-original > /etc/pacman.d/mirrorlist
 msg "Updating your pacman databases"
 echo
 msg "Your mirrors have been ranked &"
 msg "the mirrorlist(s) have now been refreshed."
 echo
 msg "Refreshing your pacman database:"
 sudo pacman -Syy
 echo
 msg "Your mirrors & package database are now synchronised."
 echo
 echo
 msg "Upgrading System:"
 echo
 sudo pacman -Syu --noconfirm
 echo
 msg "System upgrade complete."
 echo
 msg "pkgCacheClean will now remove all but the 2 most "
 msg "recent versions of the installation packages in "
 msg "/var/cache/pacman/pkg directory:"
 echo
 sudo pkgcacheclean
 echo
 msg "pkgCacheClean has done its job. "
 echo
 ;;
 # Note double semicolon to terminate each option.
 
 "3")
 echo
 msg "Processing mirrors:"
 echo
 echo
 #wget https://www.archlinux.org/mirrorlist/all/https/ -O /etc/pacman.d/allservers >& /dev/null
 #echo "Editing allservers file"
 #sudo sed -i 's/^#Server/Server/' /etc/pacman.d/allservers
 echo "Removing comments from server lines in mirrorlist-arch-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-arch-original
 echo "Running rankmirrors on mirrorlist-arch(-original)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-arch-original > /etc/pacman.d/mirrorlist-arch
 echo "Removing comments from server lines in mirrorlist-artix-original"
 sudo sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist-artix-original
 echo "Running rankmirrors on mirrorlist(-artix)"
 rankmirrors -n 6 /etc/pacman.d/mirrorlist-artix-original > /etc/pacman.d/mirrorlist
 echo "Updating your pacman databases"
 echo
 msg "Your mirrors have been ranked &"
 msg "the mirrorlist have now been refreshed."
 echo
 msg "Refreshing your pacman database:"
 sudo pacman -Syy
 echo
 msg "Your mirrors & package database are now synchronised."
 echo
 msg "Upgrading System & AUR:"
 echo
 yaourt -Syua --noconfirm
 echo
 msg "System including AUR packages are up to date."
 echo
 msg "pkgCacheClean will now remove all but the 2 most "
 msg "recent versions of the installation packages in "
 msg "/var/cache/pacman/pkg directory:"
 echo
 sudo pkgcacheclean
 echo
 msg "pkgCacheClean has done its job. "
 echo
 ;;
 # Note double semicolon to terminate each option.
 
 "4")
 echo
 msg "Upgrading System:"
 echo
 sudo pacman -Syu
 echo
 msg "System update complete."
 echo
 msg "pkgCacheClean will now remove all but the 2 most "
 msg "recent versions of the installation packages in "
 msg "/var/cache/pacman/pkg directory:"
 echo
 sudo pkgcacheclean
 echo
 msg "pkgCacheClean has done its job. "
 echo
 ;;
 # Note double semicolon to terminate each option.
 
 "5")
 echo
 msg "Upgrading System & AUR: "
 echo
 yaourt -Syua
 echo
 msg "System including AUR packages are up to date. "
 echo
 msg "pkgCacheClean will now remove all but the 2 most "
 msg "recent versions of the installation packages in "
 msg "/var/cache/pacman/pkg directory:"
 echo
 sudo pkgcacheclean
 echo
 msg "pkgCacheClean has done its job. "
 echo
 ;;
 # Note double semicolon to terminate each option.
 
 "6")
 echo
 msg "About to delete /var/lib/pacman/db.lck: "
 echo
 sudo rm /var/lib/pacman/db.lck
 echo
 msg "File db.lck removed, re-attempt your intended installation. "
 echo
 ;;
 # Note double semicolon to terminate each option.
 
 esac
 
 exit 0

Last edited by handy (2017-10-19 22:18:29)

Offline

Board footer

Powered by FluxBB