blob: 1ecc7321d552f7a64711f2ea4d36434e5893ec1d [file] [log] [blame]
Zack Williamsa2763112017-01-03 11:38:38 -07001#!/usr/bin/env bash
2# cord-bootstrap.sh
3# Bootstraps environment and downloads CORD repos
4
5set -e
6set -x
7
8CORDDIR=~/cord
9
10function bootstrap() {
11
12 if [ ! -x "/usr/bin/ansible" ]
13 then
14 echo "Installing Ansible..."
15 sudo apt-get update
16 sudo apt-get install -y software-properties-common
17 sudo apt-add-repository -y ppa:ansible/ansible
18 sudo apt-get update
19 sudo apt-get install -y ansible python-netaddr
20 fi
21
22 if [ ! -x "/usr/local/bin/repo" ]
23 then
24 echo "Installing repo..."
25 REPO_SHA256SUM="e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5"
26 curl -o /tmp/repo https://storage.googleapis.com/git-repo-downloads/repo
27 echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c -
28 sudo mv /tmp/repo /usr/local/bin/repo
29 sudo chmod a+x /usr/local/bin/repo
30 fi
31
32 if [ ! -d "$CORDDIR" ]
33 then
34 echo "Downloading CORD/XOS..."
35
36 if [ ! -e "~/.gitconfig" ]
37 then
38 echo "No ~/.gitconfig, setting testing defaults"
39 git config --global user.name 'Test User'
40 git config --global user.email 'test@null.com'
41 git config --global color.ui false
42 fi
43
44 mkdir $CORDDIR && cd $CORDDIR
Zack Williamsc16596d2017-02-15 17:40:28 -070045 repo init -u https://gerrit.opencord.org/manifest -b master -g build,onos,orchestration,voltha
Zack Williamsa2763112017-01-03 11:38:38 -070046 repo sync
47
48 # check out gerrit branches using repo
49 for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
50 echo "checking out opencord gerrit branch: $gerrit_branch"
51 repo download ${gerrit_branch/:/ }
52 done
53 fi
54
55 if [ ! -x "/usr/bin/docker" ]
56 then
57 echo "Installing Devel Tools..."
58 cd ${CORDDIR}/build/platform-install
59 ansible-playbook -i inventory/localhost devel-tools-playbook.yml
60 fi
61
62 set +x
63 echo "*******************************************************************************"
64 echo "* IMPORTANT: Logout and login so your account is added to the docker group! *"
65 echo "* Then 'cd ${CORDDIR}/build/platform-install' and start your CORD profile. *"
66 echo "* Need help? Check out the wiki at: https://wiki.opencord.org/ *"
67 echo "*******************************************************************************"
68
69}
70
71function cleanup() {
72 if [ ! -x "/usr/bin/ansible" ]
73 then
74 echo "Ansible not installed, can't cleanup. Is this the initial run?"
75 else
76 echo "Cleaning up - destroying docker containers..."
77 cd ${CORDDIR}/build/platform-install
78 ansible-playbook -i inventory/localhost teardown-playbook.yaml
79 fi
80}
81
82function cord_profile() {
83 echo "Running a profile is broken due to docker group membership issue"
84}
85
86# options that may be set by getopt
87GERRIT_BRANCHES=
88CLEANUP=0
89CORD_PROFILE=""
90
91while getopts "b:hcp:" opt; do
92 case ${opt} in
93 b ) GERRIT_BRANCHES+=("$OPTARG")
94 ;;
95 c ) CLEANUP=1
96 ;;
97 h ) echo "Usage:"
98 echo " $0 prep system to run a CORD profile"
99 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
100 echo " be used multiple times."
101 echo " $0 -c cleanup from previous test"
102 echo " $0 -p <profile> prep then start running the specified profile"
103 echo " $0 -h display this help message"
104 exit 0
105 ;;
106 p ) CORD_PROFILE=$OPTARG
107 ;;
108 \? ) echo "Invalid option: -$OPTARG"
109 exit 1
110 ;;
111 esac
112done
113
114# "main" function
115if [[ $CLEANUP -eq 1 ]]
116then
117 cleanup
118fi
119
120bootstrap
121
122if [[ $CORD_PROFILE -ne "" ]]
123then
124 set -x
125 cord_profile
126fi
127
128exit 0