#!/bin/sh

set -e

name=$([[ $1 ]] && echo $1 || echo "node")
mount=$([[ $2 ]] && echo $2 || echo "$HOME/projects/")

read -p "Port to expose (default = 8080) " port

if [[ $port == "" ]]; then
	port=8080
fi

if [[ $port == "none" ]]; then
	echo "
=> Mounting folder to /mnt (in container)
=> Starting container (no bound ports)
"
	docker run -it \
		-v $mount:/mnt \
		-v ~/.config/fish:/root/.config/fish \
		-v ~/projects/system/dotfiles/scripts/:/root/projects/system/dotfiles \
		--name $name \
		--hostname jh-dev-container-$name \
		-w /mnt \
		git.janishutz.com/registry/dev-container-npm
else
	echo "
=> Mounting folder to /mnt (in container)
=> Starting container
=> Port $port the same internally and externally
"

	docker run -it \
		-v $mount:/mnt \
		-v ~/.config/fish:/root/.config/fish \
		-v ~/projects/system/dotfiles/scripts/:/root/projects/system/dotfiles \
		--name $name \
		--hostname jh-dev-container-$name \
		-p $port:$port \
		-w /mnt \
		git.janishutz.com/registry/dev-container-npm
fi
