Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # cord-bootstrap.sh |
| 3 | # Bootstraps environment and downloads CORD repos |
| 4 | |
| 5 | set -e |
| 6 | set -x |
| 7 | |
Andy Bavier | 7b90cb8 | 2017-06-22 10:33:00 -0400 | [diff] [blame] | 8 | CORDDIR=/opt/cord |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 9 | |
| 10 | function bootstrap() { |
| 11 | |
| 12 | if [ ! -x "/usr/bin/ansible" ] |
| 13 | then |
| 14 | echo "Installing Ansible..." |
Andy Bavier | ba124b1 | 2017-04-17 12:01:37 -0400 | [diff] [blame] | 15 | sudo apt-get update |
Zack Williams | 0ab8f51 | 2017-06-29 08:41:51 -0700 | [diff] [blame^] | 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 python-netaddr ansible |
Sapan Bhatia | 1996c04 | 2017-06-17 17:46:23 -0700 | [diff] [blame] | 19 | sudo pip install markupsafe |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 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 |
Andy Bavier | 79702bc | 2017-06-01 15:43:36 -0400 | [diff] [blame] | 45 | repo init -u https://gerrit.opencord.org/manifest -b master |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 46 | 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 | |
| 71 | function 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 | |
| 82 | function 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 |
| 87 | GERRIT_BRANCHES= |
| 88 | CLEANUP=0 |
| 89 | CORD_PROFILE="" |
| 90 | |
| 91 | while 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 |
| 112 | done |
| 113 | |
| 114 | # "main" function |
| 115 | if [[ $CLEANUP -eq 1 ]] |
| 116 | then |
| 117 | cleanup |
| 118 | fi |
| 119 | |
| 120 | bootstrap |
| 121 | |
| 122 | if [[ $CORD_PROFILE -ne "" ]] |
| 123 | then |
| 124 | set -x |
| 125 | cord_profile |
| 126 | fi |
| 127 | |
| 128 | exit 0 |