Linux下創建安裝包的四種方式

Linux下創建安裝包的四種方式


1. rpmbuild

以Ubuntu/Debian下的virt-viewer-8.0爲例:
  • 安裝工具

apt-get install rpm

  • 下載virt-viewer-8.0源碼

wget https://releases.pagure.org/virt-viewer/virt-viewer-8.0.tar.gz ./

  • 解壓編譯

這個自己看readme或者configure吧。。。。

  • 然後跑一下rpmbuild:

rpmbuild -bb /home/jr/rpmbuild/[xxx]/virt-viewer.spec

  • 這時候會提示:

error: File /home/jr/rpmbuild/SOURCES/virt-viewer-8.0.tar.gz: No such file or directory

  • 還會幫你再當前用戶目錄下面建立一堆文件夾:

BUILD BUILDROOT RPMS SOURCES SPECS SRPMS

  • 按照提示把源代碼的gz包copy到 SOURCES下面就好

  • 編寫spec文件
    這裏偷懶直接用來解壓編譯virt-viewer源碼裏面生成的virt-viewer.spec改一改,
    不然的話要寫半天,還不一定寫了能用。。。。尼瑪。。。


Name: virt-viewer
Version: 8.0
Release: 1%{?dist}
Summary: Virtual Machine Viewer
Group: Applications/System
License: GPLv2+
URL: http://virt-manager.org/
Source0: http://virt-manager.org/download/sources/%{name}/%{name}-%{version}.tar.gz

%description
Virtual Machine Viewer provides a graphical console client for connecting
to virtual machines. It uses the GTK-VNC or SPICE-GTK widgets to provide
the display, and libvirt for looking up VNC/SPICE server details.

%prep
%setup -q

%build


#%configure %{spice_arg} %{govirt_arg} --with-buildid=%{release} --disable-update-mimedb
%configure --prefix=/usr --libdir=/usr/lib --without-gtk-vnc --without-ovirt --with-buildid=%{release} --disable-update-mimedb


#%__make %{?_smp_mflags}
%__make -j4

%install
rm -rf $RPM_BUILD_ROOT
%__make install  DESTDIR=$RPM_BUILD_ROOT
%find_lang %{name}


%files -f %{name}.lang
%doc README.md COPYING AUTHORS ChangeLog NEWS

%define name remote-viewer

%{_bindir}/%{name}
%{_bindir}/remote-viewer
%{_datadir}/icons/hicolor/*/apps/*
%{_datadir}/icons/hicolor/*/devices/*
%{_datadir}/applications/remote-viewer.desktop
%{_datadir}/appdata/remote-viewer.appdata.xml
%{_datadir}/mime/packages/virt-viewer-mime.xml
%{_mandir}/man1/virt-viewer.1*
%{_mandir}/man1/remote-viewer.1*

%changelog

  • 然後再跑:

rpmbuild -bb /home/jr/rpmbuild/[xxx]/virt-viewer.spec
最後有個rpm包生成。
我的arm盒子,uname -m ,顯示armv7l
正常來說,我應該跑:
rpmbuild -bb -target armv71 /home/jr/rpmbuild/[xxx]/virt-viewer.spec
但是最終跑出來的包安裝不了,提示架構不符,只好不加target參數跑rpmbuild了

關於spec文件何編寫,有兩篇文章拿來參考不錯:
https://blog.csdn.net/czg13548930186/article/details/53144868
https://www.cnblogs.com/michael-xiang/p/10480809.html


2. dpkg-buildpackage

1.首先是查找、獲取源碼包

apt-cache showsrc xxx
查詢當前鏡像站點中是否有該源碼包

apt-get source xxx
命令來獲取源碼包,它會將源碼包下載到用戶當前目錄
該命令執行過程中,會調用dpkg-source命令,根據dsc文件中的信息,將源碼包解壓到同名目錄中
dpkg-source可以通過apt-get install dpkg-dev獲得

2.安裝依賴包:

apt-get build-dep xxx
命令可以主動獲取並安裝所有相關的軟件包

3.編譯源碼包:

cd xxx
dpkg-buildpackage

4.使用dpkg -i安裝編譯出來的deb包


3. checkinstall

感覺這個用的最方便,
rpmbuild編寫spec文件太麻煩,還容易出錯,
dpkg-buildpackage一般編譯的是完全版本的程序,依賴包超多,刪減程序、定製化不便,而且apt source下來的包不一定最新。
checkinstall只需要源碼make成功之後跑一下就好。

Pls see below:

1.安裝checkinstall:

for Ubuntu/Debian:

apt-get install checkinstall

for CentOS/Fedora:
yum install rpm-build rpmdevtools
ref: https://asic-linux.com.mx/~izto/checkinstall/download.php

wget https://raw.githubusercontent.com/rpmsphere/x86_64/master/c/checkinstall-1.6.2-1.x86_64.rpm
yum install checkinstall-1.6.2-1.x86_64.rpm

2.編譯源碼:

./configure … xxx
make -j4
3.調用checkinstall打包:

1. 調用:
sudo checkinstall
2. 輸入包描述:
The package documentation directory ./doc-pak does not exist. 
Should I create a default set of package docs? [y]:  

輸入y就對了,然後填入包名再回車。

3. 修改包信息:

This package will be built according to these values:

0 - Maintainer: [ xxx ]
1 - Summary: [ xxx ]
2 - Name: [ name ]
3 - Version: [ ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ checkinstall ]
7 - Architecture: [ amd64 ]
8 - Source location: [ nameofthesrc ]
9 - Alternate source location: [ ]
10 - Requires: [ ]
11 - Provides: [ command ]
12 - Conflicts: [ ]
13 - Replaces: [ ]

想改哪個就輸入哪個數字吧,可以來回改幾次,最後來兩下回車就ok下一步

4. 此時checkinstall會在你的機器上安裝(以spice-gtk 0.35爲例),稍等片刻,最後看到:

Copying files to the temporary directory…OK

Stripping ELF binaries and libraries…OK

Compressing man pages…OK

Building file list…OK

Building Debian package…OK

Installing Debian package…OK

Erasing temporary files…OK

Writing backup package…OK
OK

Deleting temp dir…OK

.*********************************************************************

Done. The new package has been installed and saved to

/home/jr/virt-viewer/spice-gtk-0.35/spice-gtk_0.35-1_armhf.deb

You can remove it from your system anytime using:

  dpkg -r spice-gtk

.**********************************************************************

看看,是不是超級方便,不用去寫半天rpmbuild的spec文件,也方便做功能裁剪、定製化,不像dpkg-buildpackage那麼死板笨重。
真是神器啊!


4, FPM

  • #安裝rugy、gem:

yum -y install ruby rubygems ruby-devel
gem source -l

  • #添加國內aliyun的源:

gem sources -a http://mirrors.aliyun.com/rubygems/

  • #移除原生官方源:

gem sources --remove https://rubygems.org/

  • #更新源:

gem source -u

  • #安裝fpm:

gem install fpm

  • #安裝目標程序到臨時目錄:

make install DESTDIR=/root/tmpdir

  • #打包命令舉例:

fpm -s dir -t rpm -n spice -v 0.14.1 -C /root/tmpdir

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章