Tuesday, March 15, 2022

[SOLVED] RPM to be installed only on AWS ec2 redhat instances

Issue

I am trying to build an RPM which should only be installable only on AWS EC2 redhat instances and not on other environments.

I currently have no clue on how to limit it only to aws ec2 instance. Can someone help share thoughts on how to handle this situation.


Solution

You would have to find a file that is unique to that install and then add it to your Requires tag, e.g. /etc/redhat-release-aws or something. If that file didn't exist, it wouldn't install, but something like yum wouldn't be able to help you out either, it wouldn't, for example, say "This RPM requires AWS." It would just tell the user a file is missing.

If it's not a specific file, you could write a script and put it into the %pre section. Not having AWS, I'll make believe there's a command you can run called is_aws; you can replace that with something like "grep -iq aws /etc/os-release"; anything that would return true/false.

if is_aws; then
  true # do nothing
else
  echo "This RPM requires AWS!" 1>&2
  false
fi

I'm 90% sure that the %pre scriptlet is run in "set -e" mode where the false will cause install to fail. STDOUT is ignored in non-verbose mode, so you need to write to STDERR.



Answered By - Aaron D. Marasco
Answer Checked By - Dawn Plyler (WPSolving Volunteer)