Bootstrap: docker
From: debian:bullseye

%files
   /usr/local/bin/stats /usr/local/bin
   /etc/krb5.conf /etc

%post
    sed 's/PS1/PSone/' -i .singularity.d/env/99-base.sh

    sed '2s/main/main contrib non-free/' -i /etc/apt/sources.list
    apt-get -y update
    apt-get -y install locales
    sed '/en_GB.UTF/s/# //;/en_US.UTF/s/# //' -i /etc/locale.gen
    locale-gen
    apt-get -y install apt-utils python3 python3-pip isal less git ack procps psmisc
    apt-get -y install man-db gdb emacs sqlite3 curl unzip imagemagick file rsync
    apt-get -y install moreutils mercurial qpdf xsel xclip tmux xfce4-terminal
    apt-get -y install default-jdk nano jq r-base
    apt-get -y install libcld2-0 libcld2-dev
    apt-get -y install libxmu-dev libxft-dev libxaw7-dev libgdbm-dev
    apt-get -y install libgdbm-compat-dev libgmp-dev libssl-dev xbitmaps
    # do this after the above in order to
    # hide the moreutils version of parallel as moreutils.parallel
    apt-get -y install parallel
    # Allow access to cirrus modules
    apt-get -y install environment-modules
    echo 'module() { eval `/usr/bin/modulecmd bash $*`; }' >> /etc/bashrc

    apt-get -y install python3-tk
    pip3 install isal stopit cffi
    # not clear how to make these visible to anaconda/python module
    
    echo "install.packages(c('txtplot','ggplot2'))" | R BATCH --no-save

    CFLAGS='-Wno-narrowing' pip3 install cld2-cffi
    # Below not needed if we get anaconda/python3 working...
    # Most are now in ~hst/.local/lib/python3.9/site-labs/
    # pip3 install six regex chardet urllib3 cryptography
    # pip3 install scipy matplotlib statsmodels
    
    cd /usr/local/src

    curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
    unzip awscliv2.zip
    ./aws/install

    git clone https://github.com/htInEdin/pdfminer.six.git
    git clone https://github.com/htInEdin/pdfx.git
    cd pdfminer.six
    git checkout preferLoggingToWarning
    cd ../pdfx
    git checkout tidy_up_link_extraction
    cd /usr/local/lib/python3.9/dist-packages/
    ln -s /usr/local/src/pdfx/pdfx .
    ln -s /usr/local/src/pdfminer.six/pdfminer .

    sed '8i\
  if [ "$WSHARED" ]\
  then\
   PATH="$WSHARED/bin:$PATH"\
  fi\
' -i /etc/profile

    # REMEMBER to check cc/etc/profile has $WSHARED/bin in front of PATH

%environment
export WSHARED=/work/dc007/dc007/shared
export HOME=/work/dc007/dc007/$(whoami)
export SINGULARITY_SHELL=/usr/bin/bash
export LESSOPEN="| /usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s";
export SS='$SING'
export SING=sing
export PS1='\[\033[1m\]$SS\[\033[0m\]<\!>: 'x
if [ -f "$HOME/.singrc" ] 
then 
 . "$HOME/.singrc" 
fi 

%runscript
#!/bin/bash
if [ -f $WSHARED/.bash_extras ]
then
 . $WSHARED/.bash_extras
fi

cd $HOME

if [ $# -gt 0 ]
then
 exec "$@"
else
 exec /bin/bash --login
fi
