#!/bin/bash

cd $(dirname $0)

. ./common.sh

if [ ! -e "./$DOCKER_PKG" ]; then
	echo "Docker package not found."
	exit 1
fi

if ( ( docker images | grep -q "^$DOCKER_IMG " ) || ( docker ps -a | grep -q " $DOCKER_CNT " ) ); then
	if [ "$1" == "-f" ]; then
		docker rm -f $DOCKER_CNT &>/dev/null
		docker rmi -f $DOCKER_IMG &>/dev/null
	else
		echo "The Docker image or container already exist. Run with -f to force overwriting"
		exit 1
	fi
fi

cat $DOCKER_PKG | docker import - $DOCKER_IMG
createContainer

echo "Done!"
