#!/bin/sh

##########################################################################
#   Script description:
#       Set up a clean Linux environment for running Conda packages.
#       
#   History:
#   Date        Name        Modification
#   2021-04-12  Jason Bacon Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $(whoami) = root ]; then
    cat << EOM

conda-shell should not be run as root.  Conda is designed to allow
non-root users to install software packages for their own use.

Many of the community channels contain packages with little or no quality
control or security checks.

EOM
    exit 1
fi

if [ -e /usr/local/sbin/node-type ] && [ $(/usr/local/sbin/node-type) != compute ]; then
    printf "Error: $0 should only be run on compute nodes.\n"
    exit 1
fi

if [ $# != 0 ]; then
    usage
fi

cat << EOM

Starting Linux bash shell to ensure that Conda packages are fully functional.

Note that uname will return Linux rather than $(uname) and some other aspects
of the environment will also indicate Linux.

Type "exit" or "Ctrl+d" to return to your $(uname) shell.

EOM

# Some tools (e.g. fastq-dump) will fail if they chose FreeBSD binaries over
# Linux, so put the Linux binaries explicitly first in PATH.  Otherwise,
# FreeBSD will only use tools rooted in /compat/linux if they are not found
# in /.
cl=/compat/linux
export PATH=$cl/bin:$cl/usr/bin:$cl/sbin:$cl/usr/sbin:$PATH
exec $cl/bin/bash
