3 # Set distribution type
4 distro_type="$(cat /etc/*-release | grep -w "ID" | awk -F'=' '{ print $2 }' | tr -d '"')"
6 # Path to cloned offline-installer build directory with docker_entrypoint script
7 volume_offline_directory="$(readlink -f $(dirname ${0}))"
9 # Destination path for created repository
10 volume_repo_directory="$(pwd)"
12 # Path inside container with cloned offline-installer build directory
13 container_offline_volume="/mnt/offline/"
15 # Target repository path inside container
16 container_repo_volume="/mnt/repo/"
18 # Additional packages lists files path within container
19 container_list_volume="/mnt/additional-lists/"
21 # Use cache by default
27 Wrapper script running docker container for creating package repository
29 Repository type is set with --target-platform option and the default is to use host OS platform type
31 usage: create_repo.sh [OPTION]...
34 -d | --destination-repository target path to store downloaded packages. Current directory by default
35 -c | --cloned-directory path to directory containing this and docker-entrypoint scripts (offline-installer/build directory)
36 Set it only when you want to use different script/datalists
37 -t | --target-platform target repository platform type (ubuntu/rhel/centos)
38 -a | --additional-list additional packages list; can be used multiple times for more additional lists
39 -n | --container-name-suffix add custom suffix to docker container name
40 -r | --drop-cache remove cached packages (use package cache by default)
41 -h | --help show this help
43 If build folder from offline repository is not specified current one will be used by default.
47 # Get distribution type
48 # Set Docker image name and version based on type of linux distribution
49 # Set expected directory for RPM/DEB packages
54 docker_image="ubuntu:18.04"
55 expected_dir="resources/pkg/deb"
56 container_name="${1}_repo${container_name_suffix}"
60 docker_image="centos:centos7.9.2009"
61 expected_dir="resources/pkg/rpm"
62 container_name="${1}_repo${container_name_suffix}"
65 echo "Unknown type of linux distribution."
71 # Getting input parametters
72 if [[ $# -eq 0 ]] ; then
85 -c|--cloned-directory)
87 # Set path to offline-installer build directory
88 volume_offline_directory="$2"
91 -d|--destination-repository)
92 # Repository directory parameter
93 # Set destination path for created repository
94 volume_repo_directory="$2"
98 # Repository type (rpm/deb)
99 # Set target platform for repository
103 -a|--additional-list)
104 # Array of additional packages lists
105 additional_lists+=("$2")
108 -n|--container-name-suffix)
109 # Set custom container name suffix
110 container_name_suffix="_${2}"
114 # Set flag to clean cache
126 # Check if user specified repository type
127 # This setting has higher priority than distribution type
128 if ! test -z "$target_input"
130 set_environment "$target_input"
132 set_environment "$distro_type"
135 # Check if path contains expected components:
136 # "resources/pkg/rpm" for Rhel/CentOS or
137 # "resources/pkg/deb" for Ubuntu/Debian
138 if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then
139 # Create repo folder if it doesn't exist
140 case "$distro_type" in
142 volume_repo_directory="$volume_repo_directory"/resources/pkg/deb
145 volume_repo_directory="$volume_repo_directory"/resources/pkg/rpm
148 [ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory
151 # Check if container is already running
152 if [ ! $(docker ps -q -f name="^${container_name}$") ];
155 # name of container $container_name
156 # docker entrypoint script from mounted volume
157 # with dynamic parameters
158 # mount additional packages lists to container
161 param_array+=(--directory ${container_repo_volume})
162 param_array+=(--list ${container_offline_volume}data_lists/)
163 param_array+=(--packages-lists-path ${container_list_volume})
166 param_array+=(--drop-cache)
168 [[ ! ${#additional_lists[@]} -eq 0 ]] && \
169 for array_list in "${additional_lists[@]}";
171 param_array+=(--additional-list "${array_list##*/}") && \
172 mounted_lists+=(-v ${array_list}:${container_list_volume}${array_list##*/})
175 docker run --name $container_name \
176 -v ${volume_offline_directory}:${container_offline_volume} \
177 -v ${volume_repo_directory}:${container_repo_volume} \
178 "${mounted_lists[@]}" \
180 --entrypoint="${container_offline_volume}docker-entrypoint.sh" \