ダウンロードリンク/ URLから(deb)ファイルのサイズを取得するには?

ダウンロードリンク/ URLから(deb)ファイルのサイズを取得するには?

私はDebianにダウンロードしてインストールしたいdebsのURL(ダウンロードリンク)を取得する--print-urisために使用します(apt-get水滴)GNU / Linux。

--print-uris
           Instead of fetching the files to install their URIs are printed. Each URI will have the path, the
           destination file name, the size and the expected MD5 hash. Note that the file name to write to will not
           always match the file name on the remote site! This also works with the source and update commands. When
           used with the update command the MD5 and size are not included, and it is up to the user to decompress any
           compressed files. Configuration Item: APT::Get::Print-URIs.

出力例wesnoth:-

$ apt_uris wesnoth
http://mirror.fsf.org/trisquel/pool/main/s/sdl-net1.2/libsdl-net1.2_1.2.8-4_i386.deb
http://mirror.fsf.org/trisquel/pool/main/s/sdl-ttf2.0/libsdl-ttf2.0-0_2.0.11-3_i386.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-data_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-core_1.10.7-1ubuntu0.14.04.1_i386.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-httt_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-tsg_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-trow_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-ttb_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-ei_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-utbs_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-did_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-nr_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-sof_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-sotbe_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-l_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-aoi_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-thot_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-low_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-dm_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-dw_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth-1.10-music_1.10.7-1ubuntu0.14.04.1_all.deb
http://mirror.fsf.org/trisquel/pool/main/w/wesnoth-1.10/wesnoth_1.10.7-1ubuntu0.14.04.1_all.deb

メモ:

$ type apt_uris 
apt_uris is a function
apt_uris () 
{ 
    sudo apt-get install "$@" --print-uris -qq | grep http:// | cut -d "'" -f 2;
}

それでは、ポイントを見てみましょう。URLから各debファイルのサイズを取得または印刷したいです。(ダウンロードは必要ありません)。

wgetまたは、他の手段を使用してこれを行うことができますか?

答え1

ダウンロードせずにファイルサイズを取得する一般的な方法は、HTTP HEAD要求を作成してサーバーにサイズをContent-Lengthヘッダーに送り返すことです。一般的な静的ファイル(debファイルなど)の場合、サーバーはその情報を再送信できますが、保証することはできません。

これらのHTTP HEADリクエストを送信するためのさまざまなツールがあります。以下は、このユーティリティを使用してこれを実行する関数の例ですcurl

get_size() { # arg: URI
  curl -sI "$1" | sed -n 's/^Content-Length: \([0-9]\{1,\}\).*/\1/p'
}

Content-Lengthクエリが成功するかエラー(エラーメッセージの404 Not foundサイズなど)を返すかが返されます。Content-Length

選択肢は次のとおりですcurl

  • グヌwget:。wget -qSO- --max-redirect=0 --method=HEAD "$1"クエリが失敗した場合(たとえば、set -o pipefailインスタンスで使用されている場合)、クエリは失敗した終了ステータスを返します。
  • Perl LWPHEADコマンド: HEAD "$1"。このコマンドもクエリの失敗を報告しますが、HTTPリダイレクトに従うので無効にできないようです。

人道的なアプローチが必要な場合は、次のものを使用することもできますlftp

$ lftp -c 'du -h http://mirror.fsf.org/trisquel/pool/main/s/sdl-net1.2/libsdl-net1.2_1.2.8-4_i386.deb'
12K     /trisquel/pool/main/s/sdl-net1.2/libsdl-net1.2_1.2.8-4_i386.deb

答え2

Debian派生製品では、各ファイルのサイズが.debパッケージリストに保存されるため、検索するために何もダウンロードする必要はありません。

実際、apt-get --print-uris私はあなたに直接情報を提供します:

$ apt-get install nginx --print-uris -qq
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
'http://ftp.fr.debian.org/debian/pool/main/n/nginx/nginx-common_1.9.1-1_all.deb' nginx-common_1.9.1-1_all.deb 96110 MD5Sum:fc64530dcd5a4d50a36b9f2423fcf6c2
'http://ftp.fr.debian.org/debian/pool/main/n/nginx/nginx-full_1.9.1-1_amd64.deb' nginx-full_1.9.1-1_amd64.deb 471998 MD5Sum:6392f45e4e376ea3be2e60949dd80fe0
'http://ftp.fr.debian.org/debian/pool/main/n/nginx/nginx_1.9.1-1_all.deb' nginx_1.9.1-1_all.deb 75882 MD5Sum:ab5fa732657fba06544b353572967383

3番目のフィールドは.debファイルのサイズです。

これにより、ダウンロードするパッケージのリストを決定するためにasをapt-get実行する必要がなくなります。root

関連情報