Error while creating rpm package using rpmbuild from spec file - linux

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.

Related

"/var/tmp/rpm-tmp.6K3TRj: line 33: $'\r': command not found" Can't get past this error when building my RPM

I'm trying to build my first RPM, and I keep getting this error:
/var/tmp/rpm-tmp.6K3TRj: line 33: $'\r': command not found
error: Bad exit status from /var/tmp/rpm-tmp.6K3TRj (%prep)
I have seen a few people ask about this error, but I cant find a solution that I haven't already tried.
My spec file looks like this:
Name: test
Version: 0.0.2
Release: 1%{?dist}
Summary: test
BuildArch: noarch
License: GPL
Source0: %{name}-%{version}.tar.gz
Requires: bash
%description
test
%prep
%setup -q
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
cp %{name}.sh $RPM_BUILD_ROOT/%{_bindir}
%clean
rm -rf $RPM_BUILD_ROOT
%files
%{_bindir}/%{name}.sh
I get this error after running the command
rpmbuild -bb ~/rpmbuild/SPECS/test.spec
I'm really new to this, so if anyone could help figure out what I need to change to get this to run, I'd be so grateful.
the complete output I get is:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.6K3TRj
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf api-controller-0.0.2
+ /usr/bin/tar -xf /root/rpmbuild/SOURCES/test-0.0.2.tar.gz
+ cd test-0.0.2
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ $'\r'
/var/tmp/rpm-tmp.6K3TRj: line 33: $'\r': command not found
error: Bad exit status from /var/tmp/rpm-tmp.6K3TRj (%prep)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.6K3TRj (%prep)
Any time you see random \r complaints in Linux/Unix, it means you have a Windows-formatted file. Run dos2unix on your specfile.
See Wikipedia.

rpmbuild -rp option is not supported?

I've got a shell script with some rpmbuild workflow from a previous project and there is one command which is failing with an error unsupported option.
The command is this:
rpmbuild --nodeps --define '_builddir /tmp/build' --define '_sourcedir /tmp/source' -rp package_source.src.rpm
As per the documentation this -rp option is supported but I'm unable to run the rpmbuild command with this option.
Here's the man-pages link: https://man7.org/linux/man-pages/man8/rpmbuild.8.html#SYNOPSIS
The error message I'm getting is this:
rpmbuild: arguments to --root (-r) must begin with a /
Update1: my rpm version is 4.11.3 on CentOS7 and the man-page mentioned above is the latest version.
With the current version I've rpmbuild --help output is not listing this -rp or any other -r options.
So how do I get the same result using the rpm version which doesn't have this option?
TIA
The -rp option has to be on the first position.

%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

Cannot build Mercurial from sources in CentOS

I'm trying to build Mercurial on CentOS 6, so here is what I've done so far:
I got mercurial's latest sources, file is named mercurial-2.4.1.tar.gz
I try running rpmbuild on it and I get the following:
# rpmbuild -tb mercurial-2.4.1.tar.gz
error: File /home/someuser/rpms/mercurial/mercurial-snapshot.tar.gz: No such file or directory
So I try creating the file that it wants by copying from the other guy:
# cp mercurial-2.4.1.tar.gz mercurial-snapshot.tar.gz
I try again, appears to pass the previous error:
# rpmbuild -tb mercurial-2.4.1.tar.gz
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.vV9ZXc
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf mercurial-snapshot
+ /usr/bin/gzip -dc /home/someuser/rpms/mercurial/mercurial-snapshot.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd mercurial-snapshot
/var/tmp/rpm-tmp.vV9ZXc: line 34: cd: mercurial-snapshot: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.vV9ZXc (%prep)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.vV9ZXc (%prep)
I'm not sure what is happening, my guess is that rpmbuild is not being able to create files... any ideas?
The easiest way I have found to build an RPM for CentOS that isn't already available is to find a source RPM from Fedora and do rpmbuild --rebuild on it. CentOS documents it here but seems to be down right now.
Here is a src RPM you can give a try to start with.
You don't have a /var/tmp/ directory or can't write to it. Try creating it: mkdir /var/tmp - you may have to use "sudo" for this to work, depending on the setup of your system.
I think that creating tarball by cp command is not good.
You should rename the mercurial-[version]/ directory generated after extracting the official tarball to mercuial-snapshot/ and then create zipped tar archive of the directory named mercurial-snapshot.tar.gz.
$ tar zxvf mercurial-2.4.1.tar.gz
$ mv mercurial-2.4.1 mercurial-snapshot
$ tar zcvf mercurial-snapshot.tar.gz mercurial-snapshot
The issue is that the bundled spec file has a version default of "snapshot", so it's going to look for a tar file named "mercurial-snapshot.tar.gz", and also expects the extracted directory to be "mercurial-snapshot" (so you can't just rename the tar file).
The best way (or at least, a way) to handle this is to extract the spec file, update it with the correct version and release number, then build the rpm from that.
Here's the process:
tar fxz mercurial-X.Y.tar.gz --strip-components=2 mercurial-X.Y/contrib/mercurial.spec
Place the spec file in rpmbuild/SPECS and edit it. Replace the "Version: snapshot" line with "Version: X.Y", and replace the "Release: 0" line with "Release: 1.xyz" where xyz is a custom tag so you know that you built the package yourself.
Then run rpmbuild:
rpmbuild -bb --target=i686 SPECS/mercurial.spec
Use --target=x86_64 if you're on and building for a 64-bit system.
You should then have a correctly built and named rpm file in the RPMS/$target directory.

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