linuxbashrpmrpm-specgitlab-ci.yml

Inconsistent results when installing .rpm package


I have a .sh script that I packaged as .rpm to distribute. I'm using GitLab CI CD pipeline using gitlab-ci.yml. I'm able to pacakge the script in .rpm with no problems using the .spec.

The issue is when I install the .rpm (after uploading and downloading) in various systems for testing and make sure it does what I expect it to do.

So in the .spec file I specify that I want to install it in /usr/bin/myscript.sh with the following in .spec file:

%build

%install
rm -rf %{buildroot}

mkdir -p $RPM_BUILD_ROOT/%{_prefix}/bin
install -m 755 -p $RPM_BUILD_DIR/myscript.sh $RPM_BUILD_ROOT/%{_prefix}/bin/

So to test the newly created .rpm I try to install in 2 different containers First one called centos
Output

[root@1235 /]# curl -O http://url/srpms/myscript-1.0-1.el7.src.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5773  100  5773    0     0   626k      0 --:--:-- --:--:-- --:--:--  626k
[root@1235 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  myscript-1.0-1.el7.src.rpm
[root@1235 /]# rpm -iv myscript-1.0-1.el7.src.rpm 
myscript-1.0-1.el7.noarch
[root@1235 /]# rpm -ql xsoar*
myscript.sh
myscript.spec
[root@1235 /]# find . -type f -name "myscript.sh" 2>/dev/null
./root/rpmbuild/SOURCES/myscript.sh
[root@1235 /]#

As you can see the script ends up in a path that was created by the installation itself ./root/rpmbuild/SOURCES/ instead of the expected /usr/bin/


For the next container I used the same image/container used by gitlab-ci.yml to package the .rpm
Output

[root@5704de76a68c /]# rpm -iv myscript-1.0-1.el7.src.rpm
myscript-1.0-1.el7.noarch
[root@5704de76a68c /]# rpm -ql xsoar*
package myscript-1.0-1.el7.src.rpm is not installed
[root@5704de76a68c /]# find . -type f -name "myscript.sh" 2>/dev/null
./root/rpmbuild/SOURCES/myscript.sh
[root@5704de76a68c /]#

Similar result but it says .rpm is not installed


Then for the heck of I tried installing the .rpm in the same instance/container right after creation using gitlab-ci.yml (before it gets uploaded to any repo for distribution) and I do get the expected result
Output

$ rpm -ivh $HOME/rpmbuild/RPMS/noarch/*.rpm
Preparing...                          ########################################
Updating / installing...
myscript-1.0-1.el7               ########################################
$ rpm -ql myscript
/usr/bin/myscript.sh

Part of the .spec

%prep
cp -fp %{SOURCE0} ./

%build

%install
rm -rf %{buildroot}

mkdir -p $RPM_BUILD_ROOT/%{_prefix}/bin
install -m 755 -p $RPM_BUILD_DIR/myscript.sh $RPM_BUILD_ROOT/%{_prefix}/bin/

%clean
rm -rf %{buildroot}


%files
%attr(755,root,root) %{_prefix}/bin/myscript.sh

Solution

  • Found the issue. Of course it had to be stupid. For my testing i was installing myscript.src.rpm instead of myscript.noarch.rpm