bashshellrpmrpmbuildrpm-spec

rpm build error : cannot create regular file | no such file or directory


Linux Distribution: Ubuntu 20
(So using the rpm package not rpmdevtools-package to build the rpm)

Folder structure of rpmbuild:


rpmbuild
├── BUILD
│   └── alascript-1
│       ├── config.cfg
│       ├── logfile.txt
│       └── script.sh
├── BUILDROOT
│   └── alascript-1-0.x86_64
│       └── etc
│           └── alascript\015
├── RPMS
├── SOURCES
│   ├── alascript-1
│   │   ├── config.txt
│   │   ├── logfile.txt
│   │   └── script.sh
│   └── alascript-1.0.tar.gz
├── SPECS
│   └── alascript.spec
└── SRPMS

The alascript-1.0.tar.gz is the tar file of the above folder i.e alascript-1.

Here's my spec file:

Name:           alascript
Version:        1
Release:        0
Summary:        A Bash Script for secure copying from eNodeB to server.

Group:          theogs
BuildArch:      noarch
License:        GPL
URL:            https://github.com/
Source0:        alascript-1.0.tar.gz


%description
The bash script will basically secure copy files
from the eNodeB to server and then those files will be
processed using ML Ananlyser.

%prep
%setup -q
%build
%install
install -m 0755 -d $RPM_BUILD_ROOT/etc/alascript
install -m 0600 config.cfg $RPM_BUILD_ROOT/etc/alascript/config.cfg
install -m 0644 logfile.txt $RPM_BUILD_ROOT/etc/alascript/logfile.txt
install -m 0755 script.sh $RPM_BUILD_ROOT/etc/alascript/script.sh

%files
/etc/alascript
/etc/alascript/config.cfg
/etc/alascript/script.sh
/etc/alascript/logfile.txt

%changelog
* Mon Jun 20 2022 theogs 1.0.0
  - Initial rpm release

Now when I try to run the command : rpmbuild -ba SPECS/alascript.spec I get the following output:

Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.wSNbxX
+ umask 022
+ cd /home/test/rpmbuild/BUILD
+ cd /home/test/rpmbuild/BUILD
+ rm -rf alascript-1
+ /bin/gzip -dc /home/test/rpmbuild/SOURCES/alascript-1.0.tar.gz
+ /bin/tar -xof -
+ STATUS=0
+ [ 0 -ne 0 ]
+ cd alascript-1
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.CCUFwV
+ umask 022
+ cd /home/test/rpmbuild/BUILD
+ cd alascript-1
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.BT4UXX
+ umask 022
+ cd /home/test/rpmbuild/BUILD
+ cd alascript-1
+ install -m 0755 -d /home/test/rpmbuild/BUILDROOT/alascript-1-0.x86_64/etc/alascript
+ install -m 0600 config.cfg /home/test/rpmbuild/BUILDROOT/alascript-1-0.x86_64/etc/alascript/config.cfg
install: cannot create regular file '/home/test/rpmbuild/BUILDROOT/alascript-1-0.x86_64/etc/alascript/config.cfg'$'\r': No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.BT4UXX (%install)

I am fairly new to bash and shell scripting and have never made a rpm package. I can't figure out what's the issue.

Also the reference blog I am following: How to Create a RPM Pakcage


Solution

  • You look to have some special characters within the SPEC File

    Visible when you have shown the directory tree

    └── alascript\015

    015 (Octal) is CR (Carriage return)

    Did you copy and paste a part of the code from somewhere?

    Easiest fix is to run the spec file through a formatting tool like dos2unix