create var files under with "/" with rpmbuild - linux

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.

Related

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.

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.

rpmbuild is building my target directory in /usr/local not where I specified

My rpmbuild is supposed to happen in /include, /lib, and /share, I have specified this in the spec file. But when in the BUILDROOT directory, it is creating in /usr/local/include, /usr/local/lib, /usr/local/share instead. And then is throwing an error (obviously) because I am looking for the files in the previous location.
Why would this happen? Nowhere am I specifying /usr/local, then why does it take this location?
This is my .spec file:-
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: test
Name: TEST
Version: 1.0
Release: 1
License: MYORG
Group: Development/Tools
SOURCE0 : %{name}.tar.gz
%define pbs_prefix /opt/dir1/TEST
BuildRoot: %{_topdir}/%{name}
%description
%{summary}
%prep
%setup -q
%build
./configure --with-prefix=/opt/dir1/TEST --with-drms-dir=/opt/dir1
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
%make_install
%clean
rm -rf %{buildroot}
%files
/opt/dir1/TEST/include/*
/opt/dir1/TEST/lib/*
/opt/dir1/TEST/share/*
My ~/.rpmmacros file is:-
%_topdir %(echo $HOME)/rpmbuild
%_tmppath %{_topdir}/tmp
I want to build so that my TEST-1.0-1x86_64/ has /include, /lib and /share not /usr/local/...
The --prefix option sets your path. Not --with-prefix.

%prep problems when building RPMs on CentOS 7

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

How to solve No such file or directory error: Bad exit status from (%prep) while building an RPM?

I am building an rpm please let me know where i am going wrong,
My spec file is rpms.spec and the contents are:
Summary: GNU indent
Name: rpms
Version: 1
Release: 1
Source0: %{name}-%{version}.tar.gz
License: GPL
Group: Development/Tools
%description
The GNU indent program reformats C code to any of a variety of
formatting standards, or you can define your own.
%prep
%setup -q
%build
./configure
make
%install
make install
%files
%defattr(-,root,root)
/usr/local/bin/indent
%doc /usr/local/info/indent.info
%doc %attr(0444,root,root) /usr/local/man/man1/indent.1
%doc COPYING AUTHORS README NEWS
I have copied the tar file to /usr/src/redhat/SOURCES/ also
and then when i do rpmbuild -ba rpms.spec I get the following error
rpmbuild -ba rpms.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.87218
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /usr/src/redhat/BUILD
+ rm -rf rpms-1
+ /bin/gzip -dc /usr/src/redhat/SOURCES/rpms-1.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd rpms-1 /var/tmp/rpm-tmp.87218: line 35: cd: rpms-1: No such file or directory error: Bad exit status from /var/tmp/rpm-tmp.87218 (%prep)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.87218 (%prep)
There is no directory as rpms-1.I tried creating the directory in BUILd directory it didnt work.
You have set Name to rpms and version to 1
rpmbuild will therefore assume that unpacking rpms-1.tar.gz results in a directory named rpms-1 in which is should step into to do the build.
if you want to override that, change the %setup to
%setup -n yourdir
where yourdir is whatever directory your sources are packaged in, inside your tar.gz file

Resources