blob: 8a4e7b8dd8541e7ee09c044355da795b4c7d2577 [file] [log] [blame]
Matteo Scandolo3896c472017-08-01 13:31:42 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Zack Williamsa2763112017-01-03 11:38:38 -070017#!/usr/bin/env bash
18# cord-bootstrap.sh
19# Bootstraps environment and downloads CORD repos
20
21set -e
22set -x
23
Andy Bavier7b90cb82017-06-22 10:33:00 -040024CORDDIR=/opt/cord
Zack Williamsa2763112017-01-03 11:38:38 -070025
26function bootstrap() {
27
28 if [ ! -x "/usr/bin/ansible" ]
29 then
30 echo "Installing Ansible..."
Andy Bavierba124b12017-04-17 12:01:37 -040031 sudo apt-get update
Zack Williams0ab8f512017-06-29 08:41:51 -070032 sudo apt-get install -y software-properties-common
33 sudo apt-add-repository -y ppa:ansible/ansible
Max Chucc3fee42017-07-05 10:49:09 -070034 sudo apt-get update
Zack Williams0ab8f512017-06-29 08:41:51 -070035 sudo apt-get -y install python-dev libffi-dev python-pip libssl-dev sshpass python-netaddr ansible
Sapan Bhatia1996c042017-06-17 17:46:23 -070036 sudo pip install markupsafe
Zack Williamsa2763112017-01-03 11:38:38 -070037 fi
38
39 if [ ! -x "/usr/local/bin/repo" ]
40 then
41 echo "Installing repo..."
42 REPO_SHA256SUM="e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5"
43 curl -o /tmp/repo https://storage.googleapis.com/git-repo-downloads/repo
44 echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c -
45 sudo mv /tmp/repo /usr/local/bin/repo
46 sudo chmod a+x /usr/local/bin/repo
47 fi
48
49 if [ ! -d "$CORDDIR" ]
50 then
51 echo "Downloading CORD/XOS..."
52
53 if [ ! -e "~/.gitconfig" ]
54 then
55 echo "No ~/.gitconfig, setting testing defaults"
56 git config --global user.name 'Test User'
57 git config --global user.email 'test@null.com'
58 git config --global color.ui false
59 fi
60
61 mkdir $CORDDIR && cd $CORDDIR
Andy Bavier79702bc2017-06-01 15:43:36 -040062 repo init -u https://gerrit.opencord.org/manifest -b master
Zack Williamsa2763112017-01-03 11:38:38 -070063 repo sync
64
65 # check out gerrit branches using repo
66 for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
67 echo "checking out opencord gerrit branch: $gerrit_branch"
68 repo download ${gerrit_branch/:/ }
69 done
70 fi
71
72 if [ ! -x "/usr/bin/docker" ]
73 then
74 echo "Installing Devel Tools..."
75 cd ${CORDDIR}/build/platform-install
76 ansible-playbook -i inventory/localhost devel-tools-playbook.yml
77 fi
78
79 set +x
80 echo "*******************************************************************************"
81 echo "* IMPORTANT: Logout and login so your account is added to the docker group! *"
82 echo "* Then 'cd ${CORDDIR}/build/platform-install' and start your CORD profile. *"
83 echo "* Need help? Check out the wiki at: https://wiki.opencord.org/ *"
84 echo "*******************************************************************************"
85
86}
87
88function cleanup() {
89 if [ ! -x "/usr/bin/ansible" ]
90 then
91 echo "Ansible not installed, can't cleanup. Is this the initial run?"
92 else
93 echo "Cleaning up - destroying docker containers..."
94 cd ${CORDDIR}/build/platform-install
95 ansible-playbook -i inventory/localhost teardown-playbook.yaml
96 fi
97}
98
99function cord_profile() {
100 echo "Running a profile is broken due to docker group membership issue"
101}
102
103# options that may be set by getopt
104GERRIT_BRANCHES=
105CLEANUP=0
106CORD_PROFILE=""
107
108while getopts "b:hcp:" opt; do
109 case ${opt} in
110 b ) GERRIT_BRANCHES+=("$OPTARG")
111 ;;
112 c ) CLEANUP=1
113 ;;
114 h ) echo "Usage:"
115 echo " $0 prep system to run a CORD profile"
116 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
117 echo " be used multiple times."
118 echo " $0 -c cleanup from previous test"
119 echo " $0 -p <profile> prep then start running the specified profile"
120 echo " $0 -h display this help message"
121 exit 0
122 ;;
123 p ) CORD_PROFILE=$OPTARG
124 ;;
125 \? ) echo "Invalid option: -$OPTARG"
126 exit 1
127 ;;
128 esac
129done
130
131# "main" function
132if [[ $CLEANUP -eq 1 ]]
133then
134 cleanup
135fi
136
137bootstrap
138
139if [[ $CORD_PROFILE -ne "" ]]
140then
141 set -x
142 cord_profile
143fi
144
145exit 0