summaryrefslogtreecommitdiffstats
path: root/build/create_repo.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build/create_repo.sh')
-rwxr-xr-xbuild/create_repo.sh78
1 files changed, 65 insertions, 13 deletions
diff --git a/build/create_repo.sh b/build/create_repo.sh
index eaf0ee30..4403a4e3 100755
--- a/build/create_repo.sh
+++ b/build/create_repo.sh
@@ -1,34 +1,63 @@
#!/usr/bin/env bash
-container_name="centos_repo"
+# Set type of distribution
+distro_type="$(cat /etc/*-release | grep -w "ID" | awk -F'=' '{ print $2 }' | tr -d '"')"
+
# 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/rpm"
+# Show help for using this script
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 "Script for run docker container creating DEB or RPM repository"
+ echo "Type of repository is created based on user input or if input is empty type of host OS"
+ echo "usage: create_repo.sh [-d|--destination-repository output directory] [-c|--cloned-directory input directory] [-t|--target-platform (ubuntu/rhel/centos) target platform for repository]"
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 "-t --target-platform: set target platform for repository"
echo "If build folder from offline repository is not specified will be used default path of current folder."
}
+# Get type of distribution
+# Set Docker image name and version based on type of linux distribution
+# Set expected directory for RPM/DEB packages
+set_enviroment () {
+ case "$1" in
+ ubuntu)
+ distro_type="ubuntu"
+ docker_image="ubuntu:18.04"
+ expected_dir="resources/pkg/deb"
+ container_name=$1"_repo"
+ ;;
+ centos|rhel)
+ distro_type="rhel"
+ docker_image="centos:centos7.6.1810"
+ expected_dir="resources/pkg/rpm"
+ container_name=$1"_repo"
+ ;;
+ *)
+ echo "Unknown type of linux distribution."
+ exit 1
+ ;;
+ esac
+}
+
# Getting input parametters
POSITIONAL=()
if [[ $# -eq 0 ]] ; then
help # show help
exit 0
fi
+
while [[ $# -gt 0 ]]
do
case "$1" in
@@ -47,6 +76,11 @@ do
# Sets path where will be repository created
volume_repo_directory="$2"
;;
+ -t|--type)
+ # Repository type (rpm/deb)
+ # Sets target platform for repository
+ target_input="$2"
+ ;;
*)
# unknown option
help # show help
@@ -56,10 +90,28 @@ do
shift;shift
done
-# Check if path contains expected path "resources/pkg/rpm"
+# Check if user specified type of repository
+# This settings have higher priority, then type of distribution
+if ! test -z "$target_input"
+then
+ set_enviroment "$target_input"
+else
+ set_enviroment "$distro_type"
+fi
+
+# Check if path contains expected path:
+# "resources/pkg/rpm" for Rhel/CentOS or
+# "resources/pkg/deb" for Ubuntu/Debian
if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then
# Create repo folder if it not exists
- volume_repo_directory="$volume_repo_directory"/resources/pkg/rpm
+ case "$distro_type" in
+ ubuntu)
+ volume_repo_directory="$volume_repo_directory"/resources/pkg/deb
+ ;;
+ rhel)
+ volume_repo_directory="$volume_repo_directory"/resources/pkg/rhel
+ ;;
+ esac
[ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory
fi
@@ -79,8 +131,8 @@ if [ ! "$(docker ps -q -f name=$container_name)" ]; then
-v ${volume_repo_directory}:${container_repo_volume} \
--rm \
--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
+ -it ${docker_image} \
+ --directory ${container_repo_volume} \
+ --list ${container_offline_volume}data_lists/
+ docker logs $(docker ps --filter "name=${container_name}" --format '{{.ID}}' -a) -f
fi