LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what is the error in my rpm spec file (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-error-in-my-rpm-spec-file-648210/)

ukbhan 06-10-2008 01:47 AM

what is the error in my rpm spec file
 
test.c is a small c file written to print hello world.

The below one is the test.spec file written for packaging the test.c file.
Summary:This prints hello world
Name:test
Version:1
Release:1
License:GPL
Group:Applications/System
Source:test.c
BuildRoot:/home/uday_koganti/testing
%description
This package prints hello world when executed
%prep

%build
gcc -o /home/uday_koganti/testing/test /home/uday_koganti/testing/test.c
%install
./test

After writing this spec file i had run the command rpmbuild -bs test.spec to create the source rpm package.
It ran successfully.After that i had run the command rpmbuild -ba test.spec to create binary rpm package.
But it gives an error

RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.65419 (%install)
I feel that there should be some thing wrong in the install section of my test.spec file.

Could any one please find the solution for this problem.

unSpawn 06-10-2008 04:46 AM

The "/var/tmp/rpm-tmp.65419" serves as kind of a logfile you can use for debugging, so what are the contents?

ukbhan 06-11-2008 01:56 AM

The contents of var/tmp/rpm-tmp.65419 are


#!/bin/sh

RPM_SOURCE_DIR="/usr/src/redhat/SOURCES"
RPM_BUILD_DIR="/usr/src/redhat/BUILD"
RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
RPM_ARCH="i386"
RPM_OS="linux"
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
RPM_DOC_DIR="/usr/share/doc"
export RPM_DOC_DIR
RPM_PACKAGE_NAME="test"
RPM_PACKAGE_VERSION="1"
RPM_PACKAGE_RELEASE="1"
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
RPM_BUILD_ROOT="/home/uday_koganti/testing"
export RPM_BUILD_ROOT


set -x
umask 022
cd /usr/src/redhat/BUILD
install ./test

/usr/lib/rpm/brp-compress
/usr/lib/rpm/brp-strip
/usr/lib/rpm/brp-strip-static-archive
/usr/lib/rpm/brp-strip-comment-note

unSpawn 06-11-2008 06:11 AM

- The initial error messages you posted where not complete. Sure the line you posted contains the error, but in troubleshooting it is often "better" (easier, more efficient) to provide any lines before and after the error line for troubleshooting purposes.

- Building as root?
Quote:

Originally Posted by ukbhan (Post 3181247)
RPM_BUILD_DIR="/usr/src/redhat/BUILD"
(..)cd /usr/src/redhat/BUILD

The /usr/src/redhat tree is only used by the root account user to build RPMs. You should not use the root account for testing and building RPMs but an unprivileged user account.

- Conventions
Quote:

Originally Posted by ukbhan (Post 3181247)
install ./test

In the %install section of the .spec file a Makefile is expected when handling a "default" packaging process. If there is no Makefile then you can use 'cp', but it is better (easier, more efficient) to use 'install'.

- Conventions
A RPM should not execute processes trivially during install. Running 'test', when not explicitly advertised, is unexpcted behaviour that could compromise the trust we put in RPM. Besides that the name 'test' could lead to unexpected results since on default installation there already is a 'test' binary (see '[', ']', 'test').

- Spec file. Unless you cut off your file contents, your .spec file is not complete (and please use BB code next time).
Your .spec file could look like this, note I used RPM-style %{formatting}:
Code:

Name: test
Version: 1
Release: 1
Summary: %{name} prints hello world
Group: Utilities/System # See /usr/share/docs/rpm-*/GROUPS
License: GPL
Source: $RPM_SOURCE_DIR/%{name}.c
BuildRoot: %{_tmppath}/%{name}-%{version}
Provides: %{name}

%description
This package contains a "hello world" example binary.

# or %setup if a tarball
%prep # This preps dir $RPM_BUILD_DIR/%{name}-%{version}.%{release}/.
# We're in the BuildRoot now. Make certain:
cd $RPM_BUILD_DIR/%{name}-%{version}.%{release}/
# Copy files in that aren't packaged:
cp $RPM_SOURCE_DIR/%{name}.c .

%build
gcc -o %{name} %{name}.c

%install
# Create dirs leading up to if necessary:
[ -d /usr/local/bin ] || mkdir -p /usr/local/bin
install -m 0755 ./test $RPM_BUILD_ROOT/usr/local/bin

%clean
[ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}" ] && rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%attr(755,root,root) /usr/local/bin/%{name}

%changelog
* Wed June 10 2008 %{packager}
- Initialise .spec file for %{name}-%{ver}.

Before you use your unprivileged user account to build RPMs perform the next three steps to set up the environment:

0. Create a file "/home/uday_koganti/.rpmmacros" with minimally the following contents:
Code:

%_topdir        /home/uday_koganti/redhat
%_tmppath      %{_topdir}/tmp
%fname          %{name}-%{version}.%{release}
%_builddir      %{_topdir}/BUILD
%_rpmdir        %{_topdir}/RPMS
%_sourcedir    %{_topdir}/SOURCES
%_specdir      %{_topdir}/SPECS
%_srcrpmdir    %{_topdir}/SRPMS
%distribution    none
%vendor        none

1. Then create the necessary directories with: 'mkdir -p /home/uday_koganti/redhat/{BUILD,RPMS,SOURCES,SPECS,SRPMS}'

2. Place your "test.c" in /home/uday_koganti/redhat/SOURCES and your "test.spec" in /home/uday_koganti/redhat/SPECS.

ukbhan 06-12-2008 06:38 AM

I had followed all the instructions give above by you .But even then i am getting the error has follows
[uday_koganti@silunx-fc4 SPECS]$ rpmbuild -ba test.spec


Executing(%prep): /bin/sh -e /home/uday_koganti/redhat/tmp/rpm-tmp.77791
+ umask 022
+ cd /home/uday_koganti/redhat/BUILD
+ cd /home/uday_koganti/redhat/BUILD/test-1.1/
/home/uday_koganti/redhat/tmp/rpm-tmp.77791: line 23: cd: /home/uday_koganti/redhat/BUILD/test-1.1/: No such file or directory
error: Bad exit status from /home/uday_koganti/redhat/tmp/rpm-tmp.77791 (%prep)


RPM build errors:
Bad exit status from /home/uday_koganti/redhat/tmp/rpm-tmp.77791 (%prep)

unSpawn 06-12-2008 08:19 AM

Quote:

Originally Posted by ukbhan (Post 3182457)
/home/uday_koganti/redhat/tmp/rpm-tmp.77791: line 23: cd: /home/uday_koganti/redhat/BUILD/test-1.1/: No such file or directory

That's because the directory isn't made according to specs. Try this one.

Code:

Name: test
Version: 1
Release: 1
Summary: %{name} prints hello world
Group: Utilities/System
License: GPL
Source: $RPM_SOURCE_DIR/%{name}.c
BuildRoot: %{_tmppath}/%{name}-%{version}
Provides: %{name}

%description
This package contains a "hello world" example binary.

%prep
mkdir %{name}-%{version}.%{release}
cd %{name}-%{version}.%{release}
cp $RPM_SOURCE_DIR/%{name}.c .

%build
cd %{name}-%{version}.%{release}
gcc -o %{name} %{name}.c

%install
cd %{name}-%{version}.%{release}
[ -d $RPM_BUILD_ROOT/usr/local/bin ] || mkdir -p $RPM_BUILD_ROOT/usr/local/bin
install -m 0755 ./test $RPM_BUILD_ROOT/usr/local/bin

%clean
[ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}.%{release}" ] && rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%attr(755,root,root) /usr/local/bin/%{name}

%changelog
* FILL IN THE DATE SPEC %{packager}
- Initialise .spec file for %{name}-%{ver}.

* Searching the Internet for the document "Maximum RPM" should be beneficial as it will provide the information you need for learning how to build RPMs.

ukbhan 06-12-2008 11:56 PM

I have tried the above one also.But still i am getting the below errors.

[uday_koganti@silunx-fc4 SPECS]$ rpmbuild -ba test.spec

Executing(%prep): /bin/sh -e /home/uday_koganti/redhat/tmp/rpm-tmp.48211
+ umask 022
+ cd /home/uday_koganti/redhat/BUILD
+ mkdir test-1.1
+ cd test-1.1
+ cp /home/uday_koganti/redhat/SOURCES/test.c .
+ exit 0
Executing(%build): /bin/sh -e /home/uday_koganti/redhat/tmp/rpm-tmp.48211
+ umask 022
+ cd /home/uday_koganti/redhat/BUILD
+ cd test-1.1
+ gcc -o test test.c
+ exit 0
Executing(%install): /bin/sh -e /home/uday_koganti/redhat/tmp/rpm-tmp.11521
+ umask 022
+ cd /home/uday_koganti/redhat/BUILD
+ cd test-1.1
+ '[' -d /home/uday_koganti/redhat/tmp/test-1/usr/local/bin ']'
+ mkdir -p
mkdir: too few arguments
Try `mkdir --help' for more information.
error: Bad exit status from /home/uday_koganti/redhat/tmp/rpm-tmp.11521 (%install)


RPM build errors:
Bad exit status from /home/uday_koganti/redhat/tmp/rpm-tmp.11521 (%install)

unSpawn 06-13-2008 10:26 AM

Quote:

Originally Posted by ukbhan (Post 3183318)
+ '[' -d /home/uday_koganti/redhat/tmp/test-1/usr/local/bin ']'
+ mkdir -p
mkdir: too few arguments

"too few arguments" means the 'mkdir' command doesn't have any or enough arguments to work on. In the .spec file I defined the line as "[ -d $RPM_BUILD_ROOT/usr/local/bin ] || mkdir -p $RPM_BUILD_ROOT/usr/local/bin". Did you by any chance not copy it completely?

ukbhan 06-14-2008 12:13 AM

It's working now.I got the desired output.I am highly thankful to you for helping me through this forum.

unSpawn 06-14-2008 05:11 AM

You're welcome.
BTW, could you tell me if the problem was with copying the line right or something else?
And if something else post the fix?
Thanks in advance.

ukbhan 06-15-2008 11:35 PM

yes,i had not copied it completely.

ukbhan 06-16-2008 01:49 AM

I had created the source rpm and the binary rpm successfully.
But after that i tried to install the binary rpm by giving the command

rpm -ivh test-1-1.i386.rpm

it,s giving an error saying

error: can't create transaction lock on /var/lib/rpm/__db.000


how to get rid of this error

ukbhan 06-16-2008 02:05 AM

I had tried to install the source rpm package by giving the command

rpm -i test-1-1.src.rpm

It ran successfully.

but when i tried to uninstall the source rpm package by giving the command

rpm -e test

or

rpm -e test-1-1.src.rpm
it's giving an error saying that

error: package program-1-1.src.rpm is not installed


how to get rid of the above errors while installing and uninstalling the rpm package

unSpawn 06-16-2008 03:10 AM

Quote:

Originally Posted by ukbhan (Post 3185882)
error: can't create transaction lock on /var/lib/rpm/__db.000

See if there are other (background?) processes using the RPMDB, like Yumsd, and (temporarily) stop them before you try again.


Quote:

Originally Posted by ukbhan (Post 3185891)
when i tried to uninstall the source rpm package by giving the command rpm -e test or rpm -e test-1-1.src.rpm it's giving an error saying that error: package program-1-1.src.rpm is not installed

The command 'rpm -e test' is to uninstall an installed package named "test". Uninstalling using the format 'rpm -e test-1-1.src.rpm' is an error because that references a file, a package archive and not a package known to the RPMDB. The only times you use extensions like ".rpm" or ".src.rpm" is to query them (-p) or install them. Source packages are not "installed" (not known in the RPMDB) but unpacked to the RPM tree (see ~/.rpmrc or if root, the default /usr/src/redhat). Since .src.rpms are not installed, to uninstall them you must remove the contents manually.

ukbhan 06-16-2008 04:25 AM

when i install rpm binary package ,
by giving the command

rpm -ivh test-1-1.i386.rpm

i got the error initially.
error: can't create transaction lock on /var/lib/rpm/__db.000

Now it is solved. But even then i am getting a new error as follows

error: failed to stat ./new: No such file or directory



how to get rid of this error


All times are GMT -5. The time now is 05:37 PM.