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 |
Sapan Bhatia | 96426ec | 2017-04-13 19:41:04 -0700 | [diff] [blame] | 16 | # sudo apt-get install -y software-properties-common |
| 17 | # sudo apt-add-repository -y ppa:ansible/ansible |
Andy Bavier | ba124b1 | 2017-04-17 12:01:37 -0400 | [diff] [blame] | 18 | sudo apt-get -y install python-dev libffi-dev python-pip libssl-dev sshpass python-netaddr |
Sapan Bhatia | 1996c04 | 2017-06-17 17:46:23 -0700 | [diff] [blame] | 19 | sudo pip install markupsafe |
Andy Bavier | ba124b1 | 2017-04-17 12:01:37 -0400 | [diff] [blame] | 20 | sudo pip install ansible==2.2.2.0 |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 21 | 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 Bavier | 79702bc | 2017-06-01 15:43:36 -0400 | [diff] [blame] | 46 | repo init -u https://gerrit.opencord.org/manifest -b master |
Zack Williams | a276311 | 2017-01-03 11:38:38 -0700 | [diff] [blame] | 47 | 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 | |
| 72 | function 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 | |
| 83 | function 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 |
| 88 | GERRIT_BRANCHES= |
| 89 | CLEANUP=0 |
| 90 | CORD_PROFILE="" |
| 91 | |
| 92 | while 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 |
| 113 | done |
| 114 | |
| 115 | # "main" function |
| 116 | if [[ $CLEANUP -eq 1 ]] |
| 117 | then |
| 118 | cleanup |
| 119 | fi |
| 120 | |
| 121 | bootstrap |
| 122 | |
| 123 | if [[ $CORD_PROFILE -ne "" ]] |
| 124 | then |
| 125 | set -x |
| 126 | cord_profile |
| 127 | fi |
| 128 | |
| 129 | exit 0 |