Issue
I am deploying my nodejs app via EB onto a Linux EC2 and in the .ebextensions I need to install a font package and I must use yum:
container_commands:
01_getfont:
command: sudo yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/webcore-fonts-3.0-1.noarch.rpm
Unfortunately, while that works for the 1st time, it does not work for the 2nd time if I re-deploy again it will complain the package is there already.
So what I do is to use this:
command: sudo yum -y reinstall http://li.nux.ro/download/nux/dextop/el7/x86_64/webcore-fonts-3.0-1.noarch.rpm
Unfortunately, while that works for the 2nd times and so on, it does not work for the 1st time if the package is not there, giving the error:
Error: Problem in reinstall: no package matched to remove.
This is driving me nuts.
Is there a way around this? Not really good at Linux bash script, can I like if 1st time use this command else that command?
I can create a bash script:
#!/bin/bash
sudo yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/webcore-fonts-3.0-1.noarch.rpm
and so on...
Solution
Since you mentioned running a shell
script is possible then it should be fairly easy to handle:
webcore_install.sh
#!/bin/bash
function isinstalled {
status=$?
if [[ $status -eq 0 ]]; then
# reinstall if already present
sudo yum -y reinstall http://li.nux.ro/download/nux/dextop/el7/x86_64/webcore-fonts-3.0-1.noarch.rpm
else
# install if not present
sudo yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/webcore-fonts-3.0-1.noarch.rpm
fi
}
yum -C list installed "$@"
isinstalled
Then your command could look something like this:
sudo ./path/to/webcore_install.sh webcore-fonts-3.0-1
You might need to change the permissions on the shell
script also:
chmod +x webcore_install.sh
Answered By - l'L'l Answer Checked By - Marilyn (WPSolving Volunteer)