26倍早い、apt-get installとapt-get upgrade

apt-get installのダウンロードスピードを26倍にする

matparnell.comで紹介されていた、AxelというHTTP/FTPダウンロードのスピードを向上されるコマンドラインアプリを利用して、コマンドラインが苦手な私でも知っている、apt-get installとapt-get upgradeのスピードを劇的に向上させることができる、スクリプトを紹介しよう。

まずはAxelのインストール

 sudo apt-get install axel 

そして、スクリプトはapt-fastというファイルを作成し、下記をペースト。

 #!/bin/sh
#apt-fast by Matt Parnell http://www.mattparnell.com , this thing is FOSS
#please feel free to suggest improvments to admin@mattparnell.com
# Use this just like apt-get for faster package downloading. Make sure to have axel installed

#If the first user entered variable string contains apt-get, and the second string entered is either install or dist-upgrade
if echo "$1" | grep -q "[upgrade]" || echo "$2" | grep -q "[install]" || echo "$2" | grep -q "[dist-upgrade]"; then
  echo "Working...";

  #Go into the directory apt-get normally puts downloaded packages
  cd /var/cache/apt/archives/;

  #Have apt-get print the information, including the URI's to the packages
  apt-get -y --print-uris $1 $2 $3 $4 > debs.list;

  #Strip out the URI's, and download the packages with Axel for speediness
  egrep -o -e "(ht|f)tp://[^']+" debs.list | xargs -l1 axel -a;

  #Perform the user's reqested action via apt-get
  apt-get -y $1 $2 $3 $4;

  echo "Done! Make sure and check to see that the packages all were installed properly. If a package is erred, run sudo apt-get autoclean and try installing it again without the use of this script.";

elif echo "$1" | grep -q "[*]"; then
  apt-get $1;
else
  echo "Sorry, but you appear to be entering invalid options. You must use apt-get and one of apt-get's options in order to use this script.";
fi
 

そして、作成したapt-fastを実行可能にする。

 chmod +x apt-fast 

最後に、apt-fastファイルを/usr/binに移動しよう。

使い方
使い方は、簡単。
これまで

 sudo apt-get install PACKAGE_NAME 

としていたapt-get installを

 sudo apt-fast install PACKAGE_NAME 

とするだけ。下記の2例も利用可能だ。

 sudo apt-fast install upgrade 
 sudo apt-fast install dist-upgrade 

実際に使ってみるとわかるが、26倍早いかどうかはわからなかったが、確かに早い。
ただでさえ、ストレスフルな毎日なのだから、apt-getくらいからはストレスフリーになってはどうだろうか?

categorized as

ティップス

  • Published
  • 2009 Nov 29
Trackback:
http://ubuntu.studiomohawk.com/652/fasten-apt-get-by-using-apt-fast/trackback/

コメントはこちらから

  1. [...] Shared 26倍早い、apt-get installとapt-get upgrade. [...]