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