#!/bin/sh # $Id: prerequisites_imapsync,v 1.25 2018/04/24 00:14:23 gilles Exp gilles $ MODULES_MANDATORY=' App::cpanminus Authen::NTLM CGI Compress::Zlib Crypt::OpenSSL::RSA Data::Dumper Data::Uniqid Digest::HMAC Digest::HMAC_MD5 Digest::MD5 Dist::CheckConflicts Encode::Byte File::Copy::Recursive IO::Socket::INET IO::Socket::INET6 IO::Socket::SSL IO::Tee JSON JSON::WebToken JSON::WebToken::Crypt::RSA HTML::Entities LWP::UserAgent Mail::IMAPClient Module::Implementation Module::Runtime Module::ScanDeps Net::SSLeay Package::Stash Package::Stash::XS PAR::Packer Parse::RecDescent Pod::Usage Readonly Regexp::Common Sys::MemInfo Term::ReadKey Test::Fatal Test::Mock::Guard Test::MockObject Test::More Test::Pod Test::Requires Test::NoWarnings Test::Deep Test::Warn Try::Tiny Unicode::String URI::Escape ' test_perl() { # First we need perl if perl -v > /dev/null 2>&1 ; then perl_version=`perl -e 'printf "%vd\n", $^V;'` echo Ok: Found Perl $perl_version return 0 else echo Failure: Perl is not here. You have to install Perl first. return 1 fi } test_make() { # Second we need make to build some Perl modules if make -v > /dev/null 2>&1 ; then make_version=`make -v |head -1` echo Ok: Found make $make_version return 0 else echo Failure: make is not here. You have to install the make command. return 1 fi } test_module() { test -n $1 || return M_tested=$1 shift if perl -m"$M_tested" -e '' >/dev/null 2>&1 ; then echo "Ok: Found Perl module $M_tested" else echo "Failure: Not found Perl module $M_tested $@" LIST_TO_INSTALL="$LIST_TO_INSTALL $M_tested" fi return } test_mandatory_modules() { for M in $MODULES_MANDATORY do test_module $M done } search_modules_any() { test -n "$*" || { echo "All needed modules are already installed" return } apt-file -h > /dev/null 2>&1 && { search_modules_apt "$@" return } yum -h > /dev/null 2>&1 && { search_modules_yum "$@" return } # no yum, no apt-get { search_modules_cpanm "$@" return } } search_modules_cpanm() { cat < /dev/null 2>&1 && sw_vers # Darwin lsb_release -dirc > /dev/null 2>&1 && lsb_release -dirc # Linux uname -a } test_unix #exit test_perl || exit test_make || exit test_mandatory_modules list_to_install EXIT=$? # Help the user to install missing modules search_modules_any $LIST_TO_INSTALL test "$1" = "MODULES_MANDATORY" && search_modules_any $MODULES_MANDATORY exit $EXIT