#!/bin/bash
# Start the Anaconda's Python module $1.
#
# Examples:
#   ./start-module pyanaconda.modules.boss
#   ./start-module --env LD_PRELOAD=libgomp.so.1 pyanaconda.modules.payloads
#

# Process the arguments.
while true
do
  case $1 in
    # Set up the environment.
    --env)
      export $2
      shift 2
    ;;
    # Nothing else to do.
    *)
      break
    ;;
  esac
done

# Add Anaconda addons to the PYTHONPATH.
PYTHONPATH="$PYTHONPATH:/usr/share/anaconda/addons"

# Add updates & product image directories to PYTHONPATH if
# it looks like we are in the installation environment.
if [ -d "/run/install" ]; then
  PYTHONPATH="/run/install/updates:/run/install/product:/tmp/updates:/tmp/product:$PYTHONPATH"
fi

# Export the modified PYTHONPATH.
export PYTHONPATH

# Start a Python module in the detached mode.
python3 -m $1 &
