5 # Set distribution family
6 distro_type=$(cat /etc/*-release | grep -w "ID" | awk -F'=' '{ print $2 }' | tr -d '"')
15 echo "Unknown type of linux distribution."
20 # Target path for created repository
23 # Path to directory containing onap_rpm.list and onap_deb.list files
26 # Path to additional packages lists
29 # Use cache by default
35 Docker entrypoint script for creating RPM/DEB repository based on container platform type
37 usage: create-repo.sh [OPTION]...
39 -d | --directory target repository path
40 -l | --list input rpm/deb list directory
41 -a | --additional-list additional packages list; can be used multiple times
42 -p | --packages-lists-path other additional packages lists
43 -r | --drop-cache remove cached packages (use package cache by default)
44 -h | --help show this help
46 Both paths have to be set with shared volume between
47 container and the host. Default path in container is: /tmp/
48 Repository will be created at: /<path>/resources/pkg/rhel/
49 RMP/DEB list is stored at: ./data_list/
53 # Getting input parameters
54 if [[ $# -eq 0 ]] ; then
68 # Set target reposity path
74 # Set path containing onap_rpm.list or onap_deb.list file
78 -p|--packages-lists-path)
80 # Set path for additional packages lists
85 # Array of additional packages lists
86 ADDITIONAL_LISTS+=("$2")
90 # Set flag to clean cache
102 # Testing if directory parameter was used
103 # If not variable is set to /tmp/repo by default
104 if test -z "$OFFLINE_REPO_DIR"
106 OFFLINE_REPO_DIR="/tmp/repo/"
109 # Testing if list parameter was used
110 # If not variable is set to default value /tmp/offline/data-list
111 if test -z "$PCKG_LIST_DIR"
113 PCKG_LIST_DIR="/tmp/offline/data_list"
116 # Testing if additional packages list parameter was used
117 # If not variable is set to default value /tmp/additional-lists
118 if test -z "$PCKG_LIST_DIR"
120 PCKG_LIST_DIR="/tmp/additional-lists"
123 # Clean target repo dir if --drop-cache set
126 rm -rf ${OFFLINE_REPO_DIR}/*
129 case "$distro_type" in
131 # Change current working dir
132 pushd $OFFLINE_REPO_DIR
134 # Install dpkg-deb package for create repository in folder
135 # Install software-properties-common to get add-apt-repository command
136 # Install apt-transport-https, ca-certificates, curl and gnupg-agent allowing apt to use a repository over HTTPS
138 apt-get install dpkg-dev apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
140 # Add Docker's official GPG key:
141 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
142 apt-key fingerprint 0EBFCD88
144 # Add docker repository
145 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
147 # Temp fix of known bug
148 # https://bugs.launchpad.net/ubuntu/+source/aptitude/+bug/1543280
149 chown _apt $OFFLINE_REPO_DIR
151 # Create tmp file for package list
154 # Enumerate packages that are already downloaded
155 for package in $(cat ${PCKG_LIST_DIR}/onap_deb.list);
157 # If package name contains explicit version info cut the version string off for further processing
158 p=$(echo $package |sed -r 's/=.*//')
159 # Add package to download list only if it's not already there
160 if [ $(ls ${p}_*.deb 2>/dev/null | wc -l) -eq 0 ];
162 echo ${package} >> ${list_file}
166 # Download all packages via apt-get to repository folder
167 for i in $(cat ${list_file});do apt-get download $i -y; done
168 for i in $(cat ${list_file});
170 for depends in $(apt-cache depends $i | grep -E 'Depends' | grep -v 'Depends:.*>$' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/);
172 apt-get download $depends -y;
176 # Download all packages with dependencies from all additional packages lists via apt-get to repository folder
177 if ! [ ${#ADDITIONAL_LISTS[@]} -eq 0 ]; then
178 for list in ${ADDITIONAL_LISTS[@]}
181 # Create tmp file for package list
184 # Enumerate packages that are already downloaded
185 for package in $(cat ${ADD_LIST_DIR}/${list});
187 # If package name contains explicit version info cut the version string off for further processing
188 p=$(echo $package |sed -r 's/=.*//')
189 # Add package to download list only if it's not already there
190 if [ $(ls ${p}_*.deb 2>/dev/null | wc -l) -eq 0 ];
192 echo ${package} >> ${list_file}
196 for i in $(cat ${list_file});do apt-get download $i -y; done
197 for i in $(cat ${list_file});
199 for depends in $(apt-cache depends $i | grep -E 'Depends' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/);
200 do apt-get download $depends -y;
206 # In repository folder create gz package with deb packages
207 dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
211 # Install createrepo package for create repository in folder,
212 # yum-utils due to yum-config-manager for adding docker repository
213 # and epel-release for additional packages (like jq etc.)
214 yum install createrepo yum-utils epel-release -y
216 # Add official docker repository
217 yum-config-manager --add-repo=https://download.docker.com/linux/centos/7/x86_64/stable/
219 # Create tmp file for package list
222 # Enumerate packages that are already downloaded
223 for package in $(cat ${PCKG_LIST_DIR}/onap_rpm.list);
225 # Add package to download list only if it's not already there
226 if [ ! -f ${OFFLINE_REPO_DIR}/${package}.rpm ];
228 echo ${package} >> ${list_file}
232 # Download all packages from onap_rpm.list via yumdownloader to repository folder
233 for i in $(cat ${list_file});do yumdownloader --resolve --downloadonly --destdir=${OFFLINE_REPO_DIR} $i -y; done
235 # Download all packages from all additional packages lists via yumdownloader to repository folder
236 if ! [ ${#ADDITIONAL_LISTS[@]} -eq 0 ]; then
237 for list in ${ADDITIONAL_LISTS[@]}
239 # Create tmp file for additional package list
241 # Enumerate packages that are already downloaded
242 for package in $(cat ${ADD_LIST_DIR}/${list});
244 # Add package to download list only if it's not already there
245 if [ ! -f ${OFFLINE_REPO_DIR}/${package}.rpm ];
247 echo ${package} >> ${list_file}
251 for i in $(cat ${list_file});
253 yumdownloader --resolve --downloadonly --destdir=${OFFLINE_REPO_DIR} $i -y
259 createrepo $OFFLINE_REPO_DIR
263 echo "Unknown type of linux distribution."