#!/bin/bash
#
# Initialize the environment for use with my tools.
#
# Several additional options are provided as one-time initializations:
#   cocalc: Initial a CoCalc project for use as described here:
#      https://alum.mit.edu/www/mforbes/public/notes/cocalc-workflow/

function usage() {
    echo "usage: source mmf_setup [-v]  OR  . mmf_setup [-v]  OR  mmf_setup cocalc"
    echo
    echo "  -v : show variables that are set"
    echo
    echo "For initial setup on cocalc.com projects:"
    echo
    echo "   mmf_setup cocalc"
    echo
}

BIN_DIR="$(dirname $BASH_SOURCE{0})"

for i in "$@"
do
    case $i in
        -v)
            echo "mmf_setup environment:"
            echo "$(mmf_setup_bash.py)"
            ;;
        smc|cocalc)
            DATA_DIR="$(python -c 'import mmf_setup;print(mmf_setup.DATA)')"
            echo "Seting up config files for CoCalc..."
            shift # move to the next argument
            "$BIN_DIR/mmf_initial_setup" \
                 -v "$DATA_DIR/config_files/cocalc" $*
            cat "$DATA_DIR/config_files/cocalc/message.txt"
            exit 0
            ;;
        *)
            usage
            exit 1
            ;;
    esac
    shift # move to the next argument
done

# Ensure that this script is sourced, not executed
if [[ -n $BASH_VERSION ]] && [[ "$(basename "$0" 2> /dev/null)" == "mmf_setup" ]];
then
    >&2 echo "Error: mmf_setup must be sourced. Run 'source mmf_setup' or '. mmf_setup' instead of 'mmf_setup'"
    usage
    exit 1
fi

eval "$(mmf_setup_bash.py)"
