摘要:
Checkinstall 是一個(gè)能從 tar.gz類的源代碼自動(dòng)生成RPM/Debian或Slackware安裝包的程序。這樣使你能用幾乎所有的 tar.gz 類的源代碼生成“干凈”的安裝或者卸載包。
簡介
經(jīng)常出現(xiàn)這樣的問題:你很想試用的程序只有 tar.gz的源代碼可用(沒人提供 rpm 或者 Debian包)。這樣,你只好下載回源代碼,解壓,然后手動(dòng)編譯。到目前為止,一切正常。然而,當(dāng)你想刪掉它的時(shí)候呢?
Makefile文件只包括了很少情況下的卸載例程。當(dāng)然,你可以把程序安裝到臨時(shí)文件夾,然后記下所有由程序生成或修改的文件,最后刪除他們。但是如果這個(gè)程序要經(jīng)常重新編譯,那樣做是非常痛苦的,工作量也是相當(dāng)大的。 Felipe Eduardo所寫的 CheckInstall [1] Sánchez Díaz Durán 就是用來解決這個(gè)問題的。
一般說來,我們編譯安 裝一個(gè)由GNU Autoconf配置的程序是采用如下的步驟:
./configure && make && make install.
這個(gè) configure 腳本文件是用來“猜”出一系列系統(tǒng)相關(guān)的變量,這些變量是在后面的編譯過程要用到的。它將檢查系統(tǒng)變量值是否滿足編譯要求,然后使用這些變量在程序包內(nèi)每個(gè)文件夾下生成 Makefile 。此外,configure 腳本還會(huì)生成其他文件,他們是:
- 每個(gè)文件夾/子文件夾下的一個(gè)或多個(gè)Makefile(s)
- 一個(gè)名叫config.status的腳本
- 一個(gè)文本文件config.log
- 另一個(gè)名叫config.cache的腳本(可選的)
- 帶有系統(tǒng)特殊定義的C頭文件(*.h)(可選項(xiàng))
configure腳本文件成功運(yùn)行之后, 你會(huì)輸入make來編譯程序,得到你需要的可執(zhí)行文件。你也可能在make之后馬上使用make check來運(yùn)行測試。但是這只是可選的步驟,因?yàn)檫@需要這個(gè)程序包的支持。如果 make成功的完成了,你可以使用make install來安裝這個(gè)程序了——很明顯,完成這步你需要一些相關(guān)權(quán)限。程序安裝好了,你可以在源代碼的文件夾下輸入make clean來清除這些生成的可執(zhí)行文件和目標(biāo)文件。如果你還想刪除由configure生成的文件,那么輸入 then typemake distclean。后兩步同make check一樣(是可選的),它們通常是開發(fā)者在開發(fā)和測試階段所使用,也可以被一般使用者用來節(jié)省硬盤空間或者保持文件夾的結(jié)構(gòu)簡潔明快。另外make distclean使得我們?cè)诓煌愋偷碾娔X上編譯程序成為可能。
關(guān)于GNU Autoconf的詳細(xì)資料可以在在線文檔[2]上找到。在基本介紹之外,你可以通過寫你自己的configure腳本、用M4編程和創(chuàng)建自己的宏等方式來學(xué)習(xí)更多有關(guān)GNU Build System的知識(shí)。
CheckInstall
前面提到,我們采用GNU Autoconf通過一系列如下指令來編譯程序:
./configure && make && make install
現(xiàn)在該是換一種方式的時(shí)候了,你可以使用CheckInstall。它采用自己的指令checkinstall來代替make install。其他兩個(gè)指令保留下來跟以前一樣,因此,現(xiàn)在這個(gè)指令序列使用 CheckInstall變成了:
./configure && make && checkinstall
指令checkinstall不僅默認(rèn)運(yùn)行了make install,而且還監(jiān)測所有安裝過程中的寫操作。為此,CheckInstall使用了Pancrazio de Mauro 所寫的程序Installwatch [3]。在make install成功完成之后,CheckInstall會(huì)產(chǎn)生一個(gè)Slackware-, Debian- 或RPM- 安裝包,然后按照軟件包的默認(rèn)配置安裝程序,并在當(dāng)前目錄(或標(biāo)準(zhǔn)安裝包存儲(chǔ)目錄)留下一個(gè)生成的安裝包。而外,你可以通過修改變量PAK_DIR來修改保存這個(gè)目錄。這樣生成的安裝包安裝到其他機(jī)器上而無須重新編譯——當(dāng)然,還得考慮軟件包的相互依賴性。
CheckInstall并不只是使用make install,它還可以與其他安裝指令相協(xié)調(diào)。例如,如果安裝指令為setup.sh,那么安裝指令序列變成:
./configure && make && checkinstall setup.sh
我們還可以讓CheckInstall帶著很多參數(shù)運(yùn)行。如下命令會(huì)顯示所有可用的子參數(shù),這些子參數(shù)大致分為:安裝選項(xiàng)(Install options), 腳本處理選項(xiàng)(Scripting options), 信息顯示選項(xiàng)(Info display options),安裝包選項(xiàng)(Package tuning options),清除選項(xiàng)(Cleanup options)和關(guān)于CheckInstall(About CheckInstall)等。
# checkinstall -h
如果CheckInstall帶著這些參數(shù)運(yùn)行,他會(huì)使用這些參數(shù)值來代替配置文件checkinstallrc中相應(yīng)的值。
CheckInstall也有自己的局限之處。它不能處理靜態(tài)連接的程序,因?yàn)檫@樣Installwatch就不能監(jiān)測到安裝過程中修改過文件了。總體說來,有兩類連接庫:動(dòng)態(tài)的和靜態(tài)的。這些連接庫通過include-指令整合到程序中。靜態(tài)連接過的程序已經(jīng)包含了所有需要的庫文件,運(yùn)行時(shí)也就不需要再將這些庫載入內(nèi)存中。這種程序與安裝在系統(tǒng)中的連接庫無關(guān),因?yàn)樗^的連接器(Linker)已經(jīng)在編譯時(shí)把這些庫內(nèi)置到可執(zhí)行程序里了。
安裝
CheckInstall已經(jīng)在大一些的發(fā)行版的“程序池”(software pools)中存在很長的時(shí)間了,可以通過發(fā)行版各自提供的安裝方式安裝。你也可以在主頁[4]上下載各種預(yù)編譯好的安裝包或者合適的源碼包。
CheckInstall的安裝非常簡單,只需要很少的步驟——但要成功的安裝CheckInstall你似乎需要 CheckInstall。在必要的make install之后,你輸入checkinstall,就會(huì)從編譯好的程序生成合適的二進(jìn)制安裝包。現(xiàn)在,你可以使用你的安裝包管理程序來“干凈的”安裝或者卸載了。在CheckInstall創(chuàng)建安裝包之前,你還得必須回答一個(gè)關(guān)于程序安裝包管理器的問題,并且還要檢查相關(guān)信息的正確性。這些信息將會(huì)出現(xiàn)在稍后生成的安裝包的頭部。
下面將展示安裝checkinstall-1.6.0beta4.tgz的全過程。這會(huì)安裝上CheckInstall、Installwatch和makepak,其中makepak是makepkg的修改版。如果你對(duì)新版本的改進(jìn)感興趣,請(qǐng)參看Release Notes [5] 和/或 Changelog [6].
$ tar xzf checkinstall-1.6.0beta4.tgz$ cd checkinstall-1.6.0beta4checkinstall-1.6.0beta4 $ make[...]checkinstall-1.6.0beta4 $ suPassword:checkinstall-1.6.0beta4 # make install[...]checkinstall-1.6.0beta4 # checkinstallcheckinstall 1.6.0beta4, Copyright 2002 Felipe Eduardo Sanchez Diaz DuranThis software is released under the GNU GPL.Please choose the packaging method you want to use.Slackware [S], 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./COPYINGCopying files to the temporary directory...OKStriping ELF binaries and libraries...OKCompressing man pages...OKBuilding file list...OKBuilding RPM package...OKNOTE: The package will not be installedErasing temporary files...OKWriting backup package...OKDeleting temp dir...OK****************************************************************完成。新的安裝包保存在 /usr/src/redhat/RPMS/i386/checkinstall-1.6.0beta4-1.i386.rpm你可以在系統(tǒng)中隨時(shí)安裝它: 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.rpmi386 #
Debian 的用戶可以使用dpkg -i來安裝。 Slackware用戶用 installpkg可以達(dá)到同樣目的。
使用包管理程序的查詢語句,你可以檢查安裝包中文件是否完全在程序庫中記錄了,還可以查看安裝包頭部的一些額外信息。在此,使用 RPM 作為例子:
$ rpm -qi checkinstallName : checkinstall Relocations: (not relocatable)Version : 1.6.0beta4 Vendor : (none)Release : 1 Build Date : Mo 06 Dez 2004 17:05:45 CETInstall Date: Di 07 Dez 2004 01:41:49 Build Host : deimos.neo5k.lanGroup : Applications/System Source RPM : checkinstall-1.6.0beta4-1.src.rpmSize : 264621 License : GPLSignature : (none)Packager : checkinstall-1.6.0beta4Summary : CheckInstall installations tracker, version 1.6.0beta4Description :CheckInstall installations tracker, version 1.6.0beta4CheckInstall keeps track of all the files created ormodified by your installation script ("make install""make install_modules", "setup", etc), builds astandard binary package and installs it in yoursystem giving you the ability to uninstall it with yourdistribution's standard package management utilities. 配置
你可以通過修改文件/usr/lib/local/checkinstall/checkinstallrcCheckInstall的默認(rèn)配置。
盡管CheckInstall每次運(yùn)行都會(huì)詢問生成何種類型安裝包,明智的辦法還是手工修改/設(shè)置INSTYPE變量。看看變量INSTALL、PAK_DIR和RPM_FLAGS或者DPKG_FLAGS也是值得推薦的。最后兩個(gè)變量允許你定義一些可選的安裝標(biāo)志,通過修改PAK_DIR你可以指定安裝包的存儲(chǔ)目錄。而INSTALL讓你決定是只生成安裝包呢還是一起將這個(gè)包馬上安裝。
$ 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 tooDEBUG=0# Location of the "installwatch" programINSTALLWATCH_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 filesDOC_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 : DebianINSTYPE="R"# Storage directory for newly created packages# By default they will be stored at the default# location defined for the package typePAK_DIR=""# RPM optional flagsRPM_FLAGS=" --force --nodeps --replacepkgs "# dpkg optional flagsDPKG_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 commandsSHOW_INSTALL=1# Show Slackware package installation script while it runs? Again, useful if# it's an interactive scriptSHOW_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=0STRIP_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 valueCKUMASK=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 ignoredEXCLUDE=""# 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 packageCK_INSPECT=0# Review the .spec file before creating a .rpmREVIEW_SPEC=0# Review the control file before creating a .debREVIEW_CONTROL=0# Install the package or just create it?INSTALL=0 結(jié)論
CheckInstall是一款優(yōu)秀的軟件,它能使得管理Linux更加方便。特別是在源碼需要經(jīng)常重復(fù)編譯的情況下,CheckInstall可以讓你絲毫不破壞系統(tǒng)一致性的前提下完全的卸載程序。另外,你還可以使用這些編譯好的安裝包直接在其他的機(jī)器上安裝(而無須重新編譯!)——當(dāng)然,你得考慮軟件包的相互依賴性,不過,這在同類的機(jī)器上一般并不是什么問題。
Links
[1] http://asic-linux.com.mx/~izto/checkinstall/ [Home of CheckInstall]
[2] http://www.gnu.org/software/autoconf/manual/autoconf-2.57/autoconf.html [GNU Autoconf Online Manual]
或者中文的: http://littleone.go.nease.net/AutoConf.html[AutoConf 中文手冊(cè)]
[3] http://asic-linux.com.mx/~izto/checkinstall/installwatch.html [Installwatch]
[4] http://asic-linux.com.mx/~izto/checkinstall/download.php [CheckInstall Downloads]
[5] http://asic-linux.com.mx/~izto/checkinstall/docs/RELNOTES [Release Notes]
[6] http://asic-linux.com.mx/~izto/checkinstall/docs/Changelog [Changelog]