%prep problems when building RPMs on CentOS 7 - linux

Following all the random guides on the net and even on here:
What is the minimum I have to do to create an RPM file?
Nothing seems to work with Centos 7 (surprise!)
It seems if you leave %prep in your spec file, rpmbuild will try its hardest to ./configure and make something. what I'm not sure.
here is a super basic .spec file I'm trying to make an rpm to just copy in a file.
$more newpackage.spec
Name: hello
Version: 1.2
Release: 1%{?dist}
Summary: Testing testing 1 2 3
License: Beer
URL: No
#so apparently now you have to have version numbers everywhere, even the tar files, uhg
Source0: hello-1.2.tar.gz
#and the breaking begins :-( why everything broke with you centos 7?
# BuildRoot: %{_tmppath}/%{name}-%{version}-root
# BuildRequires:
# Requires:
%description
nothing to see here folks
#well here is some of the confusion
#%prep
%setup -q
# ./configure missing? um yeahhhh
# %build
# %configure
# make %{?_smp_mflags}
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
%files
#/usr/bin/hello.sh
%{_bindir}/hello.sh
# %doc
# %changelog
in side the tar file is /usr/bin/hello.sh
which is shell script that just runs echo "hello world"
if i comment %prep rpmbuild complains about ./configure not being found.
rpmbuild -v -bb newpackage.spec

Looks like commenting out %build dosen't actully stop rpmbuild from trying to build the sources...
so if i DELETE out %build and %configure and that make line. things work

Related

rpminstall - run shell script inside rpm during install

I am working on an RPM which unpackages a tar file into an RPM whenever I run rpmbuild. I have two questions around the process:
Is my process of unpackaging the tar file into the RPM correct?
When I install the actual rpm onto a server, I'd like it to run a script inside the RPM which I have copied in called install.sh. How do I do that?
%build
# let's skip this for now
%install
mkdir -p %{buildroot}
chmod 755 ~/rpmbuild/SOURCES/bin/*
cp -frv ~/rpmbuild/SOURCES/bin/* %{buildroot}
%files
/*
%changelog
# let's skip this for now
Generally RPM support pre and post installation/uninstall scripts. And they are defined with %pre, %post, %preun and %postun. So if you are sure this file (install.sh) already exist you can run it on this way:
%pre
/path/to/install.sh
or
%post
/path/to/install.sh

Error while creating rpm package using rpmbuild from spec file

I want to build a rpm package from a spec file(hello-world.spec).The command and error output are given below
Command1:
rpmbuild -ba hello-world.spec
ErrorOutput1:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.z4GoQn
+ umask 022
+ cd /root/rpmbuild/BUILD
+
: not foundm-tmp.z4GoQn: 28: /var/tmp/rpm-tmp.z4GoQn:
error: Bad exit status from /var/tmp/rpm-tmp.z4GoQn (%prep)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.z4GoQn (%prep)
Content of my spec file is
Name: hello-world
Version: 1
Release: 1
Summary: Most simple RPM package
License: FIXME
%description
This is my first RPM package, which does nothing.
%prep
# we have no source, so nothing here
%build
cat > hello-world.sh <<EOF
#!/usr/bin/bash
echo Hello world
EOF
%install
mkdir -p %{buildroot}/usr/bin/
install -m 755 hello-world.sh %{buildroot}/usr/bin/hello-world.sh
%files
/usr/bin/hello-world.sh
%changelog
# let's skip this for now
My System/software details are
OS: Ubuntu 16.04
RPM version:4.12.0.1
The list of contents in rpmbuild folder is
Command2:
:~/rpmbuild# ls
Output2:
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
Can anybody help on this issue?
Check how your files is being generated. If you are passing files from windows to Linux, usually, there are different EOL for the files. We had a similar issue, I recommend you to change all the files to Unix format. I'm sharing with you how to reproduce your issue, if you edit that file in a Linux environment, like "nano", the problem disappears.

create var files under with "/" with rpmbuild

I'm new to the rpmbuild, googled and copy one spec file paramenters and created rpm successfully when i ran it the rpm nothing is creating
var.tar.gz -- this is my tar file. it has
var/
var/www/
var/www/html/index.html
My spec file
[root#kaka1 SPECS]# vi var.spec
Name: var
Version: 1
Release: 0
Summary: Xiph Streaming media server that supports multiple formats.
Group: Applications/Multimedia
License: GPL
URL: http################
Source: var-1.0.tar.gz
Prefix: %{_prefix}
Packager: Sukama
BuildRoot: %{_tmppath}/%{name}-root
%description
easily and supports open standards for commuincation and interaction.
%prep
rm -rf /root/rpmbuild/BUILD/*
%setup -n var
gzip -dc /root/rpmbuild/SOURCES/var-1.0.tar.gz| tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
could you help me where can i should mention my files to create under root?
First, don't use name like var, usr as package name, use that's more relevant to what the package may represent. Here is a simple spec file that should install index.html into the /var/www directory.
%define debug_package %{nil}
Summary: Simple SPEC
Name: simple
Version: 0
Release: 1
License: NONE # Use your suitable license
Group: NONE
URL: NONE
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
## Following lines are commented out, but that's the way to go
#BuildRequires: httpd # This needs https RPM during your build
#Requires: httpd # This would require httpd to be installed for this RPM
%description
%prep
%setup -q # This untars the source
%build # currently empty
%install # This moves into the source directory "simple-0" (see below)
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/var/www
install -m 0644 index.html %{buildroot}/var/www/index.html
%clean
rm -rf $RPM_BUILD_ROOT
%post
%files
%defattr(-,root,root,-)
%doc
/var/www/index.html # Your packages owns the file, but not the directories
%changelog
* Web Feb 14 2018 <user#localhost> - 0.0
- Initial build.
For the above .spec file, one would need a tarball named simple-0.tar.gz. This maps to the Source0 name that is used inside the .spec. The content in this case would be a directory and a file: simple-0/index.html.

How do I add an init script to my RPM

I want to add an init script to my RPM in order to run the program from a terminal just by typing its name, there's one more thing which I am confused about and that is:-
where are these files located: pre, post, preun, postun, are they written directly into the spec file after adding a line %pre etc.
I've been through the following links however I couldn't find a solution: -
https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd
https://fedoraproject.org/wiki/Packaging:Systemd?#Filesystem_locations
Updated===============================================================
I am doing it on CentOS 6.8 and here's the spec file I created so far:-
# RPM package for xyz.
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: XYZ program.
Name: xyz
Version: 1.0
Release: 1
License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: https://wwwDOTxyzDOTcom/
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
* Mon Mar 6 2017 xyz <noemail#noemail.com> 1.0-1
- First Build
EOF
but still confused as to how do I start the program from a terminal just by typing its name.
You mean SYSV init files? Or systemD unit files? Different logic, but ok - at the end they are both files. In different location, but just files.
You have to do:
%{?systemd_requires}
BuildRequires: systemd
%install
cp -a path/in/your/targz/SOMESERVICE.service %{buildroot}%{_unitdir}/
%post
%systemd_post SOMESERVICE.service
%preun
%systemd_preun SOMESERVICE.service
%postun
%systemd_postun_with_restart SOMESERVICE.service
%files
%{_unitdir}/SOMESERVICE.service
For SYSV there would be little bit different paths and different snippets in %post* and %preun.

CentOS 5.5 - symbolic link creation into RPM spec file

I need to create the following symbolic links into RPM file
/bin/ln -sf libcrypto.so.0.9.8e /lib/libcrypto.so.0.9.8
/bin/ln -sf libssl.so.0.9.8e /lib/libssl.so.0.9.8
In my RPM spec file:
%files
%defattr(-,root,root)
/lib/libcrypto.so.0.9.8
/lib/libssl.so.0.9.8
<other files...>
%install
/bin/ln -sf libcrypto.so.0.9.8e /lib/libcrypto.so.0.9.8
/bin/ln -sf libssl.so.0.9.8e /lib/libssl.so.0.9.8
The /lib/libcrypto.so.0.9.8e and /lib/libssl.so.0.9.8e are exists on my PC, but when I'm trying to install my RPM, I got an error:
libcrypto.so.0.9.8 is needed by my-test-rpm-1.el5.i686
libssl.so.0.9.8 is needed by my-test-rpm-1.el5.i686
What wrong? What I need to do in order to create symbolic links as part of the RPM installation?
Thanks
As workaround I disabled automatic dependency processing by adding:
AutoReqProv: no
to my spec file.
I'm still looking for the real solution.
You need to run ldconfig in the %post part of the spec file:
%post
umask 007
/sbin/ldconfig > /dev/null 2>&1
%postun
umask 007
/sbin/ldconfig > /dev/null 2>&1
should do it.
1) Just for symlinks you don't need to call ldconfig at post stage.
2) As already mentioned by ldav1s: Be sure that your files are listed in %files section.
3) Once again: Be sure that your files are listed - especially if you use something like
%define _unpackaged_files_terminate_build 0
RHEL rpmbuild terminates with an error if files are found in buildroot which are not listed in %files section. With this define you can switch the behaviour/error off but you should exactly know what you are actually doing. If you use this line you should remove it from your spec file.
4) Don't build the rpm package as user root. If you forget to use rpm_build_root you won't destroy your live system. Your example looks like it was taken from a spec file of Red Hat 4.2 of 1997. Since Red Hat 5 (not RHEL 5!) in 1997 the rpm/rpmbuild command knows the RPM_BUILD_ROOT definition. I guess that this is your problem: You don't use the buildroot but install directly into the root FS and run rpmbuild as user root.
Given your example it should be changed to:
%install
/bin/ln -sf libcrypto.so.0.9.8e $RPM_BUILD_ROOT/lib/libcrypto.so.0.9.8
/bin/ln -sf libssl.so.0.9.8e $RPM_BUILD_ROOT/lib/libssl.so.0.9.8
Using buildroot is described in RPM docs.
The best way to do this is by preventing the symlinks you created from being scanned by the automatic depends & requires generators:
%filter_provides_in libcrypto.so.0.9.8e
%filter_provides_in libssl.so.0.9.8e
%filter_requires_in libcrypto.so.0.9.8e
%filter_requires_in libssl.so.0.9.8e
%filter_setup
More information on depends/requires filtering here.

Resources