Skip to content

Instantly share code, notes, and snippets.

@ocaisa
Last active June 17, 2016 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ocaisa/1ff64009b0c91acc84eae00bb1cb3d65 to your computer and use it in GitHub Desktop.
Save ocaisa/1ff64009b0c91acc84eae00bb1cb3d65 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
echo
echo This script is intended for installing EasyBuild and Lmod in a bash environ
ment
echo If that\'s not the shell you use then it may not work properly for you!
echo
echo
# Check a program exists on the system
function check_program_exists {
command -v $1 >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not install
ed. Aborting."; exit 1; }
}
function download_file {
check_program_exists wget
wget $1
if [ "$?" != 0 ]; then
echo "Command"
echo " wget $1"
echo "failed. You might have an internet connectivity problem"
exit 1
fi
}
# Test that we have essential things
check_program_exists "python"
check_program_exists "tclsh"
check_program_exists "awk"
check_program_exists "tee"
check_program_exists "grep"
check_program_exists "tail"
# Set the installation directory
if [ "$#" -gt 1 ]; then
echo "Illegal number of parameters"
echo "Expecting path of target directory only"
exit 1
fi
if [ -z "$1" ] ; then
echo "No argument supplied, using current directory as EasyBuild prefix"
ROOT_INSTALL_DIR=$(pwd)
else
ROOT_INSTALL_DIR=$1
fi
# Check we have write permissions there and change to that directory
if [ -w $ROOT_INSTALL_DIR ] ; then
echo "Using $ROOT_INSTALL_DIR as your \$EASYBUILD_PREFIX"
echo
else
echo "You do not have permission to write to $ROOT_INSTALL_DIR"
echo "Please use an argument to the script to give the path of your target!"
echo "(or move to a directory where you have write permissions)"
exit 1
fi
# Change directory
echo Moving to installation directory:
pushd $ROOT_INSTALL_DIR
echo
# Do any necessary downloading
if [ ! -f $ROOT_INSTALL_DIR/TCL_MOD/modulecmd.tcl ] ; then
mkdir -p TCL_MOD
if [ -f $ROOT_INSTALL_DIR/modulecmd.tcl ] ; then
mv modulecmd.tcl TCL_MOD/modulecmd.tcl
else
# Grab the file from sourceforge
download_file 'https://sourceforge.net/p/modules/modules-tcl/ci/master/tree/modulecmd.tcl?format=raw'
# It has a funky name because of the URL, let's rename appropriately
mv modulecmd.tcl*raw TCL_MOD/modulecmd.tcl
fi
fi
chmod +x TCL_MOD/modulecmd.tcl
export PATH=$PATH:$ROOT_INSTALL_DIR/TCL_MOD
eval `tclsh $(which modulecmd.tcl) sh autoinit`
echo "Installing EasyBuild using EasyBuild bootstrapping script"
if [ ! -f $ROOT_INSTALL_DIR/bootstrap_eb.py ] ; then
download_file 'https://raw.githubusercontent.com/hpcugent/easybuild-framework/develop/easybuild/scripts/bootstrap_eb.py'
fi
# Log the output of the bootstrapping and grab the change that needs to be made to the MODULEPATH
echo
echo "Bootstrapping EasyBuild and storing stdout in"
echo " $ROOT_INSTALL_DIR/eb_bootstrap_stdout.log"
echo "and stderr in"
echo " $ROOT_INSTALL_DIR/eb_bootstrap_stderr.log"
echo
echo
export EASYBUILD_PREFIX=$ROOT_INSTALL_DIR
new_module_path=$(python bootstrap_eb.py $EASYBUILD_PREFIX > >(tee eb_bootstrap_stdout.log) 2> >(tee eb_bootstrap_stderr.log) |grep MODULEPATH|awk '{print $NF}')
# Add the installed path to our MODULEPATH
export MODULEPATH=$new_module_path:$MODULEPATH
echo Loading EasyBuild and using to install Lmod
echo
# Load EasyBuild and set necessary options
module load EasyBuild
export EASYBUILD_MODULES_TOOL=EnvironmentModulesTcl
export EASYBUILD_ROBOT=$EASYBUILD_PREFIX/essential_easyconfigs:$EASYBUILD_ROBOT # TODO Remove this temporary path when dummy Lmod gets merged...but the robot still needs to be on
# Install the most recent working version of Lmod at the dummy level
lmod_easyconfig=$(eb --from-pr=3229 --allow-modules-tool-mismatch --search ^Lmod-[^-]*$ |grep Lmod|tail -1 |awk '{print $NF}')
# Potentially could install Lmod to another path, so that the default view isn't cluttered
eb --from-pr=3229 --allow-modules-tool-mismatch $lmod_easyconfig
module load Lmod
echo
echo
echo --------------------------------------------------------------------------------
echo \# Add the following to your .bashrc
echo --------------------------------------------------------------------------------
echo export EASYBUILD_MODULES_TOOL=Lmod
echo export EASYBUILD_PREFIX=$EASYBUILD_PREFIX
echo export MODULEPATH=$new_module_path:\$MODULEPATH
echo . $EBROOTLMOD/lmod/lmod/init/bash
echo . $EBROOTLMOD/lmod/lmod/init/lmod_bash_completions
echo --------------------------------------------------------------------------------
echo
echo
echo If you use another type of shell you will need to adjust the above lines!!!
# Tidy up
#rm -r TCL_MOD
# In case this file was sourced, do a popd
echo Exiting the installation directory
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment