Tomáš Levora | ade405a | 2019-01-29 14:25:04 +0100 | [diff] [blame] | 1 | #! /usr/bin/env bash |
Piotr Perzanowski | 2d8d165 | 2018-12-18 13:53:35 +0100 | [diff] [blame] | 2 | # COPYRIGHT NOTICE STARTS HERE |
| 3 | # |
| 4 | # Copyright 2018 © Samsung Electronics Co., Ltd. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # COPYRIGHT NOTICE ENDS HERE |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 19 | |
Tomáš Levora | ade405a | 2019-01-29 14:25:04 +0100 | [diff] [blame] | 20 | # fail fast |
| 21 | set -e |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 22 | |
Tomáš Levora | ade405a | 2019-01-29 14:25:04 +0100 | [diff] [blame] | 23 | usage () { |
| 24 | echo "Usage:" |
| 25 | echo -e "./$(basename $0) <repository list> [destination directory]\n" |
| 26 | echo "Examples:" |
| 27 | echo " ./$(basename $0) onap_3.0.0 ./git-repo" |
| 28 | } |
| 29 | |
| 30 | LIST="${1}" |
| 31 | |
| 32 | if [[ -z "${LIST}" ]]; then |
| 33 | echo "Missing argument for repository list" |
Piotr Perzanowski | 2d8d165 | 2018-12-18 13:53:35 +0100 | [diff] [blame] | 34 | exit 1 |
| 35 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 36 | |
Tomáš Levora | ade405a | 2019-01-29 14:25:04 +0100 | [diff] [blame] | 37 | OUTDIR="${2}" |
| 38 | if [[ -z "${OUTDIR}" ]]; then |
| 39 | OUTDIR="./git-repo" |
Piotr Perzanowski | 2d8d165 | 2018-12-18 13:53:35 +0100 | [diff] [blame] | 40 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 41 | |
Tomáš Levora | ade405a | 2019-01-29 14:25:04 +0100 | [diff] [blame] | 42 | mkdir -p "${OUTDIR}" |
| 43 | cd "${OUTDIR}" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 44 | |
Tomáš Levora | ade405a | 2019-01-29 14:25:04 +0100 | [diff] [blame] | 45 | |
| 46 | while IFS=" " read -r REPO BRANCH remainder |
| 47 | do |
| 48 | if [[ -z "${BRANCH}" ]]; then |
| 49 | git clone https://${REPO} --bare ${REPO} |
| 50 | else |
| 51 | git clone -b ${BRANCH} --single-branch https://${REPO} --bare ${REPO} |
| 52 | fi |
| 53 | done < <(awk '$1 ~ /^[^;#]/' ${LIST}) |
| 54 | |
| 55 | |
| 56 | exit 0 |