#!/bin/sh

base_path="~/projects/system/dev-env/scripts/"
mount_path=$(pwd)
if [[ -n "$2" ]]; then
	name=$2
else
	name=$(pwd | rev | cut -d "/" -f 1 | rev)
fi

if [[ $1 == "help" ]]; then
	echo "
dev-containers [container|rm|help] [name]

Container can be one of:
    - base
    - node
    - php
    - python
    - torch-rocm
    - vue
    - webserver
rm removes the container for the current directory if provided name is existing container, or unspecified.
    "
	exit 0
fi

if [[ $(systemctl is-active docker) != "active" ]]; then
	echo "
Docker daemon not running, starting with systemctl
    "
	sudo systemctl start docker
fi

if [[ $1 == "rm" ]]; then
	echo "
    janishutz dev containers

    -> Removing container $name <-
"
	docker stop $name
	docker container rm $name
else
	echo "
    janishutz dev containers

    -> Creating container $name <-
"
	eval "${base_path}$1-container $1-$name $mount_path"
fi
