Search code examples
bashcentosrpmrpmbuildrpm-spec

How can I fix "RPM Build Error: Bad exit status"


I'm trying to create and build a go rpm package in a CentOS8 container. Upon running the rpmbuild -ba onboarding.spec command, I'm getting this error:

Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.nAad2g
+ umask 022
+ cd /home/tiagoribeiro/rpmbuild/BUILD
+ cd /home/tiagoribeiro/rpmbuild/BUILD
+ rm -rf onboarding-1.0
+ /usr/bin/gzip -dc /home/tiagoribeiro/rpmbuild/SOURCES/onboarding-1.0.tar.gz
+ /usr/bin/tar -xof -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd onboarding-1.0
/var/tmp/rpm-tmp.nAad2g: line 41: cd: onboarding-1.0: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.nAad2g (%prep)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.nAad2g (%prep)

I'm been +- following this documentation online and it's mostly replicated. Don't understand why I'm getting this error. Here's my spec file:

Name:           onboarding
Version:        1.0
Release:        1%{?dist}
Summary:        golang api
License:        GPLv3
Source0:        %{name}-%{version}.tar.gz
BuildRequires:  systemd-rpm-macros
Provides:       %{name} = %{version}

%description
small go app

%global debug_package %{nil}
%prep
%autosetup

%build
go build -v -o %{name}

%install
install -Dpm 0755 %{name} %{buildroot}%{_bindir}/%{name}
install -Dpm 644 %{name}.service %{buildroot}%{_unitdir}/%{name}.service

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%files
%dir %{_sysconfdir}/%{name}
%{_bindir}/%{name}
%{_unitdir}/%{name}.service

%changelog

Here's my rpmbuild file tree:

/home/tiagoribeiro/rpmbuild/
├── BUILD
│   ├── main.go
│   └── onboarding.service
├── BUILDROOT
├── RPMS
├── SOURCES
│   ├── onboarding-1.0.tar.gz
├── SPECS
│   ├── onboarding.spec
└── SRPMS

What do I need to change in order to be able to build this package?


Solution

  • Unpacking the distribution file onboarding-1.0.tar.gz is not creating a directory with the default name (%{name}-%{version}, which in this case is onboarding-1.0). It looks like the tarball doesn't contain a directory at all, which is poor form. You have two main alternatives:

    1. repack the source so that it contains the wanted directory:

      cd ~
      mkdir onboarding-1.0
      tar -C onboarding-1.0 -xf ~/rpmbuild/SOURCES/onboarding-1.0.tar.gz
      tar czf rpmbuild/SOURCES/onboarding-1.0.tar.gz onboarding-1.0
      

      OR

    2. instruct rpmbuild to create the wanted directory itself, by adding a -c option to the %autosetup macro invocation:

      %prep
      %autosetup -c
      

    I would choose option (1) if you are building the tarball yourself in the first place, but option (2) if you're using a tarball provided by someone else.