3 # Set type of distribution
4 distro_type="$(cat /etc/*-release | grep -w "ID" | awk -F'=' '{ print $2 }' | tr -d '"')"
6 # Path to folder with cloned offline-installer build directory with docker_entrypoint script
7 volume_offline_directory="$(readlink -f $(dirname ${0}))"
9 # Path for directory where repository will be created
10 volume_repo_directory="$(pwd)"
12 # Path inside container with cloned offline-installer build directory
13 container_offline_volume="/mnt/offline/"
15 # Path inside container where will be created repository
16 container_repo_volume="/mnt/repo/"
18 # Path inside container where will be stored additional packages lists
19 container_list_volume="/mnt/additional-lists/"
21 # Show help for using this script
24 Script for run docker container creating DEB or RPM repository
26 Type of repository is created based on user input or if input is empty type of host OS
28 usage: create_repo.sh [-d|--destination-repository output directory] [-c|--cloned-directory input directory]
29 [-t|--target-platform centos target platform for repository]
30 [-a|----additional-lists path to additional package list]
31 -h --help: Show this help
32 -d --destination-repository: set path where will be stored RPM packages. Default value is current directory
33 -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
34 -t --target-platform: set target platform for repository (ubuntu/rhel/centos)
35 -a --additional-list: add additional packages list
36 can be used multiple times for more additional lists
38 If build folder from offline repository is not specified will be used default path of current folder.
42 # Get type of distribution
43 # Set Docker image name and version based on type of linux distribution
44 # Set expected directory for RPM/DEB packages
49 docker_image="ubuntu:18.04"
50 expected_dir="resources/pkg/deb"
51 container_name=$1"_repo"
55 docker_image="centos:centos7.6.1810"
56 expected_dir="resources/pkg/rpm"
57 container_name=$1"_repo"
60 echo "Unknown type of linux distribution."
66 # Getting input parametters
68 if [[ $# -eq 0 ]] ; then
81 -c|--cloned-directory)
82 # Directory parametter
83 # Sets path where is cloned offline-installer build directory
84 volume_offline_directory="$2"
86 -d|--destination-repository)
87 # Repository direcotry parametter
88 # Sets path where will be repository created
89 volume_repo_directory="$2"
92 # Repository type (rpm/deb)
93 # Sets target platform for repository
97 # Array with more packages lists
98 # Add more packages lists to download
99 additional_lists+=("$2")
110 # Check if user specified type of repository
111 # This settings have higher priority, then type of distribution
112 if ! test -z "$target_input"
114 set_enviroment "$target_input"
116 set_enviroment "$distro_type"
119 # Check if path contains expected path:
120 # "resources/pkg/rpm" for Rhel/CentOS or
121 # "resources/pkg/deb" for Ubuntu/Debian
122 if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then
123 # Create repo folder if it not exists
124 case "$distro_type" in
126 volume_repo_directory="$volume_repo_directory"/resources/pkg/deb
129 volume_repo_directory="$volume_repo_directory"/resources/pkg/rhel
132 [ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory
135 #Check if container "centos-repo" is running
136 if [ ! "$(docker ps -q -f name=$container_name)" ]; then
137 if [ "$(docker ps -aq -f status=exited -f name=$container_name)" ]; then
139 docker rm $container_name
142 # name of container $container_name
143 # docker entrypoint script from mounted volume
144 # with dynamic parameters
145 # mount additional packages lists to container
148 param_array+=(--directory ${container_repo_volume})
149 param_array+=(--list ${container_offline_volume}data_lists/)
150 param_array+=(--packages-lists-path ${container_list_volume})
151 [[ ! ${#additional_lists[@]} -eq 0 ]] && \
152 for array_list in "${additional_lists[@]}";
154 param_array+=(--additional-list "${array_list##*/}") && \
155 mounted_lists+=(-v ${array_list}:${container_list_volume}${array_list##*/})
159 --name $container_name \
160 -v ${volume_offline_directory}:${container_offline_volume} \
161 -v ${volume_repo_directory}:${container_repo_volume} \
162 "${mounted_lists[@]}" \
164 --entrypoint="${container_offline_volume}docker-entrypoint.sh" \
165 -it ${docker_image} \
167 docker logs $(docker ps --filter "name=${container_name}" --format '{{.ID}}' -a) -f