I have a shell script which checks if there is an internet connection (by pinging google), and then calls
yum install packageA packageB --assumeyes
How would I confirm that the packages were installed (or were already installed)? Do I make another yum call and parse the output (I presume this gets very complicated if the system is in another language)?
I've used the following method, which might not be foolproof, but seems to work:
Assuming the variable PACKAGES contains the list of packages you want to install, then:
Run yum -y install $PACKAGES (I assume if this is a script, you really want to pass -y to avoid prompting).
Check its exit status in order to detect some failure conditions.
Run rpm --query --queryformat "" $PACKAGES, which will output nothing for each package that was installed successfully, and will output package <name> is not installed for each failure.
Check its exit status, which appears to be the number of packages that were not successfully installed, i.e. will be 0 on success as usual.
This will only work if PACKAGES contains plain package names that yum is expected to find in a repository, not if it contains other things that yum accepts like URLs, file names or Provides: names.
Based on this random post, it looks like yum returns an error code to the shell. You can test this out by running a command and then immediately (as the next command) doing:
echo $?
That will print the previous command's return code. Success should be 0, failure of some kind nonzero. But that's just a guess since I don't have a box accessible to me at the moment. :)
By ping google.com does not ensure the yum repo you trying to connect is available
The command to check whether a package is already installed :-
yum list installed PACKAGE_NAME
Related
Is there any way, within the chocolateyinstall.ps1 file, to check if the process was triggered with the Upgrade command versus the Install command?
I tried using things like "choco list --lo" and "choco outdated", but those kept bringing up the package currently being installed - even if it hadn't yet been fully installed. I was hoping there was some sort of environment variable or something easy that I've overlooked.
Thanks!
I am using AWS Elastic Beanstalk on a Linux machine and need to install some fonts in .ebextensions:
container_commands:
01_getfont:
command: sudo yum -y install http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
That works well the 1st time, with the fonts installed.
The 2nd time when I deploy the EB again, it now gave me this error:
Application update failed at 2019-01-28T23:44:14Z with exit status 1 and error: container_command 01_getfont in .ebextensions/fonts.config failed.
Loaded plugins: priorities, update-motd, upgrade-helper
Examining /var/tmp/yum-root-0Yx1DY/webcore-fonts-3.0-1.noarch.rpm: webcore-fonts-3.0-1.noarch
/var/tmp/yum-root-0Yx1DY/webcore-fonts-3.0-1.noarch.rpm: does not update installed package.
Error: Nothing to do.
How do I avoid getting that errors when that package has been installed on the same EC2 instance the 2nd time?
I found out the answer to this problem later, posting it here for the benefits of others with similar issue.
I use reinstall instead:
sudo yum -y reinstall http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
This will work the 1st time and all other times of deployment.
Edit:
The above does not work as well as reinstall will fail if package is not installed. I ended up detecting if the package has been installed, if not, install it else re-install:
command: sudo yum -q list installed webcore-fonts.noarch &>/dev/null && sudo yum -y reinstall http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm || sudo yum -y install http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
Use the packages directive:
packages:
rpm:
webcore-fonts: http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
This will handle not installed and already installed scenarios.
Yum can return a non-zero exit status for things that are not really errors, causing higher-level systems such as Elastic Beanstalk to think the script has failed.
In particular, yum sometimes says "Nothing to do" with exit status of 1 - this can mean various things but includes the case where required packages are already installed.
The way I work around this for scripts using yum is:
yum -y install somepackage
if [ $? -ne 1 ]; then # Exit on any any error except 'nothing to do'
exit 0
fi
A simpler way is just to ignore all errors by appending a true or exit 0 command - however, this is eventually going to bite you when the Yum repo is unreachable, or Yum has out of date metadata, etc.
Advanced tip
If you have several yum commands, or more error codes to handle, you might want to read up on the shell trap command, specifically on EXIT or ERR which lets you handle these cases in a single place, and potentially not exit on unwanted errors. See this stack for more on this.
Alternative for local installs
See this answer for more, including a simple alternative when installing RPMs that you have downloaded.
I just created rpm package which contains few shell scripts and My rpm executes those shell scripts in post installation step ( i.e %post section).
My RPM is created successfully and when I run
rpm -ivh myrpmfile.rpm RPM able to find my shell scripts and running them properly. Those scripts also install few other packages with yum so when yum try to install those packages it hangs with the following error
Warning: RPMDB altered outside of yum
Sometimes it hangs at the following state.
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
You can't call yum from your %post because the database is locked. If you need other packages installed, you set them as Required. If your RPM also installs the yum repo files, then you need to make them into two RPMs.
That warning is just because you used rpm directly "behind its back" and most likely is a red herring.
I'm used to apt-get however today I'm stuck by something really easy. I'm on a Debian 8 VM and need to use gethostip. As it's part of syslinux here is what I've done:
$ sudo apt-get install syslinux
$ gethostip -d localhost
However it returns me bash: gethostip: command not found. I also tried which gethostip to find the package and it returns nothing.
What should I do in order to make it works?
gethostip is not part of the syslinux binary package.
Debian chose to split syslinux (the source package) into multiple binary (== installable) packages, to allow people/dependencies to just install the components they need. E.g. if you don't want to create bootable CDs, chances are high that you won't need the isolinux package.
The package that contains /usr/bin/gethostip is called syslinux-utils.
You can use the search on packages.debian.org to find out, which package installs a given file.
Alternatively you could install the command-not-found package, that will suggest to you which package to install when you typed a yet-unknown command on the cmdline.
I have a simple bash script that connects to a series of servers and updates a specific package, using a here-string to answer a prompt:
sudo /usr/bin/apt-get install package-name <<< Y
The prompt is:
Configuration file /etc/package-name/package-name.conf
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : background this process to examine the situation
The default action is to keep your current version.
*** package-name.conf (Y/I/N/O/D/Z [default=N] ?
This is the error when it doesn't work:
dpkg: error processing package-name (--configure):
EOF on stdin a conffile prompt
Errors were encountered while processing:
package-name
I'm not able to install expect or any other programs on the servers. Any help would be appreciated.
You should pass in a dpkg option to specify at the prompt the desired behavior in this scenario. Then it won't prompt.
sudo apt-get -o DPkg::Options::="--force-confnew" -y install package-name
(Untested; obtained by googling.)
If you look at the apt-get man page, you can find an option (-y) to answer yes for you. Why not try that.