How would I check to see if a package has not been installed, in the .ebextensions folder of an Elastic Beanstalk setup? What I want to do is similar to this command, but I only want to run the command if the package does not exist, rather than if it exists.
commands:
install_package:
test: rpm -qa | grep -c example_package
command: yum install -y example_package.rpm
So in pseudocode, this is what I am after:
commands:
install_package:
test: not(rpm -qa | grep -c example_package)
command: yum install -y example_package.rpm
Update: I have gotten this to work without the test parameter, using a double pipe in the command itself instead, but it isn't as neat as I'd like; I'd rather use the test parameter instead to make it more explicit:
commands:
install_package:
command: rpm -qa | grep -c example_package || { yum install -y example_package.rpm; }
You can run shell script in the test option:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-commands-options
If you want to count the grep result (as you write in the question), you can condition with
-eq(equal),-gt(greater than) or-ge(greater or equal).Example for 3 or more lines:
If you want the result
found/not foundfrom grep, you should use the quiet option-q, --quiet, --silentto only retrieve theexit codefrom grep:At the end, if you want to run the command ONLY if the package is NOT installed, you should test if grep returns 1: