RPM build issues - linux

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.

Related

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

Installing RPM doesn't run all the %install actions listed in .spec

TL;DR: I made a .spec file that successfully builds a .rpm, but rpm -i <file>.rpm doesn't do all the actions I think it should. Why?
Excerpt from <file>.spec:
%install
sudo python2.7 -m pip install 'tornado<5'
...#other pip commands...
cp -r $RPM_BUILD_DIR/%{name}-%{version}/* %{buildroot}
(I know this isn't the ideal way to do it, but I'm forced to use CentOS 6 and can't upgrade the system version of python because corporate/shared environment so this was the best way I could figure out.)
All the commands under %install are correctly run when building the .rpm, so all of the pip packages get installed on the machine creating the .rpm from the .spec. rpmbuild -ba <file>.spec completes with exit 0. However, when I try to install the .noarch.rpm file that is created (on another system with identical OS/architecture), all that happens is the rpm-specified dependencies get installed and the files get shoved to the correct directories, but the other commands from %install are not run. What ends up happening is that I try to call the executable that gets made and it errors out because of the missing python packages.
RPM.org says:
Performing any tasks required before the install:
There are cases where one or more commands must be given prior to the actual installation of a package. RPM performs these commands exactly as directed by the package builder, thus eliminating a common source of problems during installations.
...Where am I supposed to specify the commands run prior to package installation if not in the %install field of the .spec file?
If you want to run commands after the rpm is installed the, you need to place those commands in the %post target.
If you want the commands to be run right before the rpm itself is installed, place the commands in the %pre target.
The commands in %install is executed when you build the .rpm, it is not run when you install the .rpm.
%install is intended to install your software onto a sandboxed directory hierarchy which should then be packaged and included into the .rpm file.
Don't run commands in %install that alters any system state or that affects anything outside the $RPM_BUILD_DIR or %{buildroot}
The %install scriptlet is run during build, not while installing.
If you wish commands to be run while installing a package, then you need to use the %post section in the spec file.
As others noted, %install is the script section within a specfile to copy the files that have already been compiled during the %build phase (which can be a no-op for python). However, others have not yet noted that sudo python2.7 -m pip install 'tornado<5' is definitely not a command that you should be using in a specfile. You need to get the python files some other way and install them into the proper locations under %{buildroot}.
RPMs should never be built as the root user nor call sudo anywhere. EVER.

How do I link C code against BoringSSL?

I want to install BoringSSL and link against BoringSSL instead of OpenSSL on Ubuntu.
I couldn't find a simply tutorial of how to do this, the building instructions here are vague.
1) Install the language go, if not already done. https://golang.org/doc/install?download=go1.8.1.linux-amd64.tar.gz
Example :
cd /usr/local/
sudo tar xvf [path-to]/go1.8.1.linux-amd64.tar.gz
cd bin/
sudo ln -s ../go/bin/go* ./
2) boringssl, please read README.md, BUILDING.md ...
cd boringssl/
mkdir build
cd build/
cmake ../
make
There is no 'make install'. You will have to find libssl.a (in build/ssl/) etc. etc., and point to -lssl when using. ( Unfortunately you may already have like /usr/lib/libssl.so, which will be linked to, if first in the LD_LIBRARY_PATH ).

Recipe file installing in different directory

I am trying to add one package into my Yocto image. Currently, I can build my image, but when I install the image, the software is being installed in different directory. Are there any ways to reroute the installation directory. Example the library files should be installed in /usr/lib64 but its installed in /usr/lib/.
I have just figure out that when i build the application .ipk file inside dont have the /usr/lib64/ folder. Which means the files is not being added into it. Are there anyways to solve this?
This is my FILES_${PN} code:
FILES_${PN} = "/usr/lib/* \
/usr/lib64/* \
/usr/bin/* \
/etc/* "
Update 1
This is my do_install code:
do_install(){
cp -r ${WORKDIR}/xxx/* ${WORKDIR}/image/
install -d ${D}/usr/lib64
install -m 0644 ${WORKDIR}/xxx/usr/lib64/* ${D}/usr/lib64/
}
All the files listed there are being added into the ipk file except of the /usr/lib64/* files. Are this are the right way of doing it. Please can someone help me on this. Thanks in advance.
You can install libraries manually within a recipe:
do_install() {
install -d ${D}/usr/lib64 # ${D}${libdir} maybe also works
install -m 0644 libexample.a ${D}/usr/lib64
}
D variable explanation from Reference Manual:
The destination directory. The location in the Build Directory where components are installed by the do_install task. This location defaults to:
${WORKDIR}/image
You can find the content of the variables via following command (libdir variable as example):
bitbake -e | grep ^libdir

rpmbuild: how to build the package without %install?

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.

Resources