blob: 93c1e118cd583baabad93c7273c9a3533c57801f [file] [log] [blame]
Zack Williams1497a402018-02-16 15:22:42 -07001#!/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# onos-bootstrap.sh
18# Bootstraps repo for ONOS, downloads source
19
20set -e -u -o pipefail
21
22# Use master as default version
23REPO_BRANCH=${REPO_BRANCH:-'master'}
24
25ONOS_REPO_DIR="${CORDDIR:-${HOME}/onosrepo}"
26
27function install_repo() {
28 if [ ! -x "/usr/local/bin/repo" ]
29 then
30 echo "Installing repo..."
31 # v1.23, per https://source.android.com/source/downloading
32 REPO_SHA256SUM="e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5"
33 curl -o /tmp/repo https://storage.googleapis.com/git-repo-downloads/repo
34 echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c -
35 sudo mv /tmp/repo /usr/local/bin/repo
36 sudo chmod a+x /usr/local/bin/repo
37 fi
38}
39
40function checkout_onos() {
41
42 if [ ! -d "$ONOS_REPO_DIR" ]
43 then
44
45 # Create default git config if unconfigured
46 if [ ! -e "${HOME}/.gitconfig" ]
47 then
48 echo "No ${HOME}/.gitconfig, setting testing defaults"
49 git config --global user.name 'Test User'
50 git config --global user.email 'test@null.com'
51 git config --global color.ui false
52 fi
53
54 echo "Checking out ONOS using repo..."
55
56 mkdir -p $ONOS_REPO_DIR && cd $ONOS_REPO_DIR
57 repo init -u https://gerrit.onosproject.org/manifest -b $REPO_BRANCH
58 repo sync
59
60 # check out gerrit branches using repo
61 if [[ ! -z ${GERRIT_PATCHES[@]-} ]]
62 then
63 for gerrit_patch in "${GERRIT_PATCHES[@]-}"
64 do
65 echo "Checking out gerrit changeset: '$gerrit_patch'"
66 repo download ${gerrit_patch/:/ }
67 done
68 fi
69 fi
70}
71
72# Parse options
73GERRIT_PATCHES=()
74
75while getopts "p:h" opt; do
76 case ${opt} in
77 h ) echo "Usage:"
78 echo " $0 download ONOS using repo [default]"
79 echo " $0 -p <project:changeset/revision> checkout patchsetsfrom gerrit. Can"
80 echo " be used multiple times."
81 echo " $0 -h display this help message"
82 ;;
83 p ) GERRIT_PATCHES+=("$OPTARG")
84 ;;
85 \? ) echo "Invalid option: -$OPTARG"
86 exit 1
87 ;;
88 esac
89done
90
91install_repo
92checkout_onos
93