rpkg使用帮助
0 实验环境
CPU :龙芯3A5000
操作系统 :Loongnix Server 8.4
1 rpkg
Loongnix Server 8.4系统中,rpkg
软件包位于epel Everything仓库。所以在安装rpkg
之前需要先安装epel仓库的REPO包。
[loongson@bogon perl]$ sudo yum install loongnix-release-epel
1.1 rpkg是什么?
rpkg
是RedHat系推出的一个用于在git仓库中管理RPM软件包源码的工具。rpkg会和已经存在的源码管理仓库进行交互,源码管理仓库的地址需要在/etc/rpkg.conf
文件中进行设置。
1.2 rpkg帮助总览
使用rpkg
最简单的方法是--help
查看其所支持的命令。并且每个命令也可以单独使用--help
选项,用于查看指定命令的详细信息。
[loongson@bogon perl]$ rpkg --help
usage: rpkg [-h] [--config KEY=VAL] [--config-file CONFIG_FILE] [--user USER]
[--path PATH] [--verbose] [--quiet]
{add,clean,clog,clone,config,commit,ci,compile,copr-build,build,diff,gimmespec,import,install,lint,local,log,merge,new,nvr,prep,pull,push,reset,sources,spec,srpm,status,switch,tag,unused-patches,upload,verify-files}
...
positional arguments:
{add,clean,clog,clone,config,commit,ci,compile,copr-build,build,diff,gimmespec,import,install,lint,local,log,merge,new,nvr,prep,pull,push,reset,sources,spec,srpm,status,switch,tag,unused-patches,upload,verify-files}
Available subcommands
add Add changes to index
clean Remove untracked files
clog Output top changelog entry to stdout
clone Clone and checkout a repository
config Do nothing, only output used config
commit Commit changes
ci Alias for commit
compile Local test rpmbuild compile
copr-build Build package in Copr build system
build Alias for copr-build
diff Show changes between the last commit and working tree,
etc.
gimmespec Print auto-located input spec file name
import Import srpm content
install Local test rpmbuild install
lint Run rpmlint against rendered spec and build products
if present. Needs rpmlint to be installed.
local Local test rpmbuild binary
log Display git log history
merge Incorporates changes from the named commits into the
current branch
new Diff against last package tag
nvr Print package name-version-release
prep Prep test rpmbuild binary
pull Pull changes from the remote repository and update the
working copy
push Push changes and annotated tags to remote repository
reset Reset branch tip, index, or the working tree
sources Download source files from lookaside cache
spec Generate spec file from a spec template
srpm Create a source rpm
status Display git status of the current working tree and
index
switch Work with branches
tag Manage git tags
unused-patches Print list of patches in CWD not referenced by name in
the specfile
upload Upload source files
verify-files Locally verify %files section
optional arguments:
-h, --help show this help message and exit
--config KEY=VAL, -c KEY=VAL
Set specific config parameter KEY to a value VAL. May
be specified multiple times. Use <section>.<param>
format for KEY. Takes effect after -f option.
--config-file CONFIG_FILE, -C CONFIG_FILE
Specify a unique config file to be used.
--user USER, -u USER Override the discovered system user name.
--path PATH, -p PATH Define the directory to work in (defaults to cwd). The
working directory primarily determines where spec
file, sources file, and rpkg.conf are located. These
files are what forms an rpm (sub)package. The path to
a subpackage is additionally changed by --spec
argument, if specified.
--verbose, -v Run with verbose debug output.
--quiet, -q Run quietly only displaying errors.
For detailed help pass --help to a target subcommand.
1.3 rpkg常用帮助
rpkg
中封装了很多git
命令,其使用方式与git
一致,不需要过多解释。这个是git的最好入门教程。例如:其中的add
、clone
、commit
、diff
、log
、merge
、pull
、push
、status
、switch
、tag
命令就存在对应的git命令,而且功能一致。
除了原封不动的git
命令之外,还有一些进行了改造的git
命令,例如:clean
、ci
等。
以上这两种因为和git
相关,熟悉git
的同学,在见到这些时也不会陌生。
除了封装的git
命令之外,rpkg
还有一些封装了rpmbuild
的命令,例如:local
、prep
、nvr
、spec
、srpm
、verify-files
等,熟悉rpmbuild的用户查看帮助之后也基本上不难操作。
除了上面两种之外,还实现的用于操作源码包的命令,这些在此进行较详细说明。
1.3.1 rpkg config
这个命令只是用于显示当前正在使用的rpkg配置内容。
[loongson@bogon perl]$ rpkg config
[DEFAULT]
user = loongson
path = /home/loongson/workspace/lns-modules/perl
pkg_path = /home/loongson/workspace/lns-modules/perl
[rpkg]
preprocess_spec = True
base_output_path = /tmp/rpkg
user_macros =
with =
without =
rpmdefines =
bump_rpmdefines = 'dist %nil'
rpmlint_config =
default_macros = git.bash
copr_project =
......
1.3.2 rpkg sources(这个稍微复杂一些)
从配置的源码管理仓库中下载源码包(tarball)。源码管理仓库的地址在/etc/rpkg.conf
中的download_url
项中配置。例如,我配置了Fedora的源码包仓库:
download_url = https://src.fedoraproject.org/repo/pkgs/%(repo_path)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s
上面配置内容中有一个%repo_path
宏,它可以通过--repo-path
来指定。
下载源码包时依赖到spec
和sources
文件。其中spec
文件就是正常的RPM的那个规则文件,sources
文件的内容如下:
[loongson@bogon perl]$ more sources
SHA512 (perl-5.32.1.tar.xz) = 3443c75aea91f0fe3712fee576239f1946d2301b8f7390b690e2f5d070fe71af8f9fa7769e42086c2d33d5f84370f80368fa9350b4f10cc0ac3e6c1f6209d8f9
[loongson@bogon perl]$
其内容是:校验方式(源码包名称)= 校验和
,用于校验下载的源码包是否正确。
下面来看例子(以下载perl源码包为例):
[loongson@bogon perl]$ ls
perl.spec sources
[loongson@bogon perl]$ rpkg -v sources --repo-path perl
Running: /usr/lib/rpkg.macros.d/helpers/git_root
Running: /usr/lib/rpkg.macros.d/helpers/git_branch
Running: /usr/lib/rpkg.macros.d/helpers/git_remote
Running: /usr/lib/rpkg.macros.d/helpers/git_remote_url
Running: /usr/lib/rpkg.macros.d/helpers/git_head
Running: /usr/lib/rpkg.macros.d/helpers/git_head_short
Running: /usr/lib/rpkg.macros.d/helpers/git_status
Running: /usr/lib/rpkg.macros.d/helpers/git_merged_tag_refs
Running: /usr/lib/rpkg.macros.d/helpers/git_submodule_refs
Downloading perl-5.32.1.tar.xz from perl at src.fedoraproject.org:
Full url: https://src.fedoraproject.org/repo/pkgs/perl/perl-5.32.1.tar.xz/sha512/3443c75aea91f0fe3712fee576239f1946d2301b8f7390b690e2f5d070fe71af8f9fa7769e42086c2d33d5f84370f80368fa9350b4f10cc0ac3e6c1f6209d8f9/perl-5.32.1.tar.xz
######### 13.6%
......
源码包可以正常下载。rpkg upload
用于上传源码包!
1.3.3 rpkg compile
本地编译rpm包,这步就相当于rpmbuild -ba
的封装。
[loongson@bogon perl]$ rpkg compile
Wrote: /tmp/rpkg/perl-2-ei1frs48/perl.spec
正在执行(%prep):/bin/sh -e /var/tmp/rpm-tmp.pxkL9J
+ umask 022
+ cd /tmp/rpkg/perl-2-ei1frs48
+ cd /tmp/rpkg/perl-2-ei1frs48
+ rm -rf perl-5.32.1
+ /usr/bin/xz -dc /tmp/rpkg/perl-2-ei1frs48/perl-5.32.1.tar.xz
+ /usr/bin/tar -xof -
......
2 rpkg的配置文件
rpkg
的配置文件是/etc/rpkg.conf
.
内容如下:
[loongson@bogon perl]$ more /etc/rpkg.conf
[rpkg]
preprocess_spec = True
base_output_path = /tmp/rpkg
[git]
#clone_url = ssh://${user}@pkgs.fedoraproject.org/%(repo_path)s
#anon_clone_url = https://src.fedoraproject.org/%(repo_path)s
anon_clone_url = https://gitlab.com/loongnix/%(repo_path)s
default_namespace = rpms
push_follow_tags = True
clean_force = True
clean_dirs = True
[lookaside]
#download_url = http://${git_props:remote_netloc}/repo/pkgs/%(repo_path)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s
download_url = https://src.fedoraproject.org/repo/pkgs/%(repo_path)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s
upload_url = https://${git_props:remote_netloc}/repo/pkgs/upload.cgi
[loongson@bogon perl]$
软件包项目的patch文件、spec规则文件和软件包的源码包分开存放!其中clone_url
和anon_clone_url
用于配置软件包项目地址(perl软件包项目的spec文件、sources文件和patch文件);download_url
和upload_url
用于配置软件包源码包上传、下载的地址。