| #!/usr/bin/env bash |
| # |
| # Copyright 2017-present Open Networking Foundation |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # onos-bootstrap.sh |
| # Bootstraps repo for ONOS, downloads source |
| |
| set -e -u -o pipefail |
| |
| # Use master as default version |
| REPO_BRANCH=${REPO_BRANCH:-'master'} |
| |
| ONOS_REPO_DIR="${CORDDIR:-${HOME}/onosrepo}" |
| |
| function install_repo() { |
| if [ ! -x "/usr/local/bin/repo" ] |
| then |
| echo "Installing repo..." |
| # v1.23, per https://source.android.com/source/downloading |
| REPO_SHA256SUM="e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5" |
| curl -o /tmp/repo https://storage.googleapis.com/git-repo-downloads/repo |
| echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c - |
| sudo mv /tmp/repo /usr/local/bin/repo |
| sudo chmod a+x /usr/local/bin/repo |
| fi |
| } |
| |
| function checkout_onos() { |
| |
| if [ ! -d "$ONOS_REPO_DIR" ] |
| then |
| |
| # Create default git config if unconfigured |
| if [ ! -e "${HOME}/.gitconfig" ] |
| then |
| echo "No ${HOME}/.gitconfig, setting testing defaults" |
| git config --global user.name 'Test User' |
| git config --global user.email 'test@null.com' |
| git config --global color.ui false |
| fi |
| |
| echo "Checking out ONOS using repo..." |
| |
| mkdir -p $ONOS_REPO_DIR && cd $ONOS_REPO_DIR |
| repo init -u https://gerrit.onosproject.org/manifest -b $REPO_BRANCH |
| repo sync |
| |
| # check out gerrit branches using repo |
| if [[ ! -z ${GERRIT_PATCHES[@]-} ]] |
| then |
| for gerrit_patch in "${GERRIT_PATCHES[@]-}" |
| do |
| echo "Checking out gerrit changeset: '$gerrit_patch'" |
| repo download ${gerrit_patch/:/ } |
| done |
| fi |
| fi |
| } |
| |
| # Parse options |
| GERRIT_PATCHES=() |
| |
| while getopts "p:h" opt; do |
| case ${opt} in |
| h ) echo "Usage:" |
| echo " $0 download ONOS using repo [default]" |
| echo " $0 -p <project:changeset/revision> checkout patchsetsfrom gerrit. Can" |
| echo " be used multiple times." |
| echo " $0 -h display this help message" |
| ;; |
| p ) GERRIT_PATCHES+=("$OPTARG") |
| ;; |
| \? ) echo "Invalid option: -$OPTARG" |
| exit 1 |
| ;; |
| esac |
| done |
| |
| install_repo |
| checkout_onos |
| |