1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #!/bin/bash
[ "`whoami`" = root ] || exec sudo bash "$0" "$@"
which aria2c &>/dev/null || apt-get install -y --install-recommends aria2
if echo "$@" | grep -q "upgrade\|install\|dist-upgrade"; then cd /var/cache/apt/archives/
deb_file_list=`mktemp` trap "rm -f ${deb_file_list}" EXIT apt-get -y --print-uris $@ | egrep -o -e "(http|https)://[^\']+" > ${deb_file_list} cat ${deb_file_list}
aria2c -c -j 50 -x 5 -k 1m \ --connect-timeout=15 --timeout=15 --max-tries=0 \ --file-allocation=falloc --input-file=${deb_file_list} if [ "$?" = "0" ] ; then apt-get $@ -y else find /var/cache/apt/ -name "*.deb" -or -name "*.deb.aria2" | xargs -n 1 -r rm -- fi else apt-get $@ fi
|