#!/bin/bash

read -p "Do you want to create isolated network y/N? " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo    # (optional) move to a new line
    docker network create --driver bridge isolated
    printf "\n\nisolated network created\n\n"
else
    printf "not creating isolated network\n\n"
fi

read -p "Do you want to run mysql-server y/N? " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo    # (optional) move to a new line
    docker run --name mysql-server -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --network isolated -d mysql:5.7.22
    printf "\n\nmysql-server runned\n\n"
else
    printf "not running mysql\n\n"
fi

if [ -n "$1" ]; then
   VERSION=$1
else
    printf "Version shall be set as a parameter.\nExample:\n\trun YOUR_VERSION\n\n"

    read -p "Do you want to set VERSION to 0.0.1 y/N? " -n 1 -r
    echo    # (optional) move to a new line
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        echo    # (optional) move to a new line
        VERSION=0.0.1
    else
        echo "exiting"
        exit -1
    fi
fi

read -p "Do you want to run image with version $VERSION y/N? " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo    # (optional) move to a new line
    docker run --name elprotect-$VERSION -p 8082:80 -v $(pwd)/src:/var/www/html --network isolated -d elprotect:$VERSION
    docker exec -it elprotect-$VERSION bash
else
    printf "not running elprotect:$VERSION\n\n"
fi
