I'm writing a script that installs and configures Nagios to my requirements. It requires cpanm and some perl modules.
It's using the step/try/next function from here: https://stackoverflow.com/a/5196220
step "Downloading cpanm installer"
try `wget -q http://cpanmin.us -O $swrepo/cpanm.install`
next
step "Installing cpanm"
try echo '{ exec </dev/tty; cat $swrepo/cpanm.install | perl - App::cpanminus; }' | bash
# try bash -c "$(cat $swrepo/cpanm.install | perl - App::cpanminus)"
# try cat $swrepo/cpanm.install | perl - App::cpanminus
next
step "Installing Perl module Nagios Config"
try `cpanm Nagios::Config`
next
My problems here are:
whichever way I attempt to run the install for cpanminus, it fails the script, and won't install properly. I can't seem to make it function outside of the step/try/next functions (not that I want it to.)
The cpanm command fails too. If I isolate and run only this part of the script, it still fails, with "cpanm command not found." I can run it manually at the command line.
Any pointers for the slightly frustrated?
Update
I pulled the cpanm setup out to a separate file: step "Installing cpanm" try sh conf_cpanm.sh next
Which works, and I'll probably try and pull it back in at a later date, but so far that functions. So it can stay.
However, doing the same for try cpanm Nagios::Config won't work. The file looks like this:
#!/bin/bash
cpanm Nagios::Config
...and if I run that by calling sh conf_nagcpanm.sh
it works fine.