Fixing wrong dependency directory in create_repo

Improving logic of create_repo.sh script.
Changed from one common path to two different paths.
One path for cloned offline-installer directory and second for resources directory.

Issue-ID: OOM-2136

Change-Id: I627db02594c25df172c270ea015f167ea7050ca0
Signed-off-by: Jan Benedikt <j.benedikt@partner.samsung.com>
diff --git a/build/create_repo.sh b/build/create_repo.sh
index 8e12a16..b6db6ad 100755
--- a/build/create_repo.sh
+++ b/build/create_repo.sh
@@ -1,48 +1,67 @@
 #!/usr/bin/env bash
 
 container_name="centos_repo"
-# Path to folder with clonned offline-installer build directory with docker_entrypoint script
-volume_directory="."
-# Path inside container
-container_volume="/mnt/"
+# Path to folder with cloned offline-installer build directory with docker_entrypoint script
+volume_offline_directory="$(readlink -f $(dirname ${0}))"
+# Path for directory where repository will be created
+volume_repo_directory="$(pwd)"
+# Path inside container with cloned offline-installer build directory
+container_offline_volume="/mnt/offline/"
+# Path inside container where will be created repository
+container_repo_volume="/mnt/repo/"
 # Docker image name and version
 docker_image="centos:centos7.6.1810"
+# Expected directory for RPM packages
+expected_dir="resources/pkg/rhel"
+
+help () {
+    echo "Script for run docker container with RPM repository"
+    echo "usage: create_repo.sh [-d|--destination-repository output directory] [-c|--cloned-directory input directory]"
+    echo "-h --help: Show this help"
+    echo "-d --destination-repository: set path where will be stored RPM packages. Default value is current directory"
+    echo "-c --cloned-directory: set path where is stored this script and docker-entrypoint script (offline-installer/build directory). Fill it just when you want to use different script/datalists"
+    echo "If build folder from offline repository is not specified will be used default path of current folder."
+}
 
 # Getting input parametters
 POSITIONAL=()
+if [[ $# -eq 0 ]] ; then
+    help # show help
+    exit 0
+fi
 while [[ $# -gt 0 ]]
 do
-    key="$1"
-    case $key in
+    case "$1" in
         -h|--help)
             # Help parametter
-            echo -e "Script for run docker container with RPM repository\n"
-            echo "-h --help: Show this help"
-            echo -e "-d --directory: set root path with offline-installer directory and repository directory for RPM packages\n"
-            echo "If build folder from offline repository is not specified will be used default path of current folder."
-            shift # past argument
-            shift # past value
-            exit
+            help # show help
+            exit 0
             ;;
-        -d|--directory)
+        -c|--cloned-directory)
             # Directory parametter
-            # Sets path where is clonned offline-installer build directory
-            volume_directory="$2"
-            shift # past argument
-            shift # past value
+            # Sets path where is cloned offline-installer build directory
+            volume_offline_directory="$2"
             ;;
-        --default)
-            DEFAULT=YES
-            shift # past argument
+        -d|--destination-repository)
+            # Repository direcotry parametter
+            # Sets path where will be repository created
+            volume_repo_directory="$2"
             ;;
-        *)  
+        *)
             # unknown option
-            POSITIONAL+=("$1") # save it in an array for later
-            shift # past argument
+            help # show help
+            exit 1
             ;;
     esac
+    shift;shift
 done
 
+# Check if path contains expected path "resources/pkg/rhel"
+if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then
+    # Create repo folder if it not exists
+    volume_repo_directory="$volume_repo_directory"/resources/pkg/rhel
+    [ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory
+fi
 
 #Check if container "centos-repo" is running
 if [ ! "$(docker ps -q -f name=$container_name)" ]; then
@@ -56,10 +75,12 @@
     #
     docker run -d \
                --name $container_name \
-               -v ${volume_directory}:${container_volume} \
-               --entrypoint="${container_volume}offline-installer/build/docker-entrypoint.sh" \
-               -it ${docker_image} \
+               -v ${volume_offline_directory}:${container_offline_volume} \
+               -v ${volume_repo_directory}:${container_repo_volume} \
                --rm \
-               --directory ${container_volume}resources/pkg/rhel/ \
-               --list ${container_volume}offline-installer/build/data_lists/
+               --entrypoint="${container_offline_volume}docker-entrypoint.sh" \
+               -it ${docker_image} \
+               --directory ${container_repo_volume} \
+               --list ${container_offline_volume}data_lists/
+    docker logs $(docker ps --filter "name=centos_repo" --format '{{.ID}}' -a) -f
 fi
diff --git a/build/docker-entrypoint.sh b/build/docker-entrypoint.sh
index 798e1f0..1b4ec53 100755
--- a/build/docker-entrypoint.sh
+++ b/build/docker-entrypoint.sh
@@ -1,75 +1,71 @@
 #!/usr/bin/env bash
 
 # Path where will be created repository (in container)
-OOM_REPO_DIR=""
+OFFLINE_REPO_DIR=""
 
 # Path where is stored onap_rpm.list file
 RPM_LIST_DIR=""
 
+help () {
+    echo -e "Docker entrypoint script for creating RPM repository\n"
+    echo "usage: create-repo.sh [-d|--directory output directory] [-l|--list input rpm list directory]"
+    echo "-h --help: Show this help"
+    echo "-d --directory: set path for repo directory in container"
+    echo -e "-l --list: set path where rpm list is stored in container\n"
+    echo "Both paths have to be set with shared volume between"
+    echo "container and host computer. Default path in container is: /tmp/"
+    echo "Repository will be created at: /<path>/resources/pkg/rhel/"
+    echo "RMP list is stored at: ./data_list/"
+}
+
 # Getting input parametters
 POSITIONAL=()
+if [[ $# -eq 0 ]] ; then
+    help # show help
+    exit 0
+fi
 while [[ $# -gt 0 ]]
 do
-    key="$1"
-    case $key in
+    case "$1" in
         -h|--help)
             # Help parametter
-            echo -e "Docker entrypoint script for creating RPM repository\n"
-            echo "-h --help: Show this help"
-            echo "-d --directory: set path for repo directory in container"
-            echo -e "-l --list: set path where rpm list is stored in container\n"
-            echo "Both paths have to be set with shared volume between"
-            echo "container and host computer. Default path in container is: /tmp/"
-            echo "Repository will be created at: /<path>/resources/pkg/rhel/"
-            echo "RMP list is stored at: /<path>/offline-installer/build/data_list/"
-            shift # past argument
-            shift # past value
+            help # show help
             exit
             ;;
         -d|--directory)
             # Directory parametter
             # Sets path where will be created reposity
-            OOM_REPO_DIR="$2"
-            shift # past argument
-            shift # past value
+            OFFLINE_REPO_DIR="$2"
             ;;
         -l|--list)
             # List parametter
             # Sets path where is stored onap_rpm.list file
             RPM_LIST_DIR="$2"
-            shift # past argument
-            shift # past value
             ;;
-        --default)
-            DEFAULT=YES
-            shift # past argument
-            ;;
-        *) 
+        *)
             # unknown option
-            POSITIONAL+=("$1") # save it in an array for later
-            shift # past argument
+            help # show help
+            exit
             ;;
     esac
+    shift;shift
 done
 
 # Testing if directory parametter was used
-# If not variable is sets to default value /tmp/resources/pkg/rhel
-if test -z "$OOM_REPO_DIR"
+# If not variable is sets to default value /tmp/repo/resources/pkg/rhel
+if test -z "$OFFLINE_REPO_DIR"
 then
-    OOM_REPO_DIR="/tmp/resources/pkg/rhel"
+    OFFLINE_REPO_DIR="/tmp/repo/"
 fi
 
 # Testing if list parametter was used
-# If not variable is sets to default value /tmp/data-list
+# If not variable is sets to default value /tmp/offline/data-list
 if test -z "$RPM_LIST_DIR"
 then
-    RPM_LIST_DIR="/tmp/offline-installer/build/data_list/"
+    RPM_LIST_DIR="/tmp/offline/data_list/"
 
 fi
 
-# Create repo folder
-mkdir $OOM_REPO_DIR -p
-
 # Install createrepo package for create repository in folder
 # and yum-utils due to yum-config-manager for adding docker repository
 yum install createrepo yum-utils -y
@@ -78,7 +74,7 @@
 yum-config-manager --add-repo=https://download.docker.com/linux/centos/7/x86_64/stable/
 
 # Download all packages from onap_rpm.list via yumdownloader to repository folder
-for i in $(cat ${RPM_LIST_DIR}onap_rpm.list | awk '{print $1}');do yumdownloader --resolve --downloadonly --destdir=${OOM_REPO_DIR} $i -y; done
+for i in $(cat ${RPM_LIST_DIR}onap_rpm.list | awk '{print $1}');do yumdownloader --resolve --downloadonly --destdir=${OFFLINE_REPO_DIR} $i -y; done
 
 # In repository folder create repository
-createrepo $OOM_REPO_DIR
+createrepo $OFFLINE_REPO_DIR