#!/bin/bash while getopts fh OPT do case $OPT in "f") FLAG_FORCE="TRUE" ;; "h") FLAG_HELP="TRUE" ;; * ) FLAG_HELP="TRUE" ;; esac done shift `expr $OPTIND - 1` TARGET_VERSION="$1" LOCATION="$2" CONFIGURE_OPTIONS=${@:4} if [ "x"$FLAG_HELP != "x" -o "x$LOCATION" = "x" ]; then echo "[usage] perl-install [-f] VERSION LOCATION [-- CONFIGURE_OPTIONS]" echo " ex: perl-install 5.18.2 ~/local/perl-5.18" exit 0 fi cd $(dirname $0) set -e mkdir -p ./bin curl -s https://raw.githubusercontent.com/tokuhirom/Perl-Build/master/perl-build > ./bin/perl-build curl -s -L http://cpanmin.us/ > ./bin/fatpack_cpanm set +e if [ "x"$FLAG_FORCE = "x" -a -d "$LOCATION" -a -x "$LOCATION/bin/perl" ]; then check=$("$LOCATION"/bin/perl -v | grep "This is perl" | grep "v$TARGET_VERSION") if [ "x$check" != "x" ]; then echo "perl $TARGET_VERSION already installed on $LOCATION" echo "To do force re-install, use '-f' option" exit 0 fi fi echo "Start to build perl $TARGET_VERSION ..." perl ./bin/perl-build -DDEBUGGING=-g $CONFIGURE_OPTIONS "$TARGET_VERSION" "$LOCATION" > /tmp/$USER-perl-install.log 2>&1 if [ $? -ne 0 ]; then echo "perl-build failed. see log: /tmp/$USER-perl-install.log" exit 1 fi "$LOCATION"/bin/perl ./bin/fatpack_cpanm --notest App::cpanminus Carton Server::Starter > /tmp/$USER-perl-install-cpanm.log 2>&1 if [ $? -ne 0 ]; then echo "failed to install cpanm/carton. see log: /tmp/$USER-perl-install-cpanm.log" exit 2 fi echo "perl $TARGET_VERSION (and cpanm/carton) successfully installed on $LOCATION" echo "To use this perl, do 'export PATH=$LOCATION/bin:\$PATH'."