summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorlesto2019-02-23 14:37:51 +0100
committerlesto2019-02-23 14:37:51 +0100
commit3ef57e2043b5b9e73e7514e3276ea46c1ca99926 (patch)
treebacd27e61750f0114b652a4fb4e94d836ad08be7
parent71f9729983010f6a172b2d41f3d1083b68231943 (diff)
downloadaur-3ef57e2043b5b9e73e7514e3276ea46c1ca99926.tar.gz
Version 2 released
-rw-r--r--PKGBUILD2
-rwxr-xr-xpp.sh37
2 files changed, 23 insertions, 16 deletions
diff --git a/PKGBUILD b/PKGBUILD
index 0f05fb5f670..8374ed6afff 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,6 +1,6 @@
# Maintainer: lesto <lestofante88@gmail.com>
pkgname=pacman-parallelizer
-pkgver=1
+pkgver=2
pkgrel=1
pkgdesc="A minimal package downloader for pacman, using aria2"
arch=(any)
diff --git a/pp.sh b/pp.sh
index a913fa4dce1..3da11aa3c8c 100755
--- a/pp.sh
+++ b/pp.sh
@@ -1,13 +1,21 @@
#!/bin/bash
+maxMirrorForDownload=4
+
+arch=$(uname -m)
+
if [[ $UID -ne 0 ]]; then
- sudo -p 'Restarting as root, password: ' bash $0 "$@"
- exit $?
+ 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-)
+mirrorArrayLen=${#mirrorArray[@]}
+let maxParallelDownload=$mirrorArrayLen/$maxMirrorForDownload
+echo "mirrorsNumber:$mirrorArrayLen maxParallelDownload:$maxParallelDownload maxMirrorForDownload:$maxMirrorForDownload"
+
#randomize the order of the mirror
mirrorArray=( $(shuf -e "${mirrorArray[@]}") )
@@ -15,39 +23,37 @@ mirrorArray=( $(shuf -e "${mirrorArray[@]}") )
readarray -t packageList < <(checkupdates | cut -d ' ' -f 1,4)
pidToWait=''
-
+mirrorIndex=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
+ for (( i=0; i<$maxMirrorForDownload; i++ )); do
+ mirror=${mirrorArray[mirrorIndex]}
pkgNameAndVersion=${pkgNameAndVersion/ /-}
val=${mirror/\$repo/$repo}
val=$(echo ${val/\$arch/$arch}/$pkgNameAndVersion-$archpkg.pkg.tar.xz)
- #echo - $repo - $arch - $val - $mirror
downloadList="$downloadList $val"
+ ((mirrorIndex++))
+ if [[ $mirrorIndex -ge $mirrorArrayLen ]]; then
+ mirrorIndex=0
+ fi
done
- #echo $downloadList
aria2c -c $downloadList -d /var/cache/pacman/pkg/ &> /dev/null &
-
+
running=$(jobs |wc -l)
- echo ">>> $(date +%T) | Downloading $pkgName, $running/10 download"
-
- while [ $running -gt 10 ]; do
+ echo ">>> $(date +%T) | Downloading $pkgName, $running/$maxParallelDownload download"
+
+ while [ $running -ge $maxParallelDownload ]; do
sleep 0.1 #sleep 0.1 second
running=$(jobs |wc -l)
done
-
done
#now wait for all remaining jobs
@@ -55,6 +61,7 @@ echo "all download started, waiting for completition"
wait
if [[ $# -gt 0 ]]; then
+ echo "downloads complete, calling $1"
#DROP PRIVILEDGES
sudo -s -u $SUDO_USER $1 -Syu --noconfirm
else