I was creating a RPM based package for doing installation of the application that we are developing. While I was writing a .spec file, a requirement came my way. Check the RHEL version, and install the package only if RHEL version is 7.5 or greater.
You may be wondering, "What's a .spec file?" A .spec file is the "recipe" that is used by rpmbuild command for creating packages. It is a text file, written in a specific syntax. The .spec file tells the rpmbuild command what to do. How to build our application, actions to be performed at the time of installation and un-installation. To know about .spec files and RPM packaging, this article was suggested by one of my colleagues.
After studying .spec files for some time, I figured out that the %pre scriptlet is what I needed. Scriptlet is a section in a .spec file, for a specific purpose. The %pre scriptlet is executed just before the package is installed on the target system.
Here is the %pre scriptlet I wrote, that did the required job.
%pre
# Before copying files, check that system is running RHEL, and version of RHEL is greater than 7.5
rhel_version=`cat /etc/redhat-release | cut -d ' ' -f 7`
echo "RHEL version is $rhel_version"
rhel_min_required="7.5"
echo "Minumum required RHEL version is $rhel_min_required"
check=`echo "$rhel_version>=$rhel_min_required" | bc -l`
if [ $check -ne 1 ]
then
echo "RHEL version $rhel_version is not supported for this application"
exit 1
else
echo "RHEL version $rhel_version is OK for this application"
fi
To know more about the rpmbuild command, referring to its manual page is a good start.
You may be wondering, "What's a .spec file?" A .spec file is the "recipe" that is used by rpmbuild command for creating packages. It is a text file, written in a specific syntax. The .spec file tells the rpmbuild command what to do. How to build our application, actions to be performed at the time of installation and un-installation. To know about .spec files and RPM packaging, this article was suggested by one of my colleagues.
After studying .spec files for some time, I figured out that the %pre scriptlet is what I needed. Scriptlet is a section in a .spec file, for a specific purpose. The %pre scriptlet is executed just before the package is installed on the target system.
Here is the %pre scriptlet I wrote, that did the required job.
%pre
# Before copying files, check that system is running RHEL, and version of RHEL is greater than 7.5
rhel_version=`cat /etc/redhat-release | cut -d ' ' -f 7`
echo "RHEL version is $rhel_version"
rhel_min_required="7.5"
echo "Minumum required RHEL version is $rhel_min_required"
check=`echo "$rhel_version>=$rhel_min_required" | bc -l`
if [ $check -ne 1 ]
then
echo "RHEL version $rhel_version is not supported for this application"
exit 1
else
echo "RHEL version $rhel_version is OK for this application"
fi
To know more about the rpmbuild command, referring to its manual page is a good start.
No comments:
Post a Comment