Andy Bavier | b233c7a | 2018-05-24 09:10:50 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # bootstrap-repo.sh |
| 18 | # Downloads CORD source into ~/cord |
| 19 | |
| 20 | set -e -u -o pipefail |
| 21 | |
| 22 | # Location of 'cord' directory checked out on the local system |
| 23 | CORDDIR="${CORDDIR:-${HOME}/cord}" |
| 24 | |
| 25 | # CORD versioning |
| 26 | REPO_BRANCH="${REPO_BRANCH:-master}" |
| 27 | |
| 28 | # Parse options |
| 29 | GERRIT_PATCHES=() |
| 30 | |
| 31 | while getopts "hp:" opt; do |
| 32 | case ${opt} in |
| 33 | h ) echo "Usage for $0:" |
| 34 | echo " -p <project:change/revision> Download a patch from gerrit. Can be repeated." |
| 35 | exit 0 |
| 36 | ;; |
| 37 | p ) GERRIT_PATCHES+=("$OPTARG") |
| 38 | ;; |
| 39 | \? ) echo "Invalid option: -$OPTARG" |
| 40 | exit 1 |
| 41 | ;; |
| 42 | esac |
| 43 | done |
| 44 | |
| 45 | if [ ! -x "/usr/local/bin/repo" ] |
| 46 | then |
| 47 | echo "Installing repo..." |
| 48 | # v1.23, per https://source.android.com/source/downloading |
| 49 | REPO_SHA256SUM="394d93ac7261d59db58afa49bb5f88386fea8518792491ee3db8baab49c3ecda" |
| 50 | curl -o /tmp/repo 'https://gerrit.opencord.org/gitweb?p=repo.git;a=blob_plain;f=repo;hb=refs/heads/stable' |
| 51 | echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c - |
| 52 | sudo mv /tmp/repo /usr/local/bin/repo |
| 53 | sudo chmod a+x /usr/local/bin/repo |
| 54 | fi |
| 55 | |
| 56 | if [ ! -d "$CORDDIR/build" ] |
| 57 | then |
| 58 | # make sure we can find gerrit.opencord.org as DNS failures will fail the build |
| 59 | dig +short gerrit.opencord.org || (echo "ERROR: gerrit.opencord.org can't be looked up in DNS" && exit 1) |
| 60 | |
| 61 | echo "Downloading CORD/XOS, branch:'${REPO_BRANCH}'..." |
| 62 | |
| 63 | if [ ! -e "${HOME}/.gitconfig" ] |
| 64 | then |
| 65 | echo "No ${HOME}/.gitconfig, setting testing defaults" |
| 66 | git config --global user.name 'Test User' |
| 67 | git config --global user.email 'test@null.com' |
| 68 | git config --global color.ui false |
| 69 | fi |
| 70 | |
| 71 | mkdir -p "${CORDDIR}" && cd "${CORDDIR}" |
| 72 | repo init -u https://gerrit.opencord.org/manifest -b "${REPO_BRANCH}" |
| 73 | repo sync |
| 74 | |
| 75 | # download gerrit patches using repo |
| 76 | if [[ ! -z "${GERRIT_PATCHES[*]-}" ]] |
| 77 | then |
| 78 | for gerrit_patch in "${GERRIT_PATCHES[@]-}" |
| 79 | do |
| 80 | echo "Checking out gerrit changeset: '${gerrit_patch}'" |
| 81 | IFS=: read -r gerrit_project gerrit_changeset <<< "${gerrit_patch}" |
| 82 | repo download "${gerrit_project}" "${gerrit_changeset}" |
| 83 | done |
| 84 | fi |
| 85 | fi |