#!/bin/sh

#----------------------------------------------------------------- 
# this is a /bin/sh script that will install perl moduels 
#
#----------------------------------------------------------------- 
BootstrapModules=CPAN
RequiredModules="LWP::UserAgent Digest::MD5 File::stat Getopt::Std IO::Handle IO::File GnuPG::Interface"

if ! which perl >/dev/null 2>&1; then 
	echo "perl must be in the path"
	exit 1
fi



for i in $BootstrapModules; do
  echo "Checking for module $i"
  if ! perl -M$i -e exit >/dev/null 2>&1; then
    echo "Module $i  is required"
    exit 1;
  fi
  echo "module $i found"
done

for i in $RequiredModules; do
  echo "Checking for module $i"
  if ! perl -M$i -e exit >/dev/null 2>&1; then
    echo "Module $i is missing, trying to install"
    perl -MCPAN -e "CPAN::Shell->install($i);"
    if ! perl -M$i -e exit >/dev/null 2>&1; then echo "install failed"; exit 1; fi
    echo "module $i installed"
  fi
  echo "module $i found"
done
