Skip to main content
Topic: Allservers2 - a bash script menu to simplify updating your system's packages (Read 2422 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Allservers2 - a bash script menu to simplify updating your system's packages

@conky60 asked me to make this script available for him, so I've put it here as it may benefit someone else too:

Code: [Select]
 #!/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 relatively messy script to do the same-ish job,
 ## in a more clumsy fashion (pacman-mirrors -g is pretty cool).
 ##
 ## If your mirrorlists become owned by root, they won't be able to
 ## be operated on by this script, so check that.
 ##
 ## In the /etc/pacman.d/ I use two custom mirrorlists called
 ## mirrorlist-arch-original & mirrorlist-artix-original each have
 ## ~ half a dozen or so of the generally fastest mirrors in each
 ## list (your choice really), which, if/when you choose, will be
 ## ranked into /etc/pacman.d/mirrorlist-arch & /etc/pacman.d/mirrorlist
 ## So you need to backup your original mirrorlists & then create the
 ## two "-original" files named exactly as I called them at the start
 ## of this paragraph. The other two will be created by the
 ## rankmirrors command. This is the hardest part of the whole process.
 ## Once you have your mirrors initially set up, allservers is as easy
 ## as it ever was. ;)
 ## 
 ## 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 --noconfirm "
 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 --noconfirm "
 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
 #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
 #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
 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
 #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 --noconfirm
 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 --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.
 
 "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

Just put copy the script into your text editor, name it allservers (or anything you want for that matter) place it in your ~/ or in your /usr/bin , set the executable bit & call it from a bash terminal, or at least a bash compatible terminal. I use the "as" alias that is mentioned in the commented out notes at the start of the script.

Have fun. 

Re: Allservers2 - a bash script menu to simplify updating your system's packages

Reply #1
Thanks a lot for this @handy.....much appreciated. :)


Best regards.
We should try to be kind to everyone.....we are all fighting some sort of battle.

Re: Allservers2 - a bash script menu to simplify updating your system's packages

Reply #2
I get this
Code: [Select]
    Enter the Number of Your Choice: 

1

==> Processing mirrors:

==> Removing comments from server lines in mirrorlist-arch-original
[sudo] password for robin0800:
sed: can't read /etc/pacman.d/mirrorlist-arch-original: No such file or directory
==> Running rankmirrors on mirrorlist-arch(-original)
/usr/bin/allservers.sh: line 99: /etc/pacman.d/mirrorlist-arch: Permission denied
==> Removing comments from server lines in mirrorlist-artix-original
sed: can't read /etc/pacman.d/mirrorlist-artix-original: No such file or directory
==> Running rankmirrors on mirrorlist(-artix)
/usr/bin/allservers.sh: line 103: /etc/pacman.d/mirrorlist: Permission denied
==> Updating your pacman databases

==> Your mirrors have been ranked &
==> the mirrorlist(s) have now been refreshed.

==> Refreshing your pacman database:
:: Synchronising package databases...
 system                   173.3 KiB  1947K/s 00:00 [######################] 100%
 world                    475.2 KiB  8.14M/s 00:00 [######################] 100%
 galaxy                   101.3 KiB  7.61M/s 00:00 [######################] 100%
 lib32                     13.2 KiB  0.00B/s 00:00 [######################] 100%
 extra                   1629.8 KiB  3.34M/s 00:00 [######################] 100%
 community                  4.1 MiB  6.46M/s 00:01 [######################] 100%
 multilib                 167.8 KiB  8.20M/s 00:00 [######################] 100%

==> Your mirrors & package database are now synchronised.


Re: Allservers2 - a bash script menu to simplify updating your system's packages

Reply #3
@handy, I am having permissions issues  with mirrorlist files. Isn't it "normal" that mirrorlist files are owned by root? I never had these issues when I used your script w/Manjaro. What is the difference in Artix?

Best regards.
We should try to be kind to everyone.....we are all fighting some sort of battle.

Re: Allservers2 - a bash script menu to simplify updating your system's packages

Reply #4
@robin0800 Did you follow the instructions in the comments at the top of the script?

In my /etc/pacman.d/  I have the following files (I've marked their required permissions):

mirrorlist (user)
mirrorlist-arch (user)
mirrorlist-arch-original (root) I use a much smaller number of chosen mirrors here  to make the whole process quicker.
mirrorlist-artix-original (root) as above ^ , only 6 or 8 mirrors here too.

(I keep the "genuine" originals marked with a -BAK suffix on their names.)

So as I stated in the comments of the script, you need to create the two "-original" files from the genuine articles. Name them as I've listed above & I suggest you make them smaller by initially using the  rankmirrors command on each of the two mirrorlists (arch & artix) so that you can see the fastest mirrors & pick 6 to 8 of them out to create your "-original" files.

Once you have created the two "-original" files, which have root privileges, when you first run the allservers menu option 1, the mirrorlist & the mirrorlist-arch files will be created.

Unfortunately, getting to this point does require a bit of stuffing around initially. But once you have done the above, then allservers will run as smoothly & reliably as it has done for the last >5 years. :)

@conky60 You have probably noticed from what I've written above, that the allservers script had to be modified so that it would work with two repositories (Arch & Artix) as well as not have the benefits that come with the pacman-mirrors -g command.

Once you have jumped through the hoops of creating the /etc/pacman.d/mirrorlist-artix-original & the /etc/pacman.d/mirrorlist-arch-original files, things in allservers2 will be much the same as they always where when using allservers.

Re: Allservers2 - a bash script menu to simplify updating your system's packages

Reply #5
How'd you guys @conky60 & @robin0800 go with that? I hope I was clear enough in my instructions?

 

Re: Allservers2 - a bash script menu to simplify updating your system's packages

Reply #6
Yes it works fine now thanks.