Last active
March 19, 2022 19:16
-
-
Save Thell/7350ee9319a2967e9a0d to your computer and use it in GitHub Desktop.
Aria2 rpc based progress monitor for apt-fast in non-interactive shells.
This file contains 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/sh | |
# Aria2 rpc based progress output for apt-fast | |
# trigger using --on-download-complete callback. | |
# Provide bytesNeeded in the parent environment... | |
# apturis=$(apt-get -qq --print-uris "$@") | |
# export DLLISTBYTES=$( echo "$apturis"| awk -F " " '{bytes+=$3} END{print bytes}' ) | |
aria2_rpc () { | |
http --ignore-stdin localhost:6800/jsonrpc id=apt-fast method=aria2.$1 | |
} | |
export $( aria2_rpc getGlobalStat | jq -r '.result|to_entries[]|join("=")' ) | |
bytesNeeded=$DLLISTBYTES | |
bytesDownloaded=$(du -bcs $(dirname -- $3)/* | tail -1 | cut -f1) | |
numUris=$(( numActive + numStopped + numWaiting )) | |
timeElapsed=$(ps -p $(pgrep -f '^aria2c*' --oldest) -o etime= | tr -d " ") | |
if [ "$numStopped" = "$numUris" ]; then | |
# Shutdown aria2 when queue is exhausted. | |
printf \ | |
"Pre-Fetched %s [%s] in %s (%s) from %s packages.$(tput el)\n" \ | |
$( numfmt --to si --suffix="B" --round nearest $bytesDownloaded ) \ | |
$( numfmt --to iec-i --suffix="B" --round nearest $bytesDownloaded ) \ | |
$timeElapsed \ | |
$( numfmt --to iec-i --suffix="B/s" $downloadSpeed ) \ | |
$numUris | |
aria2_rpc shutdown > /dev/null | |
else | |
exec 1>&2 | |
printf \ | |
"\r%s %3s%% [ %s / %s @ %s ][ W: %d A: %d S: %d / %d (%s%%) ]$(tput el)" \ | |
$timeElapsed \ | |
$(( bytesDownloaded * 100 / bytesNeeded )) \ | |
$( numfmt --to iec-i --suffix="B" --round nearest $bytesDownloaded ) \ | |
$( numfmt --to iec-i --suffix="B" --round nearest $bytesNeeded ) \ | |
$( numfmt --to iec-i --suffix="B/s" $downloadSpeed ) \ | |
$numWaiting \ | |
$numActive \ | |
$numStopped \ | |
$numUris \ | |
$(( numStopped * 100 / numUris )) | |
fi |
See https://github.com/Thell/ddash along with some usage in the dockerfiles associated with https://github.com/Thell/dockerfiles/tree/master/scripts.
Good Luck! Have Fun!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi thell, how could apt-fast-progress be used?
An example??