创建 RPM 文件至少需要做什么?

发布于 2024-07-21 02:18:56 字数 336 浏览 6 评论 0原文

我只想创建一个 RPM 文件来分发我的 Linux 二进制文件“foobar”,只有几个依赖项。 它有一个配置文件 /etc/foobar.conf 并应安装在 /usr/bin/foobar 中。

不幸的是,RPM 文档有 27 章长,我真的没有有一天坐下来阅读这篇文章,因为我还忙着为其他平台制作 .deb 和 EXE 安装程序。

创建 RPM 至少需要做什么? 假设 foobar 二进制文件和 foobar.conf 位于当前工作目录中。

I just want to create an RPM file to distribute my Linux binary "foobar", with only a couple of dependencies. It has a config file, /etc/foobar.conf and should be installed in /usr/bin/foobar.

Unfortunately the documentation for RPM is 27 chapters long and I really don't have a day to sit down and read this, because I am also busy making .deb and EXE installers for other platforms.

What is the absolute minimum I have to do to create an RPM? Assume the foobar binary and foobar.conf are in the current working directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

镜花水月 2024-07-28 02:18:56

我经常在 Linux 上为每个打包专有应用程序(也最常见的是 websphere)执行二进制 rpm。
所以我的经验对你也很有用,此外,如果可以的话,最好做一个真正的 RPM。 但我离题了。

因此,打包(二进制)程序的基本步骤如下 - 我认为其中
程序是版本 1.0 的 toybinprog,在 /etc/toybinprog/toybinprog.conf 中安装一个conf,并在 /usr/bin 中安装一个名为 tobinprog 的 bin:

1. 为 RPM < 创建 rpm 构建环境 4.6,4.7

mkdir -p ~/rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp}

cat <<EOF >~/.rpmmacros
%_topdir   %(echo $HOME)/rpmbuild
%_tmppath  %{_topdir}/tmp
EOF

cd ~/rpmbuild

2. 创建项目的 tarball

mkdir toybinprog-1.0
mkdir -p toybinprog-1.0/usr/bin
mkdir -p toybinprog-1.0/etc/toybinprog
install -m 755 toybinprog toybinprog-1.0/usr/bin
install -m 644 toybinprog.conf toybinprog-1.0/etc/toybinprog/

tar -zcvf toybinprog-1.0.tar.gz toybinprog-1.0/

3. 复制到源目录

cp toybinprog-1.0.tar.gz SOURCES/

cat <<EOF > SPECS/toybinprog.spec
# Don't try fancy stuff like debuginfo, which is useless on binary-only
# packages. Don't strip binary too
# Be sure buildpolicy set to do nothing
%define        __spec_install_post %{nil}
%define          debug_package %{nil}
%define        __os_install_post %{_dbpath}/brp-compress

Summary: A very simple toy bin rpm package
Name: toybinprog
Version: 1.0
Release: 1
License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: http://toybinprog.company.com/

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

%description
%{summary}

%prep
%setup -q

%build
# Empty section.

%install
rm -rf %{buildroot}
mkdir -p  %{buildroot}

# in builddir
cp -a * %{buildroot}


%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%{_bindir}/*

%changelog
* Thu Apr 24 2009  Elia Pinto <[email protected]> 1.0-1
- First Build

EOF

4. 构建源代码和二进制 rpm

rpmbuild -ba SPECS/toybinprog.spec

就这样。

希望这有帮助

I often do binary rpm per packaging proprietary apps - also moster as websphere - on linux.
So my experience could be useful also a you, besides that it would better to do a TRUE RPM if you can. But i digress.

So the a basic step for packaging your (binary) program is as follow - in which i suppose the
program is toybinprog with version 1.0, have a conf to be installed in /etc/toybinprog/toybinprog.conf and have a bin to be installed in /usr/bin called tobinprog :

1. create your rpm build env for RPM < 4.6,4.7

mkdir -p ~/rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp}

cat <<EOF >~/.rpmmacros
%_topdir   %(echo $HOME)/rpmbuild
%_tmppath  %{_topdir}/tmp
EOF

cd ~/rpmbuild

2. create the tarball of your project

mkdir toybinprog-1.0
mkdir -p toybinprog-1.0/usr/bin
mkdir -p toybinprog-1.0/etc/toybinprog
install -m 755 toybinprog toybinprog-1.0/usr/bin
install -m 644 toybinprog.conf toybinprog-1.0/etc/toybinprog/

tar -zcvf toybinprog-1.0.tar.gz toybinprog-1.0/

3. Copy to the sources dir

cp toybinprog-1.0.tar.gz SOURCES/

cat <<EOF > SPECS/toybinprog.spec
# Don't try fancy stuff like debuginfo, which is useless on binary-only
# packages. Don't strip binary too
# Be sure buildpolicy set to do nothing
%define        __spec_install_post %{nil}
%define          debug_package %{nil}
%define        __os_install_post %{_dbpath}/brp-compress

Summary: A very simple toy bin rpm package
Name: toybinprog
Version: 1.0
Release: 1
License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: http://toybinprog.company.com/

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

%description
%{summary}

%prep
%setup -q

%build
# Empty section.

%install
rm -rf %{buildroot}
mkdir -p  %{buildroot}

# in builddir
cp -a * %{buildroot}


%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%{_bindir}/*

%changelog
* Thu Apr 24 2009  Elia Pinto <[email protected]> 1.0-1
- First Build

EOF

4. build the source and the binary rpm

rpmbuild -ba SPECS/toybinprog.spec

And that's all.

Hope this help

秋叶绚丽 2024-07-28 02:18:56

作为应用程序分发者,fpm 听起来非常适合您的需求这里有一个示例,它展示了如何打包来自源的应用程序。 FPM 可以生成 deb 文件和 RPM 文件。

As an application distributor, fpm sounds perfect for your needs. There is an example here which shows how to package an app from source. FPM can produce both deb files and RPM files.

怀里藏娇 2024-07-28 02:18:56

同样,我需要创建一个只有几个文件的 rpm。 由于这些文件是受源代码控制的,并且因为这看起来很愚蠢,所以我不想只是为了用 rpm 解压它们而对它们进行皮重处理。 我提出了以下建议:

  1. 设置您的环境:

    mkdir -p ~/rpm/{BUILD,RPMS}

    echo '%_topdir %(echo "$HOME")/rpm' > ~/.rpmmacros

  2. 创建您的规范文件 foobar.spec,其中包含以下内容:

    摘要:Foo 到酒吧 
      名称: foobar 
      版本:0.1 
      发布:1 
      组:Foo/Bar 
      许可证: FooBarPL 
      来源:%{展开:%%(pwd)} 
      BuildRoot: %{_topdir}/BUILD/%{名称}-%{版本}-%{发布} 
    
      %描述 
      %{概括} 
    
      %准备 
      rm -rf $RPM_BUILD_ROOT 
      mkdir -p $RPM_BUILD_ROOT/usr/bin 
      mkdir -p $RPM_BUILD_ROOT/etc 
      cd $RPM_BUILD_ROOT 
      cp %{SOURCEURL0}/foobar ./usr/bin/ 
      cp %{SOURCEURL0}/foobar.conf ./etc/ 
    
      %干净的 
      rm -r -f "$RPM_BUILD_ROOT" 
    
      %个文件 
      %defattr(644,根,根) 
      %config(noreplace) %{_sysconfdir}/foobar.conf 
      %defattr(755,根,根) 
      %{_bindir}/foobar 
      
  3. 构建您的 rpm:
    rpmbuild -bb foobar.spec

那里有一点黑客行为,将“源”指定为当前目录,但它看起来比替代方案要优雅得多,在我的例子中,这是编写一个单独的脚本创建 tarball 等。

注意:在我的特定情况下,我的文件根据需要放置的位置排列在文件夹中,如下所示:

./etc/foobar.conf
./usr/bin/foobar

因此准备部分变为:

%prep
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT
cd $RPM_BUILD_ROOT
tar -cC %{SOURCEURL0} --exclude 'foobar.spec' -f - ./ | tar xf -

这更干净一些。

另外,我碰巧使用的是 RHEL5.6,rpm 版本为 4.4.2.3,因此您的情况可能会有所不同。

Similarly, I needed to create an rpm with just a few files. Since these files were source controlled, and because it seemed silly, I didn't want to go through taring them up just to have rpm untar them. I came up with the following:

  1. Set up your environment:

    mkdir -p ~/rpm/{BUILD,RPMS}

    echo '%_topdir %(echo "$HOME")/rpm' > ~/.rpmmacros

  2. Create your spec file, foobar.spec, with the following contents:

    Summary: Foo to the Bar
    Name: foobar
    Version: 0.1
    Release: 1
    Group: Foo/Bar
    License: FooBarPL
    Source: %{expand:%%(pwd)}
    BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}
    
    %description
    %{summary}
    
    %prep
    rm -rf $RPM_BUILD_ROOT
    mkdir -p $RPM_BUILD_ROOT/usr/bin
    mkdir -p $RPM_BUILD_ROOT/etc
    cd $RPM_BUILD_ROOT
    cp %{SOURCEURL0}/foobar ./usr/bin/
    cp %{SOURCEURL0}/foobar.conf ./etc/
    
    %clean
    rm -r -f "$RPM_BUILD_ROOT"
    
    %files
    %defattr(644,root,root)
    %config(noreplace) %{_sysconfdir}/foobar.conf
    %defattr(755,root,root)
    %{_bindir}/foobar
    
  3. Build your rpm:
    rpmbuild -bb foobar.spec

There's a little hackery there specifying the 'source' as your current directory, but it seemed far more elegant then the alternative, which was to, in my case, write a separate script to create a tarball, etc, etc.

Note: In my particular situation, my files were arranged in folders according to where they needed to go, like this:

./etc/foobar.conf
./usr/bin/foobar

and so the prep section became:

%prep
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT
cd $RPM_BUILD_ROOT
tar -cC %{SOURCEURL0} --exclude 'foobar.spec' -f - ./ | tar xf -

Which is a little cleaner.

Also, I happen to be on a RHEL5.6 with rpm versions 4.4.2.3, so your mileage may vary.

风吹雪碎 2024-07-28 02:18:56

#要快速构建 RPM,请查看 Togo:

https://github.com/genereese/togo-rpm< /a>

它是 rpmbuild 的轻量级包装器,只需为您完成手动工作(规范文件生成、构建准备等)。 因此,如果您的项目超出了 Togo 的规模,或者您只是出于某种原因想停止使用它,您可以随时停止使用它,只需使用“rpmbuild”即可。

该项目有一个快速入门指南,我能够在不到 3 分钟的时间内创建一个基本的 RPM。

##使用原始问题中提供的数据的示例:

  1. 使用脚本创建项目目录:

    $ togo 项目创建 foobar; cd foobar

  2. 在 ./root 下创建所需的目录结构并将文件复制到其中:

    $ mkdir -p root/etc; cp /path/to/foobar.conf root/etc/
    $ mkdir -p root/usr/bin; cp /path/to/foobar root/usr/bin/

  3. 从 RPM 所有权中排除系统拥有的目录:

    $ togo 文件排除 root/etc root/usr/bin

  4. (可选)修改生成的规范以更改包描述/依赖项/版本/其他内容等:

    $ vi 规范/标题

  5. 构建 RPM:

    $ togo 构建包

- 然后你的 RPM 将被放入 ./rpms 目录中。

#For quick RPM building, check out Togo:

https://github.com/genereese/togo-rpm

It's a lightweight wrapper around rpmbuild that simply does the manual work for you (spec file generation, build prep, etc.). Because of this, you can stop using it whenever you want and simply use 'rpmbuild' instead if your project outgrows Togo or you simply want to stop using it for whatever reason.

The project has a Quick-Start guide and I was able to create a basic RPM in less than 3 minutes.

##Example using the data provided in the original question:

  1. Create the project directory using the script:

    $ togo project create foobar; cd foobar

  2. Make your desired directory structure under ./root and copy your files into it:

    $ mkdir -p root/etc; cp /path/to/foobar.conf root/etc/
    $ mkdir -p root/usr/bin; cp /path/to/foobar root/usr/bin/

  3. Exclude system-owned directories from your RPM's ownership:

    $ togo file exclude root/etc root/usr/bin

  4. (OPTIONAL) Modify the generated spec to change your package description/dependencies/version/whatever, etc.:

    $ vi spec/header

  5. Build the RPM:

    $ togo build package

-and your RPM is spit out into the ./rpms directory.

別甾虛僞 2024-07-28 02:18:56

从二进制构建 rpm 包的简单方法(这些步骤已使用 Fedora 18 进行测试):

1)首先您必须安装 rpmdevtools,因此运行这些命令(注意:以普通用户身份运行)

$ sudo yum install rpmdevtools rpmlint
$ rpmdev-setuptree

2)在 ~/rpmbuild/SPECS 文件夹中创建新文件:package_name.spec

3) 使用编辑器(如 gedit)打开它并编写以下内容:

Name:           package_name
Version:        1.0
Release:        1
Summary:        Short description (first char has to be uppercase)

License:        GPL
URL:            www. your_website/

BuildRequires:  package_required >= (or ==, or <=) 1.0.3 (for example)

%description
Description with almost 79 characters (first char has to be uppercase)

#This is a comment (just as example)

%files
/usr/bin/binary_file.bin
/usr/share/applications/package_name.desktop
/usr/share/pixmaps/package_name.png

%changelog
* date Packager's Name <packager's_email> version-revision
- Summary of changes

#For more details see: docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Packagers_Guide/sect-Packagers_Guide-Creating_a_Basic_Spec_File.html

4) 创建 ~/rpmbuild/BUILDROOT/package_name-version-release.i386 并重现放置文件的路径
因此,在这种情况下,例如创建:

  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/bin/
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/applications/
  • ~/rpmbuild/ BUILDROOT/package_name-version-release.i386/usr/share/pixmaps/

5) 将要插入包中的文件放入这些文件夹中:

  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/bin/ binary_file.bin
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/applications/package_name.desktop
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/pixmaps/package_name.png

usr /share/pixmaps/package_name.png 是二进制的图标
usr/share/applications/package_name.desktop 是在菜单项中插入程序的规则

6) package_name.desktop 必须是这样的:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=example
GenericName=Short description
Comment=Comment of the application
Exec=package_name
Icon=package_name
Terminal=false
Categories=System;

类别如下:standards.freedesktop.org/menu-spec/latest/apa.html

7 ) 运行 $ rpmbuild -bb ~/rpmbuild/SPECS/package_name.spec

8) 您的软件包已内置到 ~/rpmbuild/RPMS 文件夹中,

如果您安装此软件包,则它的安装位置为:

  • /usr/bin/binary_file。 bin
  • /usr/share/applications/package_name.desktop
  • /usr/share/pixmaps/package_name.png

感谢:losurs.org/docs/tips/redhat/binary-rpms

有关构建 rpm 的更多详细信息,请查看此 链接

用于构建 rpm 的 GUI java 软件: https://sourceforge.net/projects/javarpmbuilder/

Easy way to build rpm package from binary (these steps were tested with Fedora 18):

1) First you have to install rpmdevtools, so run these commands (attention: run as normal user)

$ sudo yum install rpmdevtools rpmlint
$ rpmdev-setuptree

2) In the ~/rpmbuild/SPECS folder create new file: package_name.spec

3) Open it with an editor (like gedit) and write this:

Name:           package_name
Version:        1.0
Release:        1
Summary:        Short description (first char has to be uppercase)

License:        GPL
URL:            www. your_website/

BuildRequires:  package_required >= (or ==, or <=) 1.0.3 (for example)

%description
Description with almost 79 characters (first char has to be uppercase)

#This is a comment (just as example)

%files
/usr/bin/binary_file.bin
/usr/share/applications/package_name.desktop
/usr/share/pixmaps/package_name.png

%changelog
* date Packager's Name <packager's_email> version-revision
- Summary of changes

#For more details see: docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Packagers_Guide/sect-Packagers_Guide-Creating_a_Basic_Spec_File.html

4) Make ~/rpmbuild/BUILDROOT/package_name-version-release.i386 and reproduce the paths where the files will be placed
So in this case for example create:

  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/bin/
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/applications/
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/pixmaps/

5) Put in these folders the files that you want insert in the package:

  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/bin/binary_file.bin
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/applications/package_name.desktop
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/pixmaps/package_name.png

usr/share/pixmaps/package_name.png is the icon of binary
usr/share/applications/package_name.desktop are the rules to insert the program in the menu entries

6) package_name.desktop must be like this:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=example
GenericName=Short description
Comment=Comment of the application
Exec=package_name
Icon=package_name
Terminal=false
Categories=System;

Categories are these: standards.freedesktop.org/menu-spec/latest/apa.html

7) Run $ rpmbuild -bb ~/rpmbuild/SPECS/package_name.spec

8) Your package was built into ~/rpmbuild/RPMS folder

if you install this package it's install:

  • /usr/bin/binary_file.bin
  • /usr/share/applications/package_name.desktop
  • /usr/share/pixmaps/package_name.png

Thanks to: losurs.org/docs/tips/redhat/binary-rpms

For more details to build rpm take a look at this link.

GUI java software to build rpm: https://sourceforge.net/projects/javarpmbuilder/

ゞ花落谁相伴 2024-07-28 02:18:56

如果 make config 适用于您的程序,或者您有一个 shell 脚本将两个文件复制到适当的位置,您可以使用 checkinstall。 只需转到 makefile 所在的目录并使用参数 -R(对于 RPM)以及可选的安装脚本来调用它。

If make config works for your program or you have a shell script which copies your two files to the appropriate place you can use checkinstall. Just go to the directory where your makefile is in and call it with the parameter -R (for RPM) and optionally with the installation script.

玻璃人 2024-07-28 02:18:56

如果您熟悉 Maven,还有 rpm-maven-plugin 可以简化 RPM 的制作:您只需编写 pom.xml 即可用于构建 RPM。 RPM 构建环境是由插件隐式创建的。

If you are familiar with Maven there also rpm-maven-plugin which simplifies making RPMs: you have to write only pom.xml which will be then used to build RPM. RPM build environment is created implicitly by the plugin.

迷乱花海 2024-07-28 02:18:56

从源文件生成RPM的过程:

  1. 下载扩展名为.gz的源文件。
  2. 从 yum install 安装 rpm-build 和 rpmdevtools。 (将生成 rpmbuild 文件夹...SPECS、SOURCES、RPMS .. 文件夹将在 rpmbuild 文件夹内生成)。
  3. 将源代码.gz 复制到 SOURCES 文件夹。(rpmbuild/SOURCES)
  4. 使用以下命令解压 tar 球。
    转至 SOURCES 文件夹:rpmbuild/SOURCES,其中存在 tar 文件。
    命令:例如 tar -xvzf httpd-2.22.tar.gz
    同一路径下会生成httpd-2.22文件夹。
  5. 转到解压的文件夹,然后输入以下命令:
    ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-proxy --enable-proxy-balancer --with-mpm=worker --enable-mods-static=all
    (.configure 可能会根据必须构建 RPM 的源而有所不同——我已经为需要 apr 和 apr-util 依赖包的 apache HTTPD 做了配置)。
  6. 配置成功后运行以下命令:
  7. 成功执行 od make 命令后运行
    检查安装
    在同一个文件夹中。 (如果您没有 checkinstall 软件,请从网站下载最新版本)
    另外checkinstall软件也有bug,可以通过以下方式解决:::::
    找到 checkinstallrc,然后使用 vim 命令将 TRANSLATE = 1 替换为 TRANSLATE=0。
    还要检查排除包: EXCLUDE="/selinux"
  8. checkinstall 将询问选项(如果您想要为源文件构建 rpm,请键入 R)
  9. 完成的 .rpm 文件将构建在 rpmbuild/RPMS 文件内的 RPMS 文件夹中...
    一切顺利 ....

Process of generating RPM from source file:

  1. download source file with.gz extention.
  2. install rpm-build and rpmdevtools from yum install. (rpmbuild folder will be generated...SPECS,SOURCES,RPMS.. folders will should be generated inside the rpmbuild folder).
  3. copy the source code.gz to SOURCES folder.(rpmbuild/SOURCES)
  4. Untar the tar ball by using the following command.
    go to SOURCES folder :rpmbuild/SOURCES where tar file is present.
    command: e.g tar -xvzf httpd-2.22.tar.gz
    httpd-2.22 folder will be generated in the same path.
  5. go to extracted folder and then type below command:
    ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-proxy --enable-proxy-balancer --with-mpm=worker --enable-mods-static=all
    (.configure may vary according to source for which RPM has to built-- i have done for apache HTTPD which needs apr and apr-util dependency package).
  6. run below command once the configure is successful:
    make
  7. after successfull execution od make command run:
    checkinstall
    in tha same folder. (if you dont have checkinstall software please download latest version from site)
    Also checkinstall software has bug which can be solved by following way:::::
    locate checkinstallrc and then replace TRANSLATE = 1 to TRANSLATE=0 using vim command.
    Also check for exclude package: EXCLUDE="/selinux"
  8. checkinstall will ask for option (type R if you want tp build rpm for source file)
  9. Done .rpm file will be built in RPMS folder inside rpmbuild/RPMS file...
    ALL the BEST ....
他是夢罘是命 2024-07-28 02:18:56

RPM 通常是从源代码构建的,而不是二进制文件。

您需要编写规范文件,其中涵盖如何配置和编译您的应用程序; 另外,哪些文件要包含在 RPM 中。

快速浏览一下该手册就会发现,第 8 章涵盖了您需要的大部分内容——而且,由于大多数基于 RPM 的发行版都有可用的源代码,因此您可以查看无数不同方法的示例。

RPMs are usually built from source, not the binaries.

You need to write the spec file that covers how to configure and compile your application; also, which files to include in your RPM.

A quick glance at the manual shows that most of what you need is covered in Chapter 8 -- also, as most RPM-based distributions have sources available, there's literally a zillion of examples of different approaches you could look at.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文