rpmbuild: how to build the package without %install? - linux

I am trying to build a rpm but unfortunately in my build machine I only have limted permission, which means the operation in %install can't be done inside the build machine. How to build the package(.rpm file) without running %install section? It looks like that no options are available for this purpose:
http://www.rpm.org/max-rpm-snapshot/ch-rpm-b-command.html
My bu.spec file:
Summary: xxxx
Name: xx
Version: 1.0
Release: 1
Group: Applications/Sound
License: Share
%description
%prep
echo "prep"
%build
%install
echo "install"
mkdir -p /opt/xcp_src/
cp scripts.tgz /opt/xcp_src/
%files
/tmp/xcp_src/scripts.tgz
%post
cd /opt/xcp_src/
tar zxvf scripts.tgz

First off, set a buildroot and use that in install, eg:
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
...
%install
mkdir -p %{buildroot}/opt/xcp_src
Second, make sure you can build without being root by moving the RPM build area.
I'd also suggest specifying an actual list of files (rather than having RPM extract a tgz file) as that would make the package cleanly removable.

Related

RHEL 8 find-debuginfo.sh gdb-add-index: No index was created

Trying to generate rpm on RHEL8 Machine. The same rpm_build.sh script works fine on RHEL6 & RHEL7. But in RHEL 8 its failing to generate debuginfo packages.
RPM BUILD VERSION :
$ sudo yum install rpm-build
Package rpm-build-4.14.3-23.el8.x86_64 is already installed.
+ install -m 755 libclntshcore.so.12.1 /home/opc/rpmbuild/BUILDROOT/my_lib-23.1.3-1.el8.x86_64/usr/lib64/pam/libclntshcore.so.12.1
+ install -m 755 libnnz12.so /home/opc/rpmbuild/BUILDROOT/my_lib-23.1.3-1.el8.x86_64/usr/lib64/pam/libnnz12.so
/usr/lib/rpm/find-debuginfo.sh -j8 --strict-build-id -m -i --build-id-seed 23.1.3-1.el8 --unique-debug-suffix -23.1.3-1.el8.x86_64 --unique-debug-src-base my_lib-23.1.3-1.el8.x86_64 --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 110000000 -S debugsourcefiles.list /home/opc/rpmbuild/BUILD/my_lib-23.1.3
extracting debug info from /home/opc/rpmbuild/BUILDROOT/my_lib23.1.3-1.el8.x86_64/usr/lib64/pam/libclntshcore.so.12.1
extracting debug info from /home/opc/rpmbuild/BUILDROOT/my_lib-23.1.3-1.el8.x86_64/usr/lib64/pam/libnnz12.so
gdb-add-index: No index was created for /home/opc/rpmbuild/BUILDROOT/my_lib-23.1.3-1.el8.x86_64/usr/lib64/pam/libons.so
gdb-add-index: [Was there no debuginfo? Was there already an index?]
gdb-add-index: No index was created for /home/opc/rpmbuild/BUILDROOT/my_lib-23.1.3-1.el8.x86_64/usr/lib64/pam/libclntshcore.so.12.1
gdb-add-index: [Was there no debuginfo? Was there already an index?]
My Spec.file
Name: my_lib-devel
Version: %{pkg_version}
Release: %{pkg_release}%{?dist}
Group: System Environment/Libraries
Source0: %{_sourcedir}/%{name}-%{version}.tar.gz
Requires: my_lib
%global debug_package %{nil}
%global _lib_authn_api_filename libauthn_api.so
%global _package_name my_lib
%description
developemnt package
%prep
%setup -q
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%build
%install
mkdir -p %{buildroot}/%{_includedir}/%{_package_name}
mkdir -p %{buildroot}%{_datadir}/doc/%{name}
cp *.h %{buildroot}/%{_includedir}/%{_package_name}
install -m 644 README %{buildroot}%{_datadir}/doc/%{name}/README
install -m 644 LICENCE %{buildroot}%{_datadir}/doc/%{name}/LICENCE
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
/%{_includedir}/%{_package_name}/*.h
%doc %{_datadir}/doc/%{name}/*
Not sure why it complaints while extracting debug info
When I ran it on RHEL6 / RHEL7 same thing works fine . Is something is updated in RHEL8 which I'm missing or do I need to update the specs to work on RHEL8 . I have tried couple of solution Like %global debug_package %{nil} or %define debug_package %{nil} But nothing works.
Kindly Help !

RPM post scriptlets permission denied with docker commands

So I'm building a rpm package with some pre-loaded docker image, and I want to load the image to the system and delete the image tar file after installation.
I've already achieved this in a debian package by simply adding these 2 lines in postinst file:
docker load -i <path>/image.tar
rm <some_path>/image.tar
However I got some troubles doing this in RPM package and here's the .spec file roughly looks like:
%prep
%build
%install
mkdir -p %{buildroot}/etc/my_app/
cp app %{buildroot}/etc/my_app/app
cp image.tar %{buildroot}/etc/my_app/image.tar
%post
docker load -i /etc/my_app/image.tar
rm /etc/my_app/image.tar
%files
/etc/my_app/app
/etc/my_app/image.tar
%changelog
The first problem is that when installing the package, I got /bin/docker: Permission denied error when running the %post scriptlets. (hence the image wasn't successfully loaded).
The second one is that when uninstalling the package, I got the warning: file /etc/edgexpert/image.tar: remove failed: No such file or directory. I guess this is because I put the image.tar file under $file.
So my questions would be :
how to make the docker command runnable?
where to put my image.tar file so that it can be used during %post scriptlets and won't be checked in %file
Thanks for the help.
Edited:
[vagrant#localhost ~]$ ls -l /bin/docker
-rwxr-xr-x. 1 root root 84956288 Jun 1 09:14 /bin/docker

Spec file for building .tar.gz as .rpm

I'd like to improve the distribution and versioning of a program I've inherited, which is currently distributed as a .tar.gz file, by building a .rpm for RHEL7 that just extracts the contents to /usr/bin/. The tarball is not small, consisting in around 120 MB worth of files.
I'm new around package building so I've been following the bello example from https://rpm-packaging-guide.github.io, but the example is too simple for my needs.
So far I have this .spec file:
Name: my-app
Version: 2.0
Release: 1%{?dist}
Summary: My application
License: Internal license
URL: <my-website>
Source0: <my-website>/%{name}-%{version}.rhel7.x86_64.tar.gz
Requires: bash
BuildArch: x86_64
%description
My application
%prep
%setup -q
%build
%install
mkdir -p %{buildroot}/%{_bindir}
install -m 0755 %{name} %{buildroot}/%{_bindir}/%{name}
%files
%{_bindir}/%{name}
Which generates a very small .rpm with just /usr/bin/my-app. On installation if complains about many missing dependencies that are inside the tarball's lib directory, but of course not in my package.
As far as I understand, the %files directive must contain a list of all the files that are supposed to be inside the .rpm, but those are hundreds. So I'm assuming there's a better way to build the package, after all is just decompressing the tarball.
Do you have any pointers?
install -m 0755 %{name} %{buildroot}/%{_bindir}/%{name}
you are only installing the binary. You should also install the dependencies if they are in your tgz, Then make sure to package them as well under %files.

How to install rpmdev tools on ubuntu?

I am creating my first package using RPM on ubuntu machine.But I am getting so many difficulties.I tried so many commands to install rpmdevtools using "yum" but it is giving error as There are not repos enabled.
When I try to install it using apt-get it gives error as Unable to locate the package.
Can anybody suggest the proper start to end procedure with commands to build a package using RPM?
rpmdev is mostly optional. rpm is enough. The following describes the minimum steps to package a script program into a RPM file on Debian.
Install rpmbuild:
apt-get install rpm
Create a helloworld program:
cat > helloworld <<EOF
#! /bin/bash
printf "Hello World!\n"
EOF
chmod +x helloworld
Create a minimal specification helloworld.spec:
Name: helloworld
Version: 1.0
Release: 1%{?dist}
Summary: Hello World
License: GPLv3+
BuildArch: noarch
%description
Hello World!
%prep
%build
%install
mkdir -p %{buildroot}/%{_bindir}
install -m 0755 %{name} %{buildroot}/%{_bindir}/%{name}
%files
%{_bindir}/%{name}
%changelog
Build the RPMs:
rpmbuild -ba --build-in-place --define "_topdir $(pwd)/rpm" helloworld.spec
mv rpm/SRPMS/*.rpm .
mv rpm/RPMS/*/*.rpm .
rm -rf rpm
But you will not be able to install it on Debian or Ubuntu. The installation requires Fedora or Red Hat.

RPM build issues

I have an RPM spec file like this, I have compiled a C file and created an executable and trying to copy it to buildroot/tmp folder and trying to execute it from there,
%install
mkdir -p %{buildroot}/tmp/
install -m 755 /root/Desktop/np %{buildroot}/tmp/np
./%{buildroot}/tmp/np
%files
/tmp/np
When I try to build the RPM, I am facing an error
"/var/tmp/rpm-tmp.0HMeZn: line 35:
.//root/rpmbuild/BUILDROOT/hp-simulate-generalfailure1-1.0.0-1.x86_64/tmp/np:
No such file or directory"
Help me out to make a clean build. Thanks in advance.
Let's put aside that you are doing something very strange and executing rpmbuild as root (very nasty).
The %{buildroot} is an absolute path. See:
$ rpm --eval '%{buildroot}'
/home/msuchy/rpmbuild/BUILDROOT/%{NAME}-%{VERSION}-%{RELEASE}.x86_64
If you are really trying to execute that binary, you should not put the leading ./ there. So you snippet should be:
%install
mkdir -p %{buildroot}/tmp/
install -m 755 /root/Desktop/np %{buildroot}/tmp/np
%{buildroot}/tmp/np
%files
/tmp/np
Running anything in %install section will occur only on the build machine, during rpm build process. It will not happen when you install the RPM.
To run something upon package installation, you have to make use of scriplets:
%install
mkdir -p %{buildroot}/tmp/
install -m 755 /root/Desktop/np %{buildroot}/tmp/np
%files
/tmp/np
%post
/tmp/np
In example above, /tmp/np will be executed when package is either installed for the first time, or upgraded.

Resources