#!/bin/bash

# This bash script uploads the pdf2htmlEX docker image to docker hub
#
# We EXPECT the following environment variables to be set:
#    DOCKER_USERNAME
#
# You can OPTIONALLY set the following environment variables:
#    DOCKER_PASSWORD  (if not set you will be asked for your password)
#

source ./buildScripts/reSourceVersionEnvs

echo ""
echo "-------------------------------------------------------------------"
echo "UPLOADING pdf2htmlEX Docker Image to Docker Hub"
echo "-------------------------------------------------------------------"
echo ""

##################################
# push docker image
#
if [ -x "$(which docker)" ]; then

  if [ -z "$DOCKER_USERNAME" ]; then
    echo ""
    read -p "Enter the Docker usernane): " DOCKER_USERNAME
    echo ""
    if [ -z "$DOCKER_USERNAME" ]; then
      echo "DOCKER_USERNAME not set... so we do not know where to push image."
      exit 1
    fi
  fi

  if [ -z "$DOCKER_PASSWORD" ]; then
    echo ""
    echo "Please type your the Docker hub password"
    docker login -u "$DOCKER_USERNAME"
  else
    echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  fi

  docker push $DOCKER_USERNAME/pdf2htmlex

else
  echo "Docker is not installed... skipping upload of docker image."
fi

