APT 全称Advanced Package Tool, 系Debian的牛X工具集,功能强大,使用方便,APT是具有牛力的。:)
A. 组件
I. apt-cache
II. apt-get (尚有多种工具,如apt-cdrom apt-setup apt-key ...常用的就这两个)
III. APT configure file
/etc/apt/apt.conf
IV. source list
/etc/apt/source.list
V. Packages pool directory
/var/cache/apt/archives/
`----partial/
VI. Local index files from source server
/var/lib/apt/lists/
|----192.168.10.252_debian_dists_unstable_Release
|-----192.168.10.252_debian_dists_unstable_Release.gpg
|-----192.168.10.252_debian_dists_unstable_contrib_binary-i386_Packages
|-----192.168.10.252_debian_dists_unstable_main_binary-i386_Packages
|-----lock
`-----partial/
VII. 安装于系统的软件包的信息记录文件,很重要!可在依赖关系不满足时修改之,让其暂时通过:)
/var/lib/dpkg/status
B. 有用的配置选项
// From /usr/share/doc/apt/examples/configure-index
Note: These are APT system default value
Dir "/" {
// Location of the state dir ----------------->Dir::State=/var/lib/apt/
State "var/lib/apt/"
{
Lists "lists/"; ----------->-o Dir::State::Lists="/tmp/lists/" => /tmp/lists/
xstatus "xstatus"; -o Dir::State::Lists="fuck/" => /var/lib/apt/fuck/
userstatus "status.user";
status "/var/lib/dpkg/status";
cdroms "cdroms.list";
};
// Location of the cache dir
Cache "var/cache/apt/" {
Archives "archives/";
srcpkgcache "srcpkgcache.bin";
pkgcache "pkgcache.bin";
};
// Config files
Etc "etc/apt/" {
SourceList "sources.list";
Main "apt.conf";
Preferences "preferences";
Parts "apt.conf.d/";
};
// Locations of binaries
Bin {
methods "/usr/lib/apt/methods/";
gzip "/bin/gzip";
dpkg "/usr/bin/dpkg";
dpkg-source "/usr/bin/dpkg-source";
dpkg-buildpackage "/usr/bin/dpkg-buildpackage"
apt-get "/usr/bin/apt-get";
apt-cache "/usr/bin/apt-cache";
};
};
APT
{
Architecture "i386";
Build-Essential "build-essential";
// Options for apt-get
Get
{
Arch-Only "false";
Download-Only "false";
Simulate "false";
Assume-Yes "false";
Force-Yes "false"; // I would never set this.
Fix-Broken "false";
Fix-Missing "false";
Show-Upgraded "false";
Show-Versions "false";
Upgrade "true";
Print-URIs "false";
Compile "false";
Download "true";
Purge "false";
List-Cleanup "true";
ReInstall "false";
Trivial-Only "false";
Remove "true";
Only-Source "";
Diff-Only "false";
Tar-Only "false";
};
};
C. 演示
1. -o apt::get::download-only="true" <==> -d
To see /usr/share/doc/apt/examples/configure-index
2. apt-get -d -o dir::cache::archives="/tmp/" install emac21
You need to create the directory /tmp/partial/
获取emac21的相关包,置于目录/tmp下, APT系统默认获取的软件包是置于/var/cache/apt/archieves/ 下。
Default: Dir::Cache::archives = /var/cache/apt/archieves/
Note: dir::cache::archives="tmp" ==> /var/cache/apt/tmp/
2.1 apt-get -o dir::cache::archives="/tmp/" clean
delete all *.deb in /tmp/
3. apt-get -o dir::state::lists="/tmp/" update
You need to create the directory /tmp/partial/
从服务器获取软件包索引于 /tmp 下,APT系统默认是置于/var/lib/apt/list 下。
Default: Dir::State::lists = /var/lib/apt/lists/
4. 在已经安装octave2.1 的机器上获取 octave2.1 所需的所有软件包,APT 会解析其所依赖的包,并下载之。
apt-get -d -o dir::cache::archives="/tmp/" -o dir::state::status="/tmp/status" install octave2.1
Note: /tmp/status 拷贝自某台需安装octave2.1 目标机的 /var/lib/dpkg/status
D. Example:
I. 问题描述:
机器A 装有debian-sid,因为特殊的原因没有可用的源;机器B安装debian-sarge,可以获得可靠的deb包,为了稳定一直使用stable的源;现因业务需要对机器A进行升级。
II. 分析
默认情况下,系统安装的软件包状态由 /var/lib/dpkg/status 文件记录(实际上就是安装的软件包信息的汇总)
安装或升级时apt-get 首先会把要用到的包下载到 /var/cache/apt/archives/ 目录下,然后再执行相应的操作(-d 或 -o apt::get::download-only="true" 则仅仅下载)
III. 求解
0. 在机器B的 /tmp下建立工作目录pool/
pool/
|-- archives/
| `-- partial/
|-- lists/
| `-- partial/
|-- sources.list ------------------------------>机器A所用的unstable源
`-- status ------------------------------>拷贝自机器A的/var/lib/dpkg/status
1.root@A#apt-get
-o dir::etc::sourcelist="/tmp/pool/sources.list" -------------->指定sources.list
-o dir::state::lists="/tmp/pool/lists/" ------>指定Packages,Release文件的存放路径
update
获取APT所要用到的索引文件(如Packages,Release),并置于/tmp/pool/lists/下。
2.root@A#apt-get -d
-o dir::cache="/tmp/pool/" --------->对应于/var/cache/apt/
-o dir::cache::archives="/tmp/pool/archives/" -------->下载之deb包存放目录
-o dir::state::status="/tmp/pool/status" --------->机器A升级前状态
-o dir::state::lists="/tmp/pool/lists/"
-o dir::etc::sourcelist="/tmp/pool/sources.list" --->APT从该文件获取源类型(unstable,etc.)
dist-upgrade
获取机器A升级所用软件包,存放于/tmp/pool/archives/
3.把pool目录拷入机器A 之 /tmp 目录下
root@B#apt-get -o dir::cache="/tmp/pool/" -o dir::state="/tmp/pool/" -o dir::etc="/tmp/pool/" check
[ APT generates a local copy of the cache files ]
root@B#apt-get -o dir::cache="/tmp/pool/" -o dir::state="/tmp/pool/" -o dir::state::status="/var/lib/dpkg/status" -o dir::etc="/tmp/pool/" dist-upgrade
4.以上过程采用配置文件可简化为:
4.1 建立 apt.conf ,置于pool目录下
apt.conf must contain the necessary information to make APT use the pool:
APT
{
/* This is not necessary if the two machines are the same arch, it tells
the remote APT what architecture the Debian machine is */
Architecture "i386";
Get::Download-Only "true";
};
Dir
{
/* Use the disc for state information and redirect the status file from
the /var/lib/dpkg default */
State "/tmp/pool/";
State::status "status";
// Binary caches will be stored locally
Cache::archives "/tmp/pool/archives/";
Cache "/tmp/";
// Location of the source list.
Etc "/tmp/pool/";
};
4.2 root@A# export APT_CONFIG="/disc/apt.conf"
root@A# apt-get update
[ APT fetches the package files ]
root@A# apt-get dist-upgrade
[ APT fetches all the packages needed to upgrade your machine ]
4.3 root@B# export APT_CONFIG="/disc/apt.conf"
root@B# apt-get check
[ APT generates a local copy of the cache files ]
root@B# apt-get --no-d -o dir::state::status=/var/lib/dpkg/status dist-upgrade
[ Or any other APT command ]
以下测试获取 libciao0.4.7
5.apt-get -d
-o dir::cache="/tmp/pool/"
-o dir::cache::archives="/tmp/pool/archives/"
-o dir::state::status="/tmp/pool/status"
-o dir::state::lists="/tmp/pool/lists/"
-o dir::etc::sourcelist="/tmp/pool/sources.list" --->APT从该文件获取源类型(指定unstable)
install libciao0.4.7
E: Reference
[1] /usr/share/doc/apt/example/configure-index
[2] /usr/share/doc/apt-doc/offline.html/ch2.html