I wrote a bash script to install multiple packages and calling the bash script in %post. But its not executing the script. I am new to this area and I am not sure what I am missing.
If i manually execute the script its working fine but not through the rpm package.
InstallRPM.spec file:
Name:           InstallRPM
Version:        1
Release:        1%{?dist}
Summary:        Install RPM Packages
License:        Script
URL:            NA
Source0:        InstallRPM-1.tar.gz
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-buildroot
Requires:       /bin/sh
%description
Install RPM files from the /tmp/ folder
%prep
%setup -q
%install
mkdir -p "$RPM_BUILD_ROOT"
cp -R * "$RPM_BUILD_ROOT"
%post
echo "Executing the script /tmp/InstallRPM.sh"
/tmp/InstallRPM.sh
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/tmp/InstallRPM.sh
Shell Script:
#!/bin/bash
echo "Installing package using YUM"
package="vim zip"
echo "Install $package ..."
if [ "`cat /etc/centos-release | awk '{print $1}'`" == "CentOS" ]
then
{
        for i in $package
        do
        {
                #if [ "`/bin/rpm -qa $i | cut -d. -f1`" == "" ]
                if [ "`/bin/rpm -qa $i`" == "" ]
                then
                {
                        echo "Clean Install"
                        /usr/bin/sudo /bin/yum install -y $i
                }
                else
                {
                        echo "Upgrade"
                        /usr/bin/sudo /bin/yum update -y $i
                }
                fi
                echo "****************"
        }
        done
}
fi
I ran the rpmbuild -ba InstallRPM.spec and it created a rpm file which I executed but nothing happened. Its getting hung in the below mentioned spot.
Downloading packages:
vim-enhanced-7.4.629-6.el7.x86_64.rpm                                                                                               | 1.1 MB  00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
^C
 
    