Last active
August 29, 2015 14:00
-
-
Save diginc/11151145 to your computer and use it in GitHub Desktop.
Script to install local lib CPAN modules, just tell it what to install in the MODULES variable and the rc file to setup for perl local lib environment variables so it can find the locally installed modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Customize variables: | |
RCFILE=~/.bashrc | |
MODULES=( | |
"XML::Simple" | |
"DateTime::Event::Cron" | |
"Switch" | |
"LWP::Simple" | |
) | |
function cpan_local_lib_setup { | |
RCFILE=$1 | |
if ( ! perl -Mlocal::lib 1>&2 > /dev/null ) ; then | |
sudo perl -MCPAN -e 'install local::lib'; | |
fi; | |
if ( ! grep -q 'local::lib' $RCFILE ) ; then | |
echo "Setting up $RCFILE Perl local::lib environment variables" | |
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >> $RCFILE | |
fi; | |
} | |
function cpan_local_install { | |
if ( perl -Mlocal::lib -M$1 -we 1 ) ; then | |
echo $1 "already installed." | |
else | |
echo "Cannot find module $1 installed" 1>&2 | |
perl -MCPAN -Mlocal::lib -e "install $1" | |
fi | |
} | |
# MAIN RUN | |
cpan_local_lib_setup $RCFILE && { | |
for module in "${MODULES[@]}"; do | |
cpan_local_install $module | |
done; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment