Matteo Scandolo | 3896c47 | 2017-08-01 13:31:42 -0700 | [diff] [blame] | 1 | |
| 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 Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 17 | #!/usr/bin/env bash |
| 18 | # cord-bootstrap.sh |
| 19 | # Bootstraps environment and downloads CORD repos |
| 20 | |
| 21 | set -e |
| 22 | set -x |
| 23 | |
Andy Bavier | 7b90cb8 | 2017-06-22 10:33:00 -0400 | [diff] [blame] | 24 | CORDDIR=/opt/cord |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 25 | |
| 26 | function bootstrap() { |
| 27 | |
| 28 | if [ ! -x "/usr/bin/ansible" ] |
| 29 | then |
| 30 | echo "Installing Ansible..." |
Andy Bavier | ba124b1 | 2017-04-17 12:01:37 -0400 | [diff] [blame] | 31 | sudo apt-get update |
Zack Williams | 0ab8f51 | 2017-06-29 08:41:51 -0700 | [diff] [blame] | 32 | sudo apt-get install -y software-properties-common |
| 33 | sudo apt-add-repository -y ppa:ansible/ansible |
Max Chu | cc3fee4 | 2017-07-05 10:49:09 -0700 | [diff] [blame] | 34 | sudo apt-get update |
Zack Williams | 0ab8f51 | 2017-06-29 08:41:51 -0700 | [diff] [blame] | 35 | sudo apt-get -y install python-dev libffi-dev python-pip libssl-dev sshpass python-netaddr ansible |
Sapan Bhatia | 1996c04 | 2017-06-17 17:46:23 -0700 | [diff] [blame] | 36 | sudo pip install markupsafe |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 37 | 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 Bavier | 79702bc | 2017-06-01 15:43:36 -0400 | [diff] [blame] | 62 | repo init -u https://gerrit.opencord.org/manifest -b master |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 63 | 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 | |
| 88 | function 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 | |
| 99 | function 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 |
| 104 | GERRIT_BRANCHES= |
| 105 | CLEANUP=0 |
| 106 | CORD_PROFILE="" |
| 107 | |
| 108 | while 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 |
| 129 | done |
| 130 | |
| 131 | # "main" function |
| 132 | if [[ $CLEANUP -eq 1 ]] |
| 133 | then |
| 134 | cleanup |
| 135 | fi |
| 136 | |
| 137 | bootstrap |
| 138 | |
| 139 | if [[ $CORD_PROFILE -ne "" ]] |
| 140 | then |
| 141 | set -x |
| 142 | cord_profile |
| 143 | fi |
| 144 | |
| 145 | exit 0 |