Last active
January 7, 2019 22:55
-
-
Save MauroMombelli/04b24fa0644a4870869099276b86f2d4 to your computer and use it in GitHub Desktop.
Parallel download update for Arch Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $UID -ne 0 ]]; then | |
sudo -p 'Restarting as root, password: ' bash $0 "$@" | |
exit $? | |
fi | |
#read mirrorlist, "Server =" lines, remove all before and including "= " (10 char) | |
readarray -t mirrorArray < <(grep "^Server =" /etc/pacman.d/mirrorlist | cut -c 10-) | |
#randomize the order of the mirror | |
mirrorArray=( $(shuf -e "${mirrorArray[@]}") ) | |
#now get the list of stuff to update | |
readarray -t packageList < <(checkupdates | cut -d ' ' -f 1,4) | |
pidToWait='' | |
count=0 | |
for pkgNameAndVersion in "${packageList[@]}"; do | |
pkgName=${pkgNameAndVersion% *} | |
#echo "pkgName $pkgName" | |
repoAndArch=($(pacman -Si $pkgName | grep 'Repository :\|Architecture :' | cut -c 19-)) | |
repo=${repoAndArch[0]} | |
archpkg=${repoAndArch[1]} | |
arch='x86_64' | |
downloadList='' | |
for mirror in "${mirrorArray[@]}"; do | |
pkgNameAndVersion=${pkgNameAndVersion/ /-} | |
val=${mirror/\$repo/$repo} | |
val=$(echo ${val/\$arch/$arch}/$pkgNameAndVersion-$archpkg.pkg.tar.xz) | |
#echo - $repo - $arch - $val - $mirror | |
downloadList="$downloadList $val" | |
done | |
#echo $downloadList | |
aria2c -c $downloadList -d /var/cache/pacman/pkg/ &> /dev/null & | |
echo ">>> $(date +%T) | Downloading $pkgName, $running/10 download" | |
running=$(jobs |wc -l) | |
while [ $running -gt 10 ]; do | |
sleep 0.1 #sleep 0.1 second | |
running=$(jobs |wc -l) | |
done | |
done | |
#now wait for all remaining jobs | |
echo "all download started, waiting for completition" | |
wait | |
if [[ $# -gt 0 ]]; then | |
#DROP PRIVILEDGES | |
sudo -s -u $SUDO_USER $1 -Syu --noconfirm | |
else | |
echo "downloads complete, calling pacman" | |
pacman -Syu --no-confirm | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tested for a long time, working