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