CheckInstall-Linux源碼安裝工具

Checkinstall 是一個能從 tar.gz類的源代碼自動生成RPM/Debian或Slackware安裝包的程序。這樣使你能用幾乎全部的 tar.gz 類的源代碼生成「乾淨」的安裝或者卸載包。html

 簡介 node

  常常出現這樣的問題:你很想試用的程序只有 tar.gz的源代碼可用(沒人提供 rpm 或者 Debian包)。這樣,你只好下載回源代碼,解壓,而後手動編譯。到目前爲止,一切正常。然而,當你想刪掉它的時候呢?編程

  Makefile文件只包括了不多狀況下的卸載例程。固然,你能夠把程序安裝到臨時文件夾,而後記下全部由程序生成或修改的文件,最後刪除他們。可是若是這個程序要常常從新編譯,那樣作是很是痛苦的,工做量也是至關大的。 Felipe Eduardo所寫的 CheckInstall [1] Sánchez Díaz Durán 就是用來解決這個問題的。 ide

  通常說來,咱們編譯安 裝一個由GNU Autoconf配置的程序是採用以下的步驟: 學習

./configure && make && make install.測試

  這個 configure 腳本文件是用來「猜」出一系列系統相關的變量,這些變量是在後面的編譯過程要用到的。它將檢查系統變量值是否知足編譯要求,而後使用這些變量在程序包內每一個文件夾下生成 Makefile .此外,configure 腳本還會生成其餘文件,他們是:ui

  * 每一個文件夾/子文件夾下的一個或多個Makefile(s)this

  * 一個名叫config.status的腳本 spa

  * 一個文本文件config.log debug

  * 另外一個名叫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)已經在編譯時把這些庫內置到可執行程序裏了。

 

  安裝

$ tar xzf checkinstall-1.6.0beta4.tgz

   

  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].
 

$ 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 [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

./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可讓你絲絕不破壞系統一致性的前提下徹底的卸載程序。另外,你還可使用這些編譯好的安裝包直接在其餘的機器上安裝(而無須從新編譯!)——固然,你得考慮軟件包的相互依賴性,不過,這在同類的機器上通常並非什麼問題。

原文:
 

http://tech.16c.cn/Os/Linux/20100813_48978.html

相關文章
相關標籤/搜索