blob: 14f6aaa7378dcc1a9f9caedeb7f24313d945a1bb [file] [log] [blame]
Jan Benedikt7c0f6b12019-10-08 10:01:41 -04001#!/usr/bin/env bash
2
3# Path where will be created repository (in container)
Jan Benedikt8fdbfe72019-10-15 06:07:46 -04004OFFLINE_REPO_DIR=""
Jan Benedikt7c0f6b12019-10-08 10:01:41 -04005
6# Path where is stored onap_rpm.list file
7RPM_LIST_DIR=""
8
Jan Benedikt8fdbfe72019-10-15 06:07:46 -04009help () {
10 echo -e "Docker entrypoint script for creating RPM repository\n"
11 echo "usage: create-repo.sh [-d|--directory output directory] [-l|--list input rpm list directory]"
12 echo "-h --help: Show this help"
13 echo "-d --directory: set path for repo directory in container"
14 echo -e "-l --list: set path where rpm list is stored in container\n"
15 echo "Both paths have to be set with shared volume between"
16 echo "container and host computer. Default path in container is: /tmp/"
Jan Benedikt5907acf2019-10-25 03:35:51 -040017 echo "Repository will be created at: /<path>/resources/pkg/rpm/"
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040018 echo "RMP list is stored at: ./data_list/"
19}
20
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040021# Getting input parametters
22POSITIONAL=()
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040023if [[ $# -eq 0 ]] ; then
24 help # show help
25 exit 0
26fi
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040027while [[ $# -gt 0 ]]
28do
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040029 case "$1" in
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040030 -h|--help)
31 # Help parametter
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040032 help # show help
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040033 exit
34 ;;
35 -d|--directory)
36 # Directory parametter
37 # Sets path where will be created reposity
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040038 OFFLINE_REPO_DIR="$2"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040039 ;;
40 -l|--list)
41 # List parametter
42 # Sets path where is stored onap_rpm.list file
43 RPM_LIST_DIR="$2"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040044 ;;
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040045 *)
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040046 # unknown option
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040047 help # show help
48 exit
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040049 ;;
50 esac
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040051 shift;shift
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040052done
53
54# Testing if directory parametter was used
Jan Benedikt5907acf2019-10-25 03:35:51 -040055# If not variable is sets to default value /tmp/repo/resources/pkg/rpm
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040056if test -z "$OFFLINE_REPO_DIR"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040057then
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040058 OFFLINE_REPO_DIR="/tmp/repo/"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040059fi
60
61# Testing if list parametter was used
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040062# If not variable is sets to default value /tmp/offline/data-list
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040063if test -z "$RPM_LIST_DIR"
64then
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040065 RPM_LIST_DIR="/tmp/offline/data_list/"
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040066
67fi
68
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040069# Install createrepo package for create repository in folder
70# and yum-utils due to yum-config-manager for adding docker repository
71yum install createrepo yum-utils -y
72
73# Add official docker repository
74yum-config-manager --add-repo=https://download.docker.com/linux/centos/7/x86_64/stable/
75
76# Download all packages from onap_rpm.list via yumdownloader to repository folder
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040077for i in $(cat ${RPM_LIST_DIR}onap_rpm.list | awk '{print $1}');do yumdownloader --resolve --downloadonly --destdir=${OFFLINE_REPO_DIR} $i -y; done
Jan Benedikt7c0f6b12019-10-08 10:01:41 -040078
79# In repository folder create repository
Jan Benedikt8fdbfe72019-10-15 06:07:46 -040080createrepo $OFFLINE_REPO_DIR