Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Path where will be created repository (in container) |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 4 | OFFLINE_REPO_DIR="" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 5 | |
| 6 | # Path where is stored onap_rpm.list file |
| 7 | RPM_LIST_DIR="" |
| 8 | |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 9 | help () { |
| 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/" |
| 17 | echo "Repository will be created at: /<path>/resources/pkg/rhel/" |
| 18 | echo "RMP list is stored at: ./data_list/" |
| 19 | } |
| 20 | |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 21 | # Getting input parametters |
| 22 | POSITIONAL=() |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 23 | if [[ $# -eq 0 ]] ; then |
| 24 | help # show help |
| 25 | exit 0 |
| 26 | fi |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 27 | while [[ $# -gt 0 ]] |
| 28 | do |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 29 | case "$1" in |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 30 | -h|--help) |
| 31 | # Help parametter |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 32 | help # show help |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 33 | exit |
| 34 | ;; |
| 35 | -d|--directory) |
| 36 | # Directory parametter |
| 37 | # Sets path where will be created reposity |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 38 | OFFLINE_REPO_DIR="$2" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 39 | ;; |
| 40 | -l|--list) |
| 41 | # List parametter |
| 42 | # Sets path where is stored onap_rpm.list file |
| 43 | RPM_LIST_DIR="$2" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 44 | ;; |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 45 | *) |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 46 | # unknown option |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 47 | help # show help |
| 48 | exit |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 49 | ;; |
| 50 | esac |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 51 | shift;shift |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 52 | done |
| 53 | |
| 54 | # Testing if directory parametter was used |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 55 | # If not variable is sets to default value /tmp/repo/resources/pkg/rhel |
| 56 | if test -z "$OFFLINE_REPO_DIR" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 57 | then |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 58 | OFFLINE_REPO_DIR="/tmp/repo/" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 59 | fi |
| 60 | |
| 61 | # Testing if list parametter was used |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 62 | # If not variable is sets to default value /tmp/offline/data-list |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 63 | if test -z "$RPM_LIST_DIR" |
| 64 | then |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 65 | RPM_LIST_DIR="/tmp/offline/data_list/" |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 66 | |
| 67 | fi |
| 68 | |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 69 | # Install createrepo package for create repository in folder |
| 70 | # and yum-utils due to yum-config-manager for adding docker repository |
| 71 | yum install createrepo yum-utils -y |
| 72 | |
| 73 | # Add official docker repository |
| 74 | yum-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 Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 77 | for i in $(cat ${RPM_LIST_DIR}onap_rpm.list | awk '{print $1}');do yumdownloader --resolve --downloadonly --destdir=${OFFLINE_REPO_DIR} $i -y; done |
Jan Benedikt | 7c0f6b1 | 2019-10-08 10:01:41 -0400 | [diff] [blame] | 78 | |
| 79 | # In repository folder create repository |
Jan Benedikt | 8fdbfe7 | 2019-10-15 06:07:46 -0400 | [diff] [blame] | 80 | createrepo $OFFLINE_REPO_DIR |