From 1fa67cded0d80c0c9a42121a314049eccbfed684 Mon Sep 17 00:00:00 2001 From: tin6150 Date: Thu, 21 Sep 2017 22:24:58 -0700 Subject: [PATCH] singularity installer script --- install | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 install diff --git a/install b/install new file mode 100755 index 0000000..628f6e0 --- /dev/null +++ b/install @@ -0,0 +1,94 @@ +#!/bin/bash + +# This script install singularity + +function print_usage () { + echo "This script download singularity, compile and installs it" + echo "root prividge is needed as some files need to be installed with suid. eg:" + echo "sudo ./install will install to /usr/local/singularity-\$BUILD" + echo "sudo ./install --prefix=/opt --build=2.4.alpha will install to /opt/singularity-2.4.alpha" +} + +### process command line arguments ### +# option parsing ref: +# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash +for i in "$@"; do + case $i in + -p=*|--prefix=*) + PREFIX="${i#*=}" + shift # past argument=value + ;; + -b=*|--build=*) + #BUILD="${i#*=}" + BUILD="${i#*=}" + shift # past argument=value + ;; + -h|--help) + print_usage + exit 255 + ;; + *) + echo "Unknown argument. Use -h for help" + exit 255 + ;; + esac +done + + + +### actual install ### + +PREFIX="${PREFIX:-/usr/local}" # default install to /usr/local unless otherwise specified +#VER="{VER:-}" +if [[ x${BUILD} == "x" ]] ; then + BUILD=$(date "+%Y.%m%d") +fi +INSTALLDIR=${PREFIX}/singularity-${BUILD} + +echo "This script install singularity to ${INSTALLDIR}" +echo "Press ^C in the next 15 seconds to cancel" +sleep 15 +#echo "Press ^C to cancel or the ANY key to continue..." +#read CONFIRM +echo "installing..." + + + +if [[ ! -d ${INSTALLDIR} ]]; then + mkdir -p ${INSTALLDIR} + EXITCODE=$? + if [[ $EXITCODE -gt 0 ]]; then + echo "Unable to create ${INSTALLDIR}. Exiting." + exit $EXITCODE + fi +fi + +GITSOURCE=${INSTALLDIR}/github +if [[ ! -d ${GITSOURCE} ]] ; then + # singularity never pulled from github, setting it up now + mkdir ${GITSOURCE} + cd ${GITSOURCE} + git clone https://github.com/singularityware/singularity.git +else + # update code before install + cd ${GITSOURCE}/singularity + git pull +fi + +cd ${GITSOURCE}/singularity +./autogen.sh +EXITCODE=$? +if [[ $EXITCODE -gt 0 ]]; then + echo "autogen didn't work correctly. " + echo "Please make sure the following packages are installed: libtool automake autoconf" + exit $EXITCODE +fi +./configure --prefix=${INSTALLDIR} +make +sudo make install +EXITCODE=$? +if [[ $EXITCODE -eq 0 ]]; then + echo "Done. Singularity installed to ${INSTALLDIR}." +else + echo "Something didn't go right, Singularity install exits with ${EXITCODE}." +fi