blob: eaf0ee30d44e752aacde153177fbb668650a6731 [file] [log] [blame]
Jan Benedikt7c0f6b12019-10-08 10:01:41 -04001#!/usr/bin/env bash
2
3container_name="centos_repo"
Jan Benedikt8fdbfe72019-10-15 06:07:46 -04004# Path to folder with cloned offline-installer build directory with docker_entrypoint script
5volume_offline_directory="$(readlink -f $(dirname ${0}))"
6# Path for directory where repository will be created
7volume_repo_directory="$(pwd)"
8# Path inside container with cloned offline-installer build directory
9container_offline_volume="/mnt/offline/"
10# Path inside container where will be created repository
11container_repo_volume="/mnt/repo/"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040012# Docker image name and version
13docker_image="centos:centos7.6.1810"
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040014# Expected directory for RPM packages
Jan Benedikt5907acf2019-10-25 03:35:51 -040015expected_dir="resources/pkg/rpm"
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040016
17help () {
18 echo "Script for run docker container with RPM repository"
19 echo "usage: create_repo.sh [-d|--destination-repository output directory] [-c|--cloned-directory input directory]"
20 echo "-h --help: Show this help"
21 echo "-d --destination-repository: set path where will be stored RPM packages. Default value is current directory"
22 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"
23 echo "If build folder from offline repository is not specified will be used default path of current folder."
24}
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040025
26# Getting input parametters
27POSITIONAL=()
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040028if [[ $# -eq 0 ]] ; then
29 help # show help
30 exit 0
31fi
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040032while [[ $# -gt 0 ]]
33do
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040034 case "$1" in
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040035 -h|--help)
36 # Help parametter
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040037 help # show help
38 exit 0
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040039 ;;
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040040 -c|--cloned-directory)
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040041 # Directory parametter
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040042 # Sets path where is cloned offline-installer build directory
43 volume_offline_directory="$2"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040044 ;;
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040045 -d|--destination-repository)
46 # Repository direcotry parametter
47 # Sets path where will be repository created
48 volume_repo_directory="$2"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040049 ;;
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040050 *)
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040051 # unknown option
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040052 help # show help
53 exit 1
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040054 ;;
55 esac
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040056 shift;shift
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040057done
58
Jan Benedikt5907acf2019-10-25 03:35:51 -040059# Check if path contains expected path "resources/pkg/rpm"
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040060if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then
61 # Create repo folder if it not exists
Jan Benedikt5907acf2019-10-25 03:35:51 -040062 volume_repo_directory="$volume_repo_directory"/resources/pkg/rpm
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040063 [ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory
64fi
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040065
66#Check if container "centos-repo" is running
67if [ ! "$(docker ps -q -f name=$container_name)" ]; then
68 if [ "$(docker ps -aq -f status=exited -f name=$container_name)" ]; then
69 # cleanup
70 docker rm $container_name
71 fi
72 # run repo container
73 # name of container $container_name
74 # docker entrypoint script from mounted volume
75 #
76 docker run -d \
77 --name $container_name \
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040078 -v ${volume_offline_directory}:${container_offline_volume} \
79 -v ${volume_repo_directory}:${container_repo_volume} \
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040080 --rm \
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040081 --entrypoint="${container_offline_volume}docker-entrypoint.sh" \
82 -it ${docker_image} \
83 --directory ${container_repo_volume} \
84 --list ${container_offline_volume}data_lists/
85 docker logs $(docker ps --filter "name=centos_repo" --format '{{.ID}}' -a) -f
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040086fi