Reputation: 21
I’d like to install a series of packages using script shell.
Question is : what to do when package is not available? Script idea is: if the package is installed go to the next one if the package is available to be installed, install it, if the package is not available exit the script, or to alert me about that package. Press a key to continue or so. Thanks!
More Info: While ago Monk posted this sentence
yum list installed vnc-server >/dev/null && echo "vnc-server installed." || yum -y install vnc-server
** it will return vnc-server installed or it will install it.**
I tried to install mariadb but – mariadb is not available in Centos 6.6 I should install other repository or something I don’t know yet, the point is script’s behavior.
pkg=mariadb || yum list installed $pkg >/dev/null && echo "--> $pkg installed." || yum install $pkg
this line as it is will return - - > mariadb installed.
( this return is wrong because MariaDB is not available)
In the command line typing
yum install mariadb
it will return
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
base: mirrors.tripadvisor.com
extras: mirrors.seas.harvard.edu
updates: mirrors.lga7.us.voxel.net
No package mariadb available.
Error: Nothing to do
Thanks!
Upvotes: 0
Views: 4314
Reputation: 84
Maybe you want to check yum's exit code (untested Bash code):
yum list $pkg > /dev/null if [ $? -eq 0 ] then echo "Installing $pkg" yum -y install $pkg else echo "$pkg not found or unknown error." fi
Upvotes: 1