Skip to content

Instantly share code, notes, and snippets.

@Burnfaker
Created May 19, 2012 23:39
Show Gist options
  • Save Burnfaker/2732829 to your computer and use it in GitHub Desktop.
Save Burnfaker/2732829 to your computer and use it in GitHub Desktop.
APT-FAST modified!
THIS IS THE MODIFIED SCRIPT IF YOU LIKE THE ORIGINAL GOTO https://github.com/ilikenwf/apt-fast
====================
About:
====================
apt-fast is a shellscript wrapper for apt-get that can drastically improve apt download
times by downloading packages in parallel, with multiple connections per package.
BE SURE to look at the tags in the repo, as some are distro specific, and may contain
files you need for autocompletion.
====================
Setup/Install:
====================
Some distros, such as PCLinuxOS include apt-fast in their repos. For those of you
who need to manually install it, download it and perform the following:
cp ./apt-fast /usr/sbin/
chmod +x /usr/sbin/apt-fast
cp ./apt-fast.conf /etc
You need to have a good download manager installed - aria2c and axel are favorites
for this script. Make sure and open apt-fast in a text editor and uncomment the line
for your download manager before using it, and configure the other options!
apt-get install aria2c
OR
apt-get install axel
Then, you should be ready to use it - simply run apt-fast instead of apt-get any time
you find yourself needing to manage packages!
Debian (and possibly others) autocompletion:
cp ./apt-fast.comp /etc/bash_completion.d/apt-fast
. /etc/bash_completion
====================
License:
====================
Consider apt-fast and all of it's derivatives licensed under the GNU GPLv3.
====================
Special thanks:
====================
Travis/travisn000 - support for complex apt-get commands
Allan Hoffmeister - aria2c support
Abhishek Sharma - aria2c with proxy support
Luca Marchetti - improvements on the locking system and downloader execution
Richard Klien - Autocompletion, Download Size Checking (made for on ubuntu, untested on other distros)
Patrick Kramer Ruiz - suggestions - see Suggestions.txt
Sergio Silva - test to see if axel is installed, root detection/sudo autorun, lock file check/creation
# !/bin/sh
# apt-fast v1.5 by Matt Parnell http://www.mattparnell.com, GNU GPLv3
# Use this just like aptitude or apt-get for faster package downloading.
###################################################################
# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
###################################################################
# Configfile
source /etc/apt-fast.conf
# Check for proper priveliges
[ "`whoami`" = root ] || exec sudo "$0" "$@"
# Check if a lockfile exist
LCK_FILE=/var/run/$(basename $0).lock
[ -f $LCK_FILE ] && { echo "$(basename $0) already running"; exit 1; }
# Remove lockfile
LCK_RM() {
rm -f $LCK_FILE
#echo lock-File $LCK_FILE deleted
}
trap "LCK_RM ; exit 1" 2 9 15
# Create and insert a PID number to lockfile
#echo "create lock-File $LCK_FILE "
echo $$ > $LCK_FILE
NUM=1
# Make sure one of the download managers is enabled
[ -z "$_DOWNLOADER" ] && echo "You must configure /etc/apt-fast.conf to use axel or aria2c" && LCK_RM && exit 1
# If the user entered arguments contain upgrade, install, or dist-upgrade
if echo "$@" | grep -q "upgrade\|install\|dist-upgrade|full-upgrade"; then
echo "Working..."; cd /var/cache/apt/archives;
# Get the package URL's
# note aptitude doesn't have this functionality
# so we use apt-get only
apt-get -y --print-uris $@ | egrep -o -e "(ht|f)tp://[^\']+" > /tmp/apt-fast.list
# Download the packages
eval ${_DOWNLOADER}
# Install our downloaded packages
${_APTMGR} $@;
echo -e "\nDone! Verify that all packages were installed successfully. If errors are found, run apt-get clean as root and try again using apt-get directly.\n";
else
${_APTMGR} $@;
fi
# Test the date of our lockfile
while [ $NUM -le 5 ] ; do
#echo Test `date`
NUM=`expr $NUM + 1`
sleep 2
done
# After error or all done remove our lockfile with a PID number
LCK_RM
exit 0
# Debian apt-fast(8) completion.
have apt-fast &&
_apt_fast()
{
local cur prev special i
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
if [[ ${COMP_WORDS[i]} == @(install|remove|autoremove|purge|source|build-dep) ]]; then
special=${COMP_WORDS[i]}
fi
done
if [ -n "$special" ]; then
case $special in
remove|autoremove|purge)
if [ -f /etc/debian_version ]; then
# Debian system
COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
else
# assume RPM based
_rpm_installed_packages
fi
return 0
;;
*)
COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
2> /dev/null ) )
return 0
;;
esac
fi
case "$prev" in
-@(c|-config-file))
_filedir
return 0
;;
-@(t|-target-release|-default-release))
COMPREPLY=( $( apt-cache policy | \
grep "release.o=Debian,a=$cur" | \
sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null) )
return 0
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y -u -t -b -c -o \
--download-only --fix-broken --help --version --ignore-missing \
--fix-missing --no-download --quiet --simulate --just-print \
--dry-run --recon --no-act --yes --assume-yes --show-upgraded \
--only-source --compile --build --ignore-hold --target-release \
--no-upgrade --force-yes --print-uris --purge --reinstall \
--list-cleanup --default-release --trivial-only --no-remove \
--diff-only --no-install-recommends --tar-only --config-file \
--option --auto-remove' -- "$cur" ) )
else
COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \
dist-upgrade install remove purge source build-dep \
check clean autoclean autoremove' -- "$cur" ) )
fi
return 0
} &&
complete -F _apt_fast $filenames apt-fast
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
###################################################################
# CONFIGURATION OPTIONS
###################################################################
# Maximum number of connections
_MAXNUM=5
# Use aptitude or apt-fast?
# Note that for outputting the package URI list, we always use apt-get
# ...since aptitude can't do this
_APTMGR=apt-get
# Note that the manager you choose has other options - feel free
# to setup your own _DOWNLOADER or customize one of the ones below
# they're simply here as examples, and to provide sane defaults
# Download manager selection
# (choose one by uncommenting one #_DOWNLOADER line)
# aria2c:
_DOWNLOADER='aria2c -c -j ${_MAXNUM} --input-file=/tmp/apt-fast.list --connect-timeout=600 --timeout=600 -m0'
# aria2c with a proxy (set username, proxy, ip and password!)
#_DOWNLOADER='aria2c -c 20 -j ${_MAXNUM} --http-proxy=http://username:password@proxy_ip:proxy_port -i apt-fast.list'
# axel:
#_DOWNLOADER='cat /tmp/apt-fast.list | xargs -l1 axel -n ${_MAXNUM} -a' # axel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment