Cannot build Mercurial from sources in CentOS - linux

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.

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.

Extract tar the tar.bz2 file error

I tried to extract the tar.bz2 file in Fedora 17 OS. I used the command:
# tar -xvjf myfile.tar.bz2
I received this error message:
tar (child):bzip2: Cannot exec :Nosuch of file or directory
tar (child): Error is not recoverable: exitng now
tar: Child returned status 2
tar:Error is not recoverable: exitng now
How can I resolve this?
Ensure that you have the bzip2 and bzip2-libs RPMs installed.
It looks like the tar command defers to the bzip2 command which the bzip2 RPM provides (/usr/bin/bzip2). In your case, tar specifically tries to call bzip2 -d to decompress the bzipped archive.
Also, a couple of tips:
The -v option is not necessary. It just gives verbose output, which means that it lists the files that were extracted from the archive. Most of the time this prints useless data to your terminal.
As #Skynet said, it is helpful to run the file command on your bzip2 archive to ensure that it is actually in bzip2 format.
As #Odin said, it appears that you don't need to specify the -j option when extracting the archive, as the tar command seems to be smart enough to figure this out.
I solved it using:
aptitude install bzip2
I found the same error as you in CentOS 7. It looks like this:
tar -jxvf target_gile.tar.bz2
<br>tar (child): bzip2: Cannot exec: No such file or directory
<br>tar (child): Error is not recoverable: exiting now
<br>tar: Child returned status 2
<br>tar: Error is not recoverable: exiting now
Then I installed bzip2 package : yum install bzip2
After that, I extracted again using this command: tar -jxvf target_gile.tar.bz2
You may need to install the bzip2 on your system.
yum -y install bzip2
I got the same problem . I have two server.
A: CentOS 7.6 Min install
B: Fedora 29 Workstation
On B:create a tarball with:
tar -jcvf XXX.tar.bz2 /Path_to_my_dir
Then scp this tarball to A server to decrompress it, but when I want to decompression it I got the same error.Finally it turns out that, tar could work with bzip2 but you have to install it first .
This worked for my file:
binutils-2.15.tar.bz2 (Found at http://ftp.gnu.org/gnu/binutils/)
bunzip2 your-tar-file.tar.bz2
Your file now looks like this:
your-tar-file.tar
tar xvf your-tar-file.tar
File will finish extracting
First you need to install lbzip2 package:
yum install lbzip2
then untar the file
tar file.tar.bz2
Regards
You can extract either tar.gz or tar.bz2 with this command:
tar -xvf ~/sometar.tar.bz2
this error come also if you use some wrong alias in your .bashrc/.zshrc as:
alias tar='tar -cf'
when you execute in terminal
$ tar -xf file.tar
it's been
$ tar -cf -xf file.tar
tar (child):bzip2: Cannot exec :Nosuch of file or directory
tar (child): Error is not recoverable: exitng now
tar: Child returned status 2
tar:Error is not recoverable: exitng now
so, you should not use an alias for tar or do
$ unalias tar
$ tar -xf file.tar
For bz2 you need to execute like this,
tar -jxvf
Alternatively, you can also execute like this
bunzip2 myfile.tar.bz2
For more information you should check it,
tar --help
If in doubt, run file on the archive to make sure it actually is compressed in bz2 format.

rpmbuild spec file %install section error

I have a spec file which is similar to:
BuildRoot: /tmp/build_%{name}-%{version}-%{release}
%prep
...
...
%install
# Directories
install -m 755 -d %{buildroot}/usr/app/mypackage/config
install -m 755 -d %{buildroot}/usr/app/mypackage/src
....
# Bash script
install -m 755 script/script1.sh %{buildroot}/usr/app/mypackage/config/script1.sh
install -m 755 script/script2.sh %{buildroot}/usr/app/mypackage/config/script2.sh
install -m 755 script/myapp-log %{buildroot}/etc/logrotate.d/myapp-log
When I run the rpmbuild I get the error:
install: cannot create regular file `/tmp/build_my_app-1.0-2/etc/logrotate.d/myapp-log'
I can get around this by manually creating the /etc/ and then /etc/logrotate.d directories in the /tmp/build_my_app-1.0-2/ directory.
When I re-reun the rpmbuild it will work.
I guess this is because I am not creating this directory in my install section but as its not directly related to my application I don't want to put that in.
My guess is that there is some clever tag I can use to fix this so that the build will work without any manual intervention.
My Question:
Could someone please suggest a way for me to achieve this (assuming its possible) or whether I need to write a script around the rpmbuild to set this up first.
You are missing the step to create the installation directories in your %install section. Remember that since you can build in "different" roots, you cannot expect certain directories (like ${buildroot}/etc) to be present.
Try adding
mkdir -p ${buildroot}/etc/logrotate.d
just before the install command that copies the file into ${buildroot}/etc/logrotate.d.

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