#!/bin/bash

# Check if we are in the right place
if [ ! -d ./images ]; then
    echo "You must run this command from the project's root folder."
    exit 1
fi

if [[ $# -eq 0 ]] ; then
    echo "Please tell me on which service to open the shell in."
    exit 1

elif [[ $# -gt 2 ]] ; then
    echo "Use double quotes to wrap commands with spaces"
    exit 1
else
    
    COMMAND=$2
    if [[ "x$COMMAND" == "x" ]] ; then
        echo ""
        echo "Executing: /bin/bash"
        echo ""
        docker-compose exec $1 sudo -i -u rosetta /bin/bash
    else
        echo ""
        echo "Executing: \"$COMMAND\""
        echo ""
        docker-compose exec $1 sudo -i -u rosetta /bin/bash -c "$COMMAND"
    fi

fi
