From 4d26429cc99fd58b9ef40cfaa8f8847509590939 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 24 Aug 2013 22:54:13 -0700 Subject: [PATCH] Add check for required Perl modules As the first step in the install process check that all the required Perl modules are available to prevent creating an installation that will ultimately not work. --- install.sh | 7 ++++ toolbox/check-perl-modules.pl | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100755 toolbox/check-perl-modules.pl diff --git a/install.sh b/install.sh index f00b9f6..246ddca 100755 --- a/install.sh +++ b/install.sh @@ -4,6 +4,13 @@ set -e +# Run perl module checker +if [ ! -x toolbox/check-perl-modules.pl ]; then + echo "ERROR: missing toolbox/check-perl-modules.pl!" >&2 + exit 1 +fi +toolbox/check-perl-modules.pl + # What Config should we use? [ -n "$GIROCCO_CONF" ] || GIROCCO_CONF=Girocco::Config echo "*** Initializing using $GIROCCO_CONF..." diff --git a/toolbox/check-perl-modules.pl b/toolbox/check-perl-modules.pl new file mode 100755 index 0000000..96cc208 --- /dev/null +++ b/toolbox/check-perl-modules.pl @@ -0,0 +1,86 @@ +#!/usr/bin/perl + +# check-perl-modules.pl -- check for modules used by Girocco +# Copyright (c) 2013 Kyle J. McKay. All rights reserved. +# License GPLv2+: GNU GPL version 2 or later. +# www.gnu.org/licenses/gpl-2.0.html +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +# Attempt to require all the modules used by Perl anywhere in Girocco and +# report the failures. There is special handling for the SHA-1 functions +# and some other optional modules. + +# These ones are not errors + +eval {require Proc::ProcessTable; 1} or +print "Warning: missing Perl module Proc::ProcessTable, optional ". + "toolbox/kill-stale-daemons.pl will not function\n"; + +eval {require HTML::Email::Obfuscate; 1} or +print "Warning: missing Perl module HTML::Email::Obfuscate, optional gitweb ". + "email obfuscation will be disabled\n"; + +eval {require HTML::TagCloud; 1} or +print "Warning: missing Perl module HTML::TagCloud, optional gitweb tag cloud ". + "display will be all one size\n"; + +eval {require HTTP::Date; 1} || +eval {require Time::ParseDate; 1} or +print "Warning: missing Perl module HTTP::Date and Time::ParseDate, gitweb ". + "will always return true to if-modified-since feed requests\n"; + +# These ones are required + +my $errors = 0; + +# For SHA1, any of Digest::SHA, Digest::SHA1 or Digest::SHA::PurePerl will do + +eval {require Digest::SHA; 1} || +eval {require Digest::SHA1; 1} || +eval {require Digest::SHA::PurePerl; 1} or +++$errors, +print STDERR "One of the Perl modules Digest::SHA or Digest::SHA1 or " +. "Digest::SHA::PurePerl must be available\n"; + +my @modules = qw( + CGI + CGI::Carp + CGI::Util + Digest::MD5 + Encode + Errno + Fcntl + File::Basename + File::Find + File::Spec + File::stat + Getopt::Long + IO::Handle + IO::Socket + IPC::Open2 + JSON + LWP::UserAgent + MIME::Base64 + Pod::Usage + POSIX + RPC::XML + RPC::XML::Client + Socket + Storable + Time::Local +); + +foreach my $module (@modules) { + eval "require $module; 1" or + ++$errors, print STDERR "Missing required Perl module $module\n"; +} + +eval {require JSON; 1} && +eval {require LWP::UserAgent; 1} && +eval {require RPC::XML; 1} && +eval {require RPC::XML::Client; 1} or +print STDERR "Note that Perl modules JSON, LWP::UserAgent, RPC::XML and RPC::". + "XML::Client are required by the ref-change notification mechanism\n"; + +exit($errors ? 1 : 0); -- 2.11.4.GIT