I'm working on a script that install Apache automatically.
Part of my pre-test is to check that the rpm are installed.
For example to install apache you need zlib and zlib-devel
So basically, I do an rpm -qa zlib
and then store the output on a variable. Then I repeat the rpm -qa
but with zlib-devel.
After that I check the versions of the stored variables.
For example: zlib-1.2.8-3.fc20.x86_64 and zlib-devel-1.2.8-3.fc20.x86_64
I break the variable to end with 1.2.8-3.fc20.x86_64, I compare the 2 variables and if its correct the script continues.
The problem is that if there is more that one rpm installed it continues by default. It only checks the first installation.
Is there any simpler way to check the rpm installations?
This is the idea of the code:
zlib_rpm=`rpm -qa zlib`
if [ -n "$zlib_rpm" ]
then
zlib_devel_rpm=`rpm -qa zlib-devel*`
if [ -n "$zlib_devel_rpm" ]
then
version_zlib_rpm=`rpm -qa zlib | cut -c 6-`
version_zlib_devel_rpm=`rpm -qa zlib-devel* | cut -c 12-`
if [ "$version_zlib_rpm" = "$version_zlib_devel_rpm" ]
then
echo "zlib rpm --> PASSED"
echo "zlib-devel rpm --> PASSED"
fi
else
echo "zlib-devel rpm --> FAILED"
echo "You can find instructions on how to install rpms on /mw_share/script/instructions/rpm_install"
exit
fi
else
echo "zlib rpm --> FAILED"
echo "You can find instructions on how to install rpms on /mw_share/script/instructions/rpm_install"
exit
fi
Thanks
The rpm
utility has rich options you can use. In your particular case I'd recommend using --qf
option. This will allow you to print the version and architecture only avoiding the need to cut
the output.
rpm -q --qf "%{version}.%{arch}\n" zlib
If you only want to query the package of specific architecture you can suffix the packagename with x86_64 to query the 64 bit package for example.
rpm -q --qf"%{version}.%{arch}\n" zlib.x86_64
The rpm
utility returns non-zero if the package doesn't exist.
Note: You don't need option -a when you are querying for specif package. This option is only for querying all packages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.