Last active
August 27, 2017 08:15
-
-
Save jerowe/20caccac532355dba2288b6fb665d52b to your computer and use it in GitHub Desktop.
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 | |
# Define help function | |
function help(){ | |
echo "EasyBuild Bootstrap - Bootstrap method of installing easybuild"; | |
echo "Usage example:"; | |
echo "easybuild-bootstrap (-e|--easybuild_install_base) char [(-h|--help) boolean] [(-E|--environment_modules)] [(-L|--lmod)] [(-b|--eb_version) char] [(-l|--lmod_version) char] [(-m|--em_version) char]"; | |
echo "Options:"; | |
echo "-h or --help boolean: Displays this information."; | |
echo "-E or --environment_modules: Include Environment Modules."; | |
echo "-e or --easybuild_install_base char: Easybuild software base. Required."; | |
echo "-L or --lmod: Include Lmod."; | |
echo "-b or --eb_version char: Easybuild Version - Default 3.1.0."; | |
echo "-l or --lmod_version char: Lmod Version - Default 7.3.16."; | |
echo "-m or --em_version char: Environment Modules Version - Default 3.2.10."; | |
exit 1; | |
} | |
EASYBUILD_BASE=0 | |
# Declare vars. Flags initalizing to 0. | |
environment_modules=0 | |
lmod=0 | |
eb_version="3.1.0"; | |
lmod_version="7.3.16"; | |
em_version="3.2.10"; | |
# Execute getopt | |
ARGS=$(getopt -o "h:Ee:Lb:l:m:" -l "help:,environment_modules,easybuild_install_base:,lmod,eb_version:,lmod_version:,em_version:" -n "EasyBuild Bootstrap" -- "$@"); | |
#Bad arguments | |
if [[ $? -ne 0 ]]; | |
then | |
help; | |
fi | |
eval set -- "$ARGS"; | |
while true; do | |
case "$1" in | |
-h|--help) | |
shift; | |
if [[ -n "$1" ]]; | |
then | |
help="$1"; | |
shift; | |
fi | |
;; | |
-E|--environment_modules) | |
shift; | |
environment_modules="1"; | |
;; | |
-e|--easybuild_install_base) | |
shift; | |
if [[ -n "$1" ]]; | |
then | |
EASYBUILD_BASE="$1"; | |
shift; | |
fi | |
;; | |
-L|--lmod) | |
shift; | |
lmod="1"; | |
;; | |
-b|--eb_version) | |
shift; | |
if [[ -n "$1" ]]; | |
then | |
eb_version="$1"; | |
shift; | |
fi | |
;; | |
-l|--lmod_version) | |
shift; | |
if [[ -n "$1" ]]; | |
then | |
lmod_version="$1"; | |
shift; | |
fi | |
;; | |
-m|--em_version) | |
shift; | |
if [[ -n "$1" ]]; | |
then | |
em_version="$1"; | |
shift; | |
fi | |
;; | |
--) | |
shift; | |
break; | |
;; | |
esac | |
done | |
# Check required arguments | |
if [[ $EASYBUILD_BASE == 0 ]] | |
then | |
echo "easybuild_base is required"; | |
help; | |
fi | |
echo "Beginning install." | |
echo "" | |
if [[ $lmod == 1 ]] && [[ $environment_modules == 1 ]]; then | |
echo "You must specify either lmod or environment modules." | |
exit 1 | |
fi | |
if [[ $lmod == 0 ]] && [[ $environment_modules == 0 ]]; then | |
echo "You have not specified either lmod or environment_modules." | |
echo "" | |
fi | |
EASYBUILD_NAME="eb--${eb_version}" | |
LMOD_NAME="lmod--${lmod_version}" | |
EM_NAME="em--${em_version}" | |
if [[ "$lmod" -eq "1" ]] | |
then | |
echo "We are including ${LMOD_NAME}"; | |
T="${EASYBUILD_NAME}_${LMOD_NAME}" | |
EASYBUILD_NAME=$T | |
fi | |
if [[ "$environment_modules" -eq "1" ]] | |
then | |
echo "We are including ${EM_NAME}"; | |
T="${EASYBUILD_NAME}_${EM_NAME}" | |
EASYBUILD_NAME=$T | |
fi | |
EASYBUILD_PACKAGE="easybuild=${eb_version}" | |
LMOD_PACKAGE="lmod=${lmod_version}" | |
EM_PACKAGE="environment-modules=${em_version}" | |
EB_CONDA_INSTALL="${EASYBUILD_PACKAGE}" | |
if [[ "$lmod" -eq "1" ]] | |
then | |
T="${EB_CONDA_INSTALL} ${LMOD_PACKAGE}" | |
EB_CONDA_INSTALL=$T | |
fi | |
if [[ "$environment_modules" -eq "1" ]] | |
then | |
T="${EB_CONDA_INSTALL} ${EM_PACKAGE}" | |
EB_CONDA_INSTALL=$T | |
fi | |
export EASYBUILD_PREFIX="${EASYBUILD_BASE}" | |
################################################################## | |
## Anaconda Setup | |
## We are using miniconda3/python3 from anaconda | |
################################################################## | |
echo "====================================================================" | |
echo "" | |
echo "Installing Anaconda3. This could take some time..." | |
export ANACONDA3_BASE="${EASYBUILD_BASE}/anaconda3" | |
curl -s -L https://repo.continuum.io/miniconda/Miniconda3-4.2.12-Linux-x86_64.sh > miniconda.sh && \ | |
openssl md5 miniconda.sh | grep 'd0c7c71cc5659e54ab51f2005a8d96f3' | |
chmod 777 miniconda.sh ; bash miniconda.sh -b -p $ANACONDA3_BASE | |
rm miniconda.sh && \ | |
export PATH=${ANACONDA3_BASE}/bin:$PATH && \ | |
conda config --set show_channel_urls True && \ | |
conda config --add channels conda-forge && \ | |
conda config --add channels defaults && \ | |
conda update --all --yes && \ | |
conda clean -tipy | |
echo "Finished installing Anaconda3." | |
echo "It is located in ${ANACONDA3_BASE}." | |
echo "" | |
export PATH="${ANACONDA3_BASE}/bin:${PATH}" | |
export EB_ENV="${EASYBUILD_BASE}/${EASYBUILD_NAME}" | |
export MODULEPATH="${EASYBUILD_PREFIX}/modules/all" | |
export EB_CONFIG="${HOME}/.config/easybuild" | |
################################################################## | |
## Add Easybuild Config | |
################################################################## | |
echo "====================================================================" | |
echo "" | |
echo "Creating configuration directory." | |
echo "${EB_CONFIG}" | |
mkdir -p "${EB_CONFIG}" | |
if [[ "$environment_modules" -eq "1" ]] | |
then | |
echo "You have opted to use environment modules for you module system." | |
echo "Please see: https://github.com/easybuilders/easybuild/blob/master/docs/Configuration.rst" | |
echo "Under 'Modules Tool' and 'Module File Syntax'" | |
echo "You will need to update your easybuild config accordingly." | |
echo "Additionally, please see this gist: https://gist.github.com/jerowe/99b4ca875c642ebac7c5feced8acb7f2" | |
echo "Which is a minimal configuration for easybuild with environment modules" | |
fi | |
################################################################## | |
## Install Easybuild and Lmod | |
## Create a conda env with easybuild and lmod - and nothing else | |
################################################################## | |
echo "====================================================================" | |
echo "" | |
echo "Creating easybuild conda env." | |
echo "conda create -p $EB_ENV $EB_CONDA_INSTALL" | |
echo "" | |
rm -rf $EB_ENV | |
conda create -p $EB_ENV $EB_CONDA_INSTALL | |
echo "====================================================================" | |
echo "Complete! You can load EasyBuild at any time with:" | |
echo "source activate ${EB_ENV}" | |
echo "" | |
echo "====================================================================" | |
echo "Please keep these variables!" | |
echo "The following are helpful environmental variables that you probably want to include in your ~/.bashrc or other shell." | |
echo "They will be stored in ${EASYBUILD_BASE}/source_eb for future use." | |
echo "Invoke as source ${EASYBUILD_BASE}/source_eb" | |
echo "In order to change where Easybuild deploys modules - please change the EASYBUILD_PREFIX." | |
echo "" | |
echo "export PATH=${ANACONDA3_BASE}/bin:\${PATH}" | |
echo "export MODULEPATH=${EASYBUILD_PREFIX}/modules/all:\${MODULEPATH}" | |
echo "export EASYBUILD_PREFIX=${EASYBUILD_PREFIX}" | |
echo "source activate ${EB_ENV}" | |
echo "" | |
echo "export PATH=${ANACONDA3_BASE}/bin:\${PATH}" >> ${EASYBUILD_BASE}/source_eb | |
echo "export MODULEPATH=${EASYBUILD_PREFIX}/modules/all:\${MODULEPATH}" >> ${EASYBUILD_BASE}/source_eb | |
echo "export EASYBUILD_PREFIX=${EASYBUILD_PREFIX}" >> ${EASYBUILD_BASE}/source_eb | |
echo "source activate ${EB_ENV}" >> ${EASYBUILD_BASE}/source_eb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment