Created
February 14, 2012 17:14
-
-
Save gabriellima/1828218 to your computer and use it in GitHub Desktop.
custom apt-fast (based on 0.02 by Matt Parnell)
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 | |
# CUSTOM version by Gabriel Lima (http://www.github.com/gabriellima) (@glima5) | |
# * Check portuguese (pt_BR) apt-get output | |
# * support '--force-yes' param to pass through user response | |
# * pass '-n10' to axel, to use 10 connections instead of default number | |
# * show packages installed or upgraded in the end of command execution | |
# apt-fast v0.02 by Matt Parnell http://www.mattparnell.com, this thing is fully open-source | |
# if you do anything cool with it, let me know so I can publish or host it for you | |
# contact me at [email protected] | |
# Special thanks to Travis/travisn000 from the PCLinux Forums for making improvements that allow | |
# for more complex apt-get commands. See the thread: http://www.pclinuxos.com/forum/index.php/topic,66385.0.html | |
# Use this just like apt-get for faster package downloading. Make sure to have axel installed. | |
# If the user entered arguments contain upgrade, install, or dist-upgrade | |
if echo "$@" | grep -q "upgrade\|install\|dist-upgrade"; then | |
echo "Working..."; | |
# Go into the directory apt-get normally puts downloaded packages | |
cd /var/cache/apt/archives/; | |
# Added to check for download size | |
apt-get -y --print-uris $@ > apt-fast.out | |
#Check if it needs to download something | |
#É preciso baixar 13,7MB de arquivos. | |
if [ `egrep -c 'É preciso baixar [ 0-9.,MKk/bB]+ de arquivos.' apt-fast.out` = "1" ] ; then | |
cat apt-fast.out | egrep -v 'http://' | |
# check when argument "--force-yes" was not used | |
if ! echo "$@" | grep -q "\-\-force\-yes"; then | |
echo -n "Você quer continuar OOOAAA [S/n]? " | |
read VAL | |
if [ "$VAL" = "n" -o "$VAL" = "N" ]; then | |
exit 0 | |
elif [ "$VAL" != "S" -a "$VAL" != "s" -a "$VAL" != "Y" -a "$VAL" != "y" -a "$VAL" != "" ]; then | |
echo "Unrecognised Response" | |
exit 0 | |
fi | |
fi | |
# Have apt-get print the information, including the URI's to the packages | |
# Strip out the URI's, and download the packages with Axel for speediness | |
# I found this regex elsewhere, showing how to manually strip package URI's you may need...thanks to whoever wrote it | |
apt-get -y --print-uris $@ | egrep -o -e "(ht|f)tp://[^\']+" > apt-fast.list && cat apt-fast.list | xargs -l1 axel -n10 -a | |
# Perform the user's requested action via apt-get | |
apt-get -y $@; | |
# Show what should've been installed/upgraded to user, if something | |
if [ `egrep -c '^ ' /var/cache/apt/archives/apt-fast.out` != "0" ] ; then | |
printf "\nOOO: The following packages were installed or upgraded: \n\n"; | |
egrep '^ ' < /var/cache/apt/archives/apt-fast.out; | |
fi | |
fi | |
printf "\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"; | |
exit 0; | |
else | |
apt-get $@; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment