Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | container_name="centos_repo" |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 4 | # Path to folder with cloned offline-installer build directory with docker_entrypoint script |
| 5 | volume_offline_directory="$(readlink -f $(dirname ${0}))" |
| 6 | # Path for directory where repository will be created |
| 7 | volume_repo_directory="$(pwd)" |
| 8 | # Path inside container with cloned offline-installer build directory |
| 9 | container_offline_volume="/mnt/offline/" |
| 10 | # Path inside container where will be created repository |
| 11 | container_repo_volume="/mnt/repo/" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 12 | # Docker image name and version |
| 13 | docker_image="centos:centos7.6.1810" |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 14 | # Expected directory for RPM packages |
Jan Benedikt | 5907acf | 2019-10-25 03:35:51 -0400 | [diff] [blame] | 15 | expected_dir="resources/pkg/rpm" |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 16 | |
| 17 | help () { |
| 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 Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 25 | |
| 26 | # Getting input parametters |
| 27 | POSITIONAL=() |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 28 | if [[ $# -eq 0 ]] ; then |
| 29 | help # show help |
| 30 | exit 0 |
| 31 | fi |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 32 | while [[ $# -gt 0 ]] |
| 33 | do |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 34 | case "$1" in |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 35 | -h|--help) |
| 36 | # Help parametter |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 37 | help # show help |
| 38 | exit 0 |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 39 | ;; |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 40 | -c|--cloned-directory) |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 41 | # Directory parametter |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 42 | # Sets path where is cloned offline-installer build directory |
| 43 | volume_offline_directory="$2" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 44 | ;; |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 45 | -d|--destination-repository) |
| 46 | # Repository direcotry parametter |
| 47 | # Sets path where will be repository created |
| 48 | volume_repo_directory="$2" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 49 | ;; |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 50 | *) |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 51 | # unknown option |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 52 | help # show help |
| 53 | exit 1 |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 54 | ;; |
| 55 | esac |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 56 | shift;shift |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 57 | done |
| 58 | |
Jan Benedikt | 5907acf | 2019-10-25 03:35:51 -0400 | [diff] [blame] | 59 | # Check if path contains expected path "resources/pkg/rpm" |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 60 | if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then |
| 61 | # Create repo folder if it not exists |
Jan Benedikt | 5907acf | 2019-10-25 03:35:51 -0400 | [diff] [blame] | 62 | volume_repo_directory="$volume_repo_directory"/resources/pkg/rpm |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 63 | [ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory |
| 64 | fi |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 65 | |
| 66 | #Check if container "centos-repo" is running |
| 67 | if [ ! "$(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 Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 78 | -v ${volume_offline_directory}:${container_offline_volume} \ |
| 79 | -v ${volume_repo_directory}:${container_repo_volume} \ |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 80 | --rm \ |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 81 | --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 Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 86 | fi |