CheckInstall-便民的源码安装工具

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
头像
jazzi
帖子: 532
注册时间: 2005-10-16 23:26
来自: 泉州
联系:

CheckInstall-便民的源码安装工具

#1

帖子 jazzi » 2006-02-04 20:51

  Checkinstall 是一个能从 tar.gz类的源代码自动生成RPM/Debian或Slackware安装包的程序。这样使你能用几乎所有的 tar.gz 类的源代码生成“干净”的安装或者卸载包。

  简介

  经常出现这样的问题:你很想试用的程序只有 tar.gz的源代码可用(没人提供 rpm 或者 Debian包)。这样,你只好下载回源代码,解压,然后手动编译。到目前为止,一切正常。然而,当你想删掉它的时候呢?

  Makefile文件只包括了很少情况下的卸载例程。当然,你可以把程序安装到临时文件夹,然后记下所有由程序生成或修改的文件,最后删除他们。但是如果这个程序要经常重新编译,那样做是非常痛苦的,工作量也是相当大的。 Felipe Eduardo所写的 CheckInstall [1] Sánchez Díaz Durán 就是用来解决这个问题的。

  一般说来,我们编译安 装一个由GNU Autoconf配置的程序是采用如下的步骤:

 

代码: 全选

 ./configure && make && make install.  
  这个 configure 脚本文件是用来“猜”出一系列系统相关的变量,这些变量是在后面的编译过程要用到的。它将检查系统变量值是否满足编译要求,然后使用这些变量在程序包内每个文件夹下生成 Makefile 。此外,configure 脚本还会生成其他文件,他们是:


* 每个文件夹/子文件夹下的一个或多个Makefile(s)
* 一个名叫config.status的脚本
* 一个文本文件config.log
* 另一个名叫config.cache的脚本(可选的)
* 带有系统特殊定义的C头文件(*.h)(可选项)


  configure脚本文件成功运行之后, 你会输入make来编译程序,得到你需要的可执行文件。你也可能在make之后马上使用make check来运行测试。但是这只是可选的步骤,因为这需要这个程序包的支持。如果 make成功的完成了,你可以使用make install来安装这个程序了——很明显,完成这步你需要一些相关权限。程序安装好了,你可以在源代码的文件夹下输入make clean来清除这些生成的可执行文件和目标文件。如果你还想删除由configure生成的文件,那么输入 then typemake distclean。后两步同make check一样(是可选的),它们通常是开发者在开发和测试阶段所使用,也可以被一般使用者用来节省硬盘空间或者保持文件夹的结构简洁明快。另外make distclean使得我们在不同类型的电脑上编译程序成为可能。

  关于GNU Autoconf的详细资料可以在在线文档[2]上找到。在基本介绍之外,你可以通过写你自己的configure脚本、用M4编程和创建自己的宏等方式来学习更多有关GNU Build System的知识。

  CheckInstall

  前面提到,我们采用GNU Autoconf通过一系列如下指令来编译程序:

  

代码: 全选

./configure && make && make install 
 

  现在该是换一种方式的时候了,你可以使用CheckInstall。它采用自己的指令checkinstall来代替make install。其他两个指令保留下来跟以前一样,因此,现在这个指令序列使用 CheckInstall变成了:

  

代码: 全选

./configure && make && checkinstall  
  指令checkinstall不仅默认运行了make install,而且还监测所有安装过程中的写操作。为此,CheckInstall使用了Pancrazio de Mauro 所写的程序Installwatch [3]。在make install成功完成之后,CheckInstall会产生一个Slackware-, Debian- 或RPM- 安装包,然后按照软件包的默认配置安装程序,并在当前目录(或标准安装包存储目录)留下一个生成的安装包。而外,你可以通过修改变量PAK_DIR来修改保存这个目录。这样生成的安装包安装到其他机器上而无须重新编译——当然,还得考虑软件包的相互依赖性。

  CheckInstall并不只是使用make install,它还可以与其他安装指令相协调。例如,如果安装指令为setup.sh,那么安装指令序列变成:

 

代码: 全选

 ./configure && make && checkinstall setup.sh  
  我们还可以让CheckInstall带着很多参数运行。如下命令会显示所有可用的子参数,这些子参数大致分为:安装选项(Install options), 脚本处理选项(Scripting options), 信息显示选项(Info display options),安装包选项(Package tuning options),清除选项(Cleanup options)和关于CheckInstall(About CheckInstall)等。

代码: 全选

  # checkinstall -h  
  如果CheckInstall带着这些参数运行,他会使用这些参数值来代替配置文件checkinstallrc中相应的值。

  CheckInstall也有自己的局限之处。它不能处理静态连接的程序,因为这样Installwatch就不能监测到安装过程中修改过文件了。总体说来,有两类连接库:动态的和静态的。这些连接库通过include-指令整合到程序中。静态连接过的程序已经包含了所有需要的库文件,运行时也就不需要再将这些库载入内存中。这种程序与安装在系统中的连接库无关,因为所谓的连接器(Linker)已经在编译时把这些库内置到可执行程序里了。

  安装

  CheckInstall已经在大一些的发行版的“程序池”(software pools)中存在很长的时间了,可以通过发行版各自提供的安装方式安装。你也可以在主页[4]上下载各种预编译好的安装包或者合适的源码包。

  CheckInstall的安装非常简单,只需要很少的步骤——但要成功的安装CheckInstall你似乎需要 CheckInstall。在必要的make install之后,你输入checkinstall,就会从编译好的程序生成合适的二进制安装包。现在,你可以使用你的安装包管理程序来“干净的”安装或者卸载了。在CheckInstall创建安装包之前,你还得必须回答一个关于程序安装包管理器的问题,并且还要检查相关信息的正确性。这些信息将会出现在稍后生成的安装包的头部。

  下面将展示安装checkinstall-1.6.0beta4.tgz的全过程。这会安装上CheckInstall、 Installwatch和makepak,其中makepak是makepkg的修改版。如果你对新版本的改进感兴趣,请参看Release Notes [5] 和/或 Changelog [6].




 $ tar xzf checkinstall-1.6.0beta4.tgz
 $ cd checkinstall-1.6.0beta4
checkinstall-1.6.0beta4  $ make
[...]
checkinstall-1.6.0beta4  $ su
Password:
checkinstall-1.6.0beta4 # make install
[...]
checkinstall-1.6.0beta4 # checkinstall

checkinstall 1.6.0beta4, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
This software is released under the GNU GPL.

Please choose the packaging method you want to use.
Slackware , RPM [R] or Debian [D]? R

*************************************
*** RPM package creation selected ***
*************************************

This package will be built according to these values:

1 - Summary: [ CheckInstall installations tracker, version 1.6.0beta4 ]
2 - Name: [ checkinstall ]
3 - Version: [ 1.6.0beta4 ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ Applications/System ]
7 - Architecture: [ i386 ]
8 - Source location: [ checkinstall-1.6.0beta4 ]
9 - Alternate source location: [ ]
10 - Provides: [ checkinstall ]
11 - Requires: [ ]

Enter a number to change any of them or press ENTER to continue:

Installing with make install...

========================= Installation results =========================
[...]



========================= Installation successful ======================

Copying documentation directory...
./
./NLS_SUPPORT
./README
./FAQ
./TODO
./CREDITS
./INSTALL
./Changelog
./BUGS
./installwatch-0.7.0beta4/
./installwatch-0.7.0beta4/README
./installwatch-0.7.0beta4/TODO/usr/src/redhat/RPMS/i386/checkinstall-1.6.0beta4-1.i386.rpm
./installwatch-0.7.0beta4/VERSION
./installwatch-0.7.0beta4/INSTALL
./installwatch-0.7.0beta4/CHANGELOG
./installwatch-0.7.0beta4/BUGS
./installwatch-0.7.0beta4/COPYING
./RELNOTES
./COPYING

Copying files to the temporary directory...OK

Striping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building RPM package...OK

NOTE: The package will not be installed

Erasing temporary files...OK

Writing backup package...OK

Deleting temp dir...OK

****************************************************************
完成。
新的安装包保存在 /usr/src/redhat/RPMS/i386/checkinstall-1.6.0beta4-1.i386.rpm
你可以在系统中随时安装它:
rpm -i checkinstall-1.6.0beta4-1.i386.rpm

****************************************************************

checkinstall-1.6.0beta4 # cd /usr/src/redhat/RPMS/i386/
i386 # rpm -i checkinstall-1.6.0beta4-1.i386.rpm
i386 #


  Debian 的用户可以使用dpkg -i来安装。 Slackware用户用 installpkg可以达到同样目的。


  使用包管理程序的查询语句,你可以检查安装包中文件是否完全在程序库中记录了,还可以查看安装包头部的一些额外信息。在此,使用 RPM 作为例子:





 $ rpm -qi checkinstall
Name : checkinstall Relocations: (not relocatable)
Version : 1.6.0beta4 Vendor : (none)
Release : 1 Build Date : Mo 06 Dez 2004 17:05:45 CET
Install Date: Di 07 Dez 2004 01:41:49 Build Host : deimos.neo5k.lan
Group : Applications/System Source RPM : checkinstall-1.6.0beta4-1.src.rpm
Size : 264621 License : GPL
Signature : (none)
Packager : checkinstall-1.6.0beta4
Summary : CheckInstall installations tracker, version 1.6.0beta4
Description :
CheckInstall installations tracker, version 1.6.0beta4

CheckInstall keeps track of all the files created or
modified by your installation script ("make install"
"make install_modules", "setup", etc), builds a
standard binary package and installs it in your
system giving you the ability to uninstall it with your
distribution's standard package management utilities.

  配置

  你可以通过修改文件/usr/lib/local/checkinstall/checkinstallrcCheckInstall的默认配置。

  尽管CheckInstall每次运行都会询问生成何种类型安装包,明智的办法还是手工修改/设置INSTYPE变量。看看变量 INSTALL、PAK_DIR和RPM_FLAGS或者DPKG_FLAGS也是值得推荐的。最后两个变量允许你定义一些可选的安装标志,通过修改 PAK_DIR你可以指定安装包的存储目录。而INSTALL让你决定是只生成安装包呢还是一起将这个包马上安装。





 $ cat /usr/lib/local/checkinstall/checkinstallrc

####################################################################
# CheckInstall configuration file #
########################################

####################################################################
# These are default settings for CheckInstall, modify them as you #
# need. Remember that command line switches will override them. #
####################################################################

# Debug level
# 0: No debug
# 1: Keep all temp files except the package's files
# 2: Keep the package's files too

DEBUG=0

# Location of the "installwatch" program
INSTALLWATCH_PREFIX="/usr/local"
INSTALLWATCH= ${INSTALLWATCH_PREFIX}/bin/installwatch

# Location of the makepkg program. "makepak" is the default, and is
# included with checkinstall. If you want to use Slackware's native "makepkg"
# then set this to "makepkg"

MAKEPKG=/sbin/makepkg

# makepkg optional flags. These are recommended if running a newer Slackware
# version: "-l y -c n"

MAKEPKG_FLAGS="-l y -c n"

# Is MAKEPKG running interactively? If so, you might want
# to see what it's doing:

SHOW_MAKEPKG=0

# Where will we keep our temp files?
BASE_TMP_DIR=/var/tmp ## Don't set this to /tmp or / !!

# Where to place the installed document files
DOC_DIR=""

# Default architecture type (Leave it empty to allow auto-guessing)
ARCHITECTURE=""

# Default package type. Leave it empty to enable asking everytime
# S : Slackware
# R : RPM
# D : Debian

INSTYPE="R"

# Storage directory for newly created packages
# By default they will be stored at the default
# location defined for the package type

PAK_DIR=""

# RPM optional flags
RPM_FLAGS=" --force --nodeps --replacepkgs "

# dpkg optional flags
DPKG_FLAGS=""


## These are boolean. Set them to 1 or 0

# Interactively show the results of the install command (i.e. "make install")?
# This is useful for interactive installation commands
SHOW_INSTALL=1

# Show Slackware package installation script while it runs? Again, useful if
# it's an interactive script
SHOW_SLACK_INSTALL=0

# Automatic deletion of "doc-pak" upon termination?
DEL_DOCPAK=1

# Automatic deletion of the spec file?
DEL_SPEC=1

# Automatic deletion of "description-pak"?
DEL_DESC=1

# Automatically strip all ELF binaries?
STRIP_ELF=1

# Automatically strip all ELF shared libraries?
# Note: this setting will automatically be set to "0" if STRIP_ELF=0
STRIP_SO_ELF=1

# Automatically search for shared libraries and add them to /etc/ld.so.conf?
# This is experimental and could mess up your dynamic loader configuration.
# Use it only if you know what you are doing.
ADD_SO=0

# Automatically compress all man pages?
COMPRESS_MAN=1

# Set the umask to this value
CKUMASK=0022

# Backup files overwritten or modified by your install command?
BACKUP=1

# Write a doinst.sh file that installs your description (Slackware)?
AUTODOINST=1

# Are we going to use filesystem translation?
TRANSLATE=1

# Reset the owner/group of all files to root.root?
RESET_UIDS=0

# Use the new (8.1+) Slackware description file format?
NEW_SLACK=1

# Comma delimited list of files/directories to be ignored
EXCLUDE=""

# Accept default values for all questions?
ACCEPT_DEFAULT=0

# Use "-U" flag in rpm by default when installing a rpm package
# This tells rpm to (U)pdate the package instead of (i)nstalling it.
RPM_IU=U

# Inspect the file list before creating the package
CK_INSPECT=0

# Review the .spec file before creating a .rpm
REVIEW_SPEC=0

# Review the control file before creating a .deb
REVIEW_CONTROL=0

# Install the package or just create it?
INSTALL=0


  结论

  CheckInstall是一款优秀的软件,它能使得管理Linux更加方便。特别是在源码需要经常重复编译的情况下, CheckInstall可以让你丝毫不破坏系统一致性的前提下完全的卸载程序。另外,你还可以使用这些编译好的安装包直接在其他的机器上安装(而无须重新编译!)——当然,你得考虑软件包的相互依赖性,不过,这在同类的机器上一般并不是什么问题。

  Links

  [1] http://asic-linux.com.mx/~izto/checkinstall/ [Home of CheckInstall]
  [2] http://www.gnu.org/software/auto ... -2.57/autoconf.html [GNU Autoconf Online Manual]或者中文的: http://littleone.go.nease.net/AutoConf.html[AutoConf 中文手册]
  [3] http://asic-linux.com.mx/~izto/checkins ... watch.html [Installwatch]
  [4] http://asic-linux.com.mx/~izto/checkins ... wnload.php [CheckInstall Downloads]
  [5] http://asic-linux.com.mx/~izto/checkins ... s/RELNOTES [Release Notes]
  [6] http://asic-linux.com.mx/~izto/checkins ... /Changelog [Changelog]
You make it fun
It will make you fun
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2006-02-04 23:06

要是从源码包开始处理就好了,make通过了以后再处理的意义小了好多。
● 鸣学
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#3

帖子 millenniumdark » 2006-02-05 0:05

好像已经有一篇介绍checkinstall的帖子了
好像没这里讲的详细

加精
XDG3669
帖子: 380
注册时间: 2006-07-10 22:50

#4

帖子 XDG3669 » 2007-04-30 12:56

详尽介绍!收下了。
头像
stlxv
论坛版主
帖子: 8275
注册时间: 2006-05-03 0:39
来自: المريخ

#5

帖子 stlxv » 2007-04-30 14:53

麻烦
PHP是最好的语言!不服来战!
头像
tendertang
帖子: 146
注册时间: 2006-07-10 9:27
来自: 哈尔滨工业大学
联系:

#6

帖子 tendertang » 2007-04-30 16:54

不错
这个很有必要呀
andrew_t
帖子: 614
注册时间: 2006-12-14 3:00

#7

帖子 andrew_t » 2007-04-30 19:31

mark
头像
Decease
帖子: 834
注册时间: 2006-12-14 20:33

#8

帖子 Decease » 2007-04-30 19:37

Good ..
头像
zhan
帖子: 1880
注册时间: 2005-08-15 0:04
来自: 南7技校

#9

帖子 zhan » 2007-04-30 19:58

checkinstall 这个东西打的包基本上只能自己个人用用。还不一定有保证...
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
yysirius
帖子: 63
注册时间: 2007-04-08 17:12

#10

帖子 yysirius » 2007-05-20 23:20

我用checkinstall 打的包都把程序装在/usr/local目录下
怎么才能改成/usr目录下?

我的 checkinstallrc在/etc目录下
里面的设置原本就是
INSTALLWATCH_PREFIX="/usr"

可是不起作用
775ftft
帖子: 83
注册时间: 2007-04-11 19:05

#11

帖子 775ftft » 2007-07-20 13:43

不错,支持
头像
YuCheng.Tang
帖子: 20
注册时间: 2007-06-21 10:18

很好的文章!

#12

帖子 YuCheng.Tang » 2007-07-21 10:11

赞个, 不错阿。 拜倒了!
xiechy
帖子: 1074
注册时间: 2006-01-18 15:01

#13

帖子 xiechy » 2007-07-21 23:09

楼主能否强化一下对checkinstall的缺点的介绍~因为不管怎样,这都不是一个很好的创建deb包的方式,只是一种权宜之计罢了。
回复