Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## apt-aria2: To help download packages faster via aria2, instead of wget.
- ## Author: Anjishnu Sarkar
- ## Version: 0.5
- ## Acknowledgement: This script is a rewrite of the apt-fast script by
- ## Matt Parnell (admin@mattparnell.com) (http://www.mattparnell.com)
- ## Usage: Same as apt-get. Using the option "-y" always.
- ## BUG:
- ## *) If this script is interuppted, then next time aria2 starts downloading
- ## the same from the begining. Can be solved - something to do with .st file.
- ## TODO:
- ## *) Start installing via apt-get as soon as first package is downloaded
- ## and also keep downloading at the same time. This however might lead
- ## to dependencies not being satisfied.
- ## Initialization(s):
- Download="False"
- Install="True"
- Confirm="True"
- UniqueName="$RANDOM"
- Options="$@"
- ## Checking for commands which requires download
- while test -n "${1}"
- do
- case "${1}" in
- install|upgrade|dist-upgrade|source|build-dep)
- ## Download
- Download="True"
- ;;
- update|remove|autoremove|purge|dselect-upgrade|clean|autoclean|check)
- ## Anything other than download
- Download="False"
- ;;
- -d) ## Download only (don't install)
- Install="False"
- ;;
- -y) ## No need to ask for confirmation
- Confirm="False"
- ;;
- *)
- ## Nothing to be done. If any wrong options/commands are given then
- ## let apt-get handle it.
- ;;
- esac
- shift
- done
- ## In case download is true
- if [ "$Download" == "True" ];then
- ## Installing pre-requisite(s): aria2
- if ! which aria2c > /dev/null; then
- echo "Aria2 not installed. Installing aria2 first via apt-get"
- apt-get -y --force-yes install aria2
- fi
- ArchiveDir=/var/cache/apt/archives/
- cd ${ArchiveDir}/partial
- PrintUris=$(apt-get --yes --print-uris ${Options})
- if [ $? -ne 0 ];then
- echo "Aborting."
- exit 1
- fi
- PackageInfo=$(echo "$PrintUris" | awk '/Reading package/,/After this operation/')
- # echo "$PrintUris" | grep ^\' | cut -d\' -f2 > "$UniqueName"-uris.txt
- echo "$PrintUris" | grep "http:" | cut -d\' -f2 > "$UniqueName"-uris.txt
- NumberOfPackages=$(wc -l "$UniqueName"-uris.txt | awk '{print $1}')
- ## Print info
- echo "$PackageInfo"
- echo "Number of packages to be downloaded: $NumberOfPackages"
- ## Check whether package has already been installed or not
- InstallUpgradeMsg=$(echo "$PackageInfo" | grep \
- -e "The following NEW packages will be installed:" \
- -e "The following packages will be upgraded:")
- if [ -z "$InstallUpgradeMsg" ];then
- rm -f "$UniqueName"-uris.txt
- exit 0
- fi
- ## In $InstallUpgradeMsg is not null, then proceed...
- ## If confirm is true
- if [ "$Confirm" == "True" ];then
- echo -n "Do you want to continue [y|n]? "
- read Ans
- case "$Ans" in
- y|yes|"") ;;
- n|no|*) echo "Abort."
- rm -f "$UniqueName"-uris.txt
- exit 1 ;;
- esac
- fi
- if [ $NumberOfPackages -ne 0 ];then
- ## Downloading the packages
- echo "Proceeding with downloading ..."
- while read DebUrl
- do
- DebName=$(basename "$DebUrl")
- echo "$DebName"
- AptConf="/etc/apt/apt.conf"
- if [ -f "$AptConf" ];then
- http_proxy=$(grep -i "http::proxy" "$AptConf" | cut -d \" -f2)
- fi
- if [ -n "$http_proxy" ];then
- echo "Using proxy..."
- aria2c -c -s 10 -j 10 --http-proxy=$http_proxy "$DebUrl"
- else
- echo "Not using proxy..."
- aria2c -c -s 10 -j 10 "$DebUrl"
- fi
- if [ $? -eq 0 ];then
- mv $DebName ${ArchiveDir}
- fi
- done < "$UniqueName"-uris.txt
- fi
- rm -f "$UniqueName"-uris.txt
- # echo "Installing..."
- if [ "$Install" == "True" ];then
- apt-get -y --force-yes ${Options}
- fi
- else
- ## Cases when download is false
- apt-get ${Options}
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement