19
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

非rootでapt-getでパッケージを依存関係を辿ってダウンロード,インストール

Last updated at Posted at 2017-12-04

概要

結論は[#パッケージを依存関係を辿ってダウンロード]
(#パッケージを依存関係を辿ってダウンロード)

環境

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
...

$ bash --version
GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu)
...

$ apt-get --version
apt 1.0.1ubuntu2 for amd64 compiled on Apr 10 2014 13:03:40
...

$ apt-cache --version
apt 1.0.1ubuntu2 for amd64 compiled on Apr 10 2014 13:03:40

$ dpkg --version
Debian `dpkg' package management program version 1.17.5 (amd64).
...

$ awk --version
GNU Awk 4.0.1
...

パッケージ(.deb)をダウンロード

カレントディレクトリに.debファイルをダウンロード.

$ apt-get download pkg_name

$ apt-get download glibc-doc
Get:1 http://jp.archive.ubuntu.com/ubuntu/ trusty-updates/main glibc-doc all 2.19-0ubuntu6.13 [19.5 kB]
Fetched 19.5 kB in 0s (198 kB/s)

$ ls
glibc-doc_2.19-0ubuntu6.13_all.deb

パッケージの依存関係を調べる

pkg_nameが依存するパッケージを調べる.

$ apt-cache depends pkg_name

$ apt-cache depends glibc-doc
glibc-doc
  Depends: glibc-doc-reference

Depends:となっているパッケージを再帰的にインストールしていく必要がある.
Depends:以外にConflicts:, Breaks:などがある.
参考: [Debian ポリシーマニュアル - Chapter 7 - パッケージ間の関連性の宣言]
(http://www.debian.or.jp/community/devel/debian-policy-ja/policy.ja.html/ch-relationships.html)

パッケージ(.deb)をインストール

pgk.debをdst_dirにインストール

$ dpkg -x pkg.deb dst_dir

$ ls
glibc-doc_2.19-0ubuntu6.13_all.deb

$ dpkg -x glibc-doc_2.19-0ubuntu6.13_all.deb ./local

$ ls
glibc-doc_2.19-0ubuntu6.13_all.deb  local/

$ find
./local
./local/usr
./local/usr/share
./local/usr/share/man
./local/usr/share/man/man3
./local/usr/share/man/man3/pthread_mutexattr_destroy.3.gz
./local/usr/share/man/man3/pthread_cond_wait.3.gz
./local/usr/share/man/man3/pthread_mutexattr_settype.3.gz
...
./local/usr/share/doc/glibc-doc/copyright
./local/usr/share/doc/glibc-doc/nptl_db
./glibc-doc_2.19-0ubuntu6.13_all.deb

現在インストール済みのパッケージ一覧を表示

$ dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                  Version                                             Architecture Description
+++-=====================================================-===================================================-============-================================================================================================
ii  account-plugin-aim                                    3.8.6-0ubuntu9                                      amd64        Messaging account plugin for AIM
ii  account-plugin-facebook                               0.11+14.04.20140409.1-0ubuntu1                      all          GNOME Control Center account plugin for single signon - facebook
...
ii  zlib1g-dev:amd64                                      1:1.2.8.dfsg-1ubuntu1                               amd64        compression library - development
ii  zsh                                                   5.0.2-3ubuntu6                                      amd64        shell with lots of features
ii  zsh-common                                            5.0.2-3ubuntu6                                      all          architecture independent files for Zsh

通常 dpkg -l の結果は以下のように画面幅に合わせて省略される.

$ dpkg -l
...
ii  zlib1g-dev:amd64 1:1.2.8.dfsg- amd64         compression library - development
ii  zsh              5.0.2-3ubuntu amd64         shell with lots of features
ii  zsh-common       5.0.2-3ubuntu all           architecture independent files for Zs

以下のようにすると省略を無効化できる.

$ dpkg -l | cat
$ COLUMNS=200 dpkg -l

200という値はどこかのサイトで拾ってきた値である.

dpkg -l の出力と.debファイルのファイル名の関係

.debのファイル名

Name_Version_Architecture.deb

各値は dpkg -l のカラム名に対応する.

$ dpkg -l
...
||/ Name                                                  Version                                             Architecture Description
...
ii  zsh                                                   5.0.2-3ubuntu6                                      amd64        shell with lots of features

の場合

zsh_5.0.2-3ubuntu6_amd64.deb

パッケージを依存関係を辿ってダウンロード

今まで見てきたものを組み合わせれば良い.
dpkg管理下のインストール済みのパッケージはダウンロードしない.
さもなくばとんでもない量のファイルをダウンロードしてしまう.
dpkg管理下以外のパッケージも考慮したいなら#dpkg -l の出力と.debファイルのファイル名の関係などを参考にして自前でパッケージ管理をする必要がある.

スクリプトファイル

download.sh
# ! /bin/bash

download(){
    apt-cache depends $1 |
    grep Depends |
    awk '{print $2}' | 
    while read i; do
        if [[ -z "$(dpkg -l | awk '{print $2}' | grep $i)" ]]; then
            download $i
        fi
    done
    apt-get download $1

}

download $1

実行例

$ ls
download.sh*

$ ./download.sh glibc-doc
Get:1 http://jp.archive.ubuntu.com/ubuntu/ trusty/main glibc-doc-reference all 2.19-0ubuntu1 [5,130 kB]
Fetched 5,130 kB in 1s (3,566 kB/s)           
Get:1 http://jp.archive.ubuntu.com/ubuntu/ trusty-updates/main glibc-doc all 2.19-0ubuntu6.13 [19.5 kB]
Fetched 19.5 kB in 0s (271 kB/s)

$ ls
download.sh*                        glibc-doc-reference_2.19-0ubuntu1_all.deb
glibc-doc_2.19-0ubuntu6.13_all.deb

インストール

$ ls
download.sh*                        glibc-doc-reference_2.19-0ubuntu1_all.deb
glibc-doc_2.19-0ubuntu6.13_all.deb

$ ls *.deb | while read i; do dpkg -x $i ./local; done

$ ls
download.sh*                        glibc-doc-reference_2.19-0ubuntu1_all.deb
glibc-doc_2.19-0ubuntu6.13_all.deb  local/

$ find
.
./local
./local/usr
./local/usr/share
./local/usr/share/info
./local/usr/share/info/libc.info-8.gz
./local/usr/share/info/libc.info-9.gz
./local/usr/share/info/libc.info.gz
...
./local/usr/share/man/man3/pthread_mutexattr_getkind_np.3.gz
./local/usr/share/man/man3/pthread_atfork.3.gz
./download.sh
./glibc-doc-reference_2.19-0ubuntu1_all.deb
./glibc-doc_2.19-0ubuntu6.13_all.deb
19
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?