add-strudel2-conda 1.79 KB
Newer Older
Chris Hines's avatar
Chris Hines committed
1
2
3
4
5
6
#!/bin/bash
if [ $# -eq 2 ]
  then
    INSTALLDIR=$1
    ENVNAME=$2
  else
7
8
      echo "please try add-strudel2-conda INSTALLDIR ENVNAME"
      echo "where INSTALLDIR is a path to miniconda that can be activated"
Chris Hines's avatar
Chris Hines committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
      echo "and ENVNAME is the name of an environment"
fi




SCRIPT=$(readlink -f $0) # Get the base directory

# The section below sets up the paths to executable files and templates
JQ=`dirname $SCRIPT`/jq
TEMPLATE=`dirname $SCRIPT`/conda-env-jupyter.sh.template
WORKINGDIR=$INSTALLDIR
APPSJSON=/home/$USER/.strudel2/apps.json
APPSJSONTEMPFILE=/home/$USER/.strudel2/apps.json.temp
APPSJSONNEW=/home/$USER/.strudel2/apps.json.new
APPSJSONTEMPLATE=`dirname $SCRIPT`/conda-env-jupyter-apps.json.template


mkdir -p ~/.strudel2/
cp -rf $TEMPLATE ~/.strudel2/conda-env-jupyter.sh
chmod +x  ~/.strudel2/conda-env-jupyter.sh

# Configure Custom Name for apps.json

WORKINGDIRSUBS=`echo "${INSTALLDIR//\//.}"` # Need this to remove the / from the template since it breaks Slurm
sed -e "s|LOCATION|${WORKINGDIRSUBS}|g" $APPSJSONTEMPLATE > $APPSJSONTEMPFILE
sed -i -e "s|INSTALLDIR|${INSTALLDIR}|g" $APPSJSONTEMPFILE
sed -i -e "s|ENVNAME|${ENVNAME}|g" $APPSJSONTEMPFILE

# This will check whether the apps.json already exists
# If it does, use the jq binary to append the template into existing file
# Else, just copy the template file over.

if [ -f $APPSJSON ]
  then
    $JQ -s '.[0] + .[1]' $APPSJSON $APPSJSONTEMPFILE > $APPSJSONNEW
    rm $APPSJSON
    mv $APPSJSONNEW $APPSJSON
  else
    mv $APPSJSONTEMPFILE $APPSJSON
fi

rm -rf $APPSJSONTEMPFILE

# Configure Jupyter Notebook for Strudel2

echo $INSTALLDIR >> ~/.jupyterenv
mkdir -p ~/.strudel2/
sed -e "s|LOCATION|${WORKINGDIR}|g" $TEMPLATE > ~/.strudel2/jupyter.sh
chmod +x  ~/.strudel2/jupyter.sh

60
echo "Strudel2 is now configured to use your conda environment."