#!/bin/bash
set -e
set -u

LABEL="Container name"

if [ "$1" == "rmi" ]; then
	LABEL="Image name"
fi



#echo "$LABEL $2"	

if [ "$1" == "status" ]; then
	docker ps -a --filter "name=$2"  	
elif [ "$1" == "stop" ]; then
	CONTAINER_ID=$(sudo docker container ps -aq --filter "name=$2")
	if [ -n "$CONTAINER_ID" ]; then
		sudo docker stop $2
		echo Container $2 stopped
	fi	
elif [ "$1" == "start" ]; then
	CONTAINER_ID=$(sudo docker container ps -aq --filter "name=$2")
	if [ -n "$CONTAINER_ID" ]; then
		sudo docker start $2
		echo Container $2 started
		
	fi	
elif [ "$1" == "rm" ]; then
	CONTAINER_ID=$(sudo docker container ps -aq --filter "name=$2")
	if [ -n "$CONTAINER_ID" ]; then
		sudo docker rm -f $2
		echo Container $2 removed
	fi	

elif [ "$1" == "rmi" ]; then
	IMAGE_ID=$(sudo docker images -q $2)
	if [ -n "$IMAGE_ID" ]; then
		sudo docker rmi -f $IMAGE_ID
	fi	
fi
