Creating a script to install a Perl application and its dependencies automatically

Solution 1:

Hmm, One way would be to look at writing a wrapper around the systems package manager, i.e. apt-get, and if packages not returned then install with cpan, cpanm, etc.

sub check_pre_req_package {
  my $package = shift;
  system("dpkg -s $package > /dev/null 2>&1");
  if ( $? != 0 ) {
    system("apt-get -y install $package > /dev/null 2>&1");
      if ( $? != 0 ) {
        system("cpanm $package");
      }
  }
  elsif ($? == 0) {
    print "Package $package is already installed \n";
  }
}

my @pre_req_packages = qw(strace nmap gcc);

foreach(@pre_req_packages) {
  check_pre_req_package($_);
}

Of course with that way you'd have to be case sensitive (or change the case) as I believe that debian uses a format of lib(package-name)-perl in all lower case and cpan will want a different format, etc, plus this code is untested and something that just thrown together.

Then there's good old bash scripting, as hell I used system commands in this example

My best suggestion is that you look into using something like cfengine or puppet and/or some other I'm sure is out there system configuration management. Then use svn or git or so... to make changes to push to a repo that will deploy to all your servers. If your going to be managing and making the changes to "numerous" servers then cfengine/puppet/etc will make your life a lot easier once set up. just my two.