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/"
24 Wrapper script running docker container for creating package repository
26 Repository type is set with --target-platform option and the default is to use host OS platform type
28 usage: create_repo.sh [OPTION]...
31 -d | --destination-repository target path to store downloaded packages. Current directory by default
32 -c | --cloned-directory path to directory containing this and docker-entrypoint scripts (offline-installer/build directory)
33 Set it only when you want to use different script/datalists
34 -t | --target-platform target repository platform type (ubuntu/rhel/centos)
35 -a | --additional-list additional packages list; can be used multiple times for more additional lists
36 -n | --container-name-suffix add custom suffix to docker container name
37 -h | --help show this help
39 If build folder from offline repository is not specified current one will be used by default.
43 # Get distribution type
44 # Set Docker image name and version based on type of linux distribution
45 # Set expected directory for RPM/DEB packages
50 docker_image="ubuntu:18.04"
51 expected_dir="resources/pkg/deb"
52 container_name="${1}_repo${container_name_suffix}"
56 docker_image="centos:centos7.6.1810"
57 expected_dir="resources/pkg/rpm"
58 container_name="${1}_repo${container_name_suffix}"
61 echo "Unknown type of linux distribution."
67 # Getting input parametters
68 if [[ $# -eq 0 ]] ; then
81 -c|--cloned-directory)
83 # Set path to offline-installer build directory
84 volume_offline_directory="$2"
86 -d|--destination-repository)
87 # Repository directory parameter
88 # Set destination path for created repository
89 volume_repo_directory="$2"
92 # Repository type (rpm/deb)
93 # Set target platform for repository
97 # Array of additional packages lists
98 additional_lists+=("$2")
100 -n|--container-name-suffix)
101 # Set custom container name suffix
102 container_name_suffix="_${2}"
113 # Check if user specified repository type
114 # This setting has higher priority than distribution type
115 if ! test -z "$target_input"
117 set_environment "$target_input"
119 set_environment "$distro_type"
122 # Check if path contains expected components:
123 # "resources/pkg/rpm" for Rhel/CentOS or
124 # "resources/pkg/deb" for Ubuntu/Debian
125 if ! [[ "/$volume_repo_directory/" = *"/$expected_dir/"* ]]; then
126 # Create repo folder if it doesn't exist
127 case "$distro_type" in
129 volume_repo_directory="$volume_repo_directory"/resources/pkg/deb
132 volume_repo_directory="$volume_repo_directory"/resources/pkg/rpm
135 [ ! -d "$volume_repo_directory" ] && mkdir -p $volume_repo_directory
138 # Check if container is already running
139 if [ ! $(docker ps -q -f name="^${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