Last active
August 29, 2015 14:10
-
-
Save mreider/029c478b22f60b6ba15d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| function welcome { | |
| printf "\nThis script is necessary in Ops Man early alpha.\n" | |
| printf "First let's check some things...\n" | |
| check_things | |
| ask_and_do $need_stemcell "Wrong Stemcell. Fix it?" rename_stemcell | |
| ask_and_do $need_bosh_pem "Need BOSH keypair in AWS (non-destructive). Ok?" create_keypair | |
| ask_and_do $need_download_runtime "Download and import experimental Elastic Runtime for AWS?" grab_runtime | |
| ask_and_do $need_import_runtime "Import experimental Elastic Runtime for AWS?" import_runtime | |
| } | |
| function ask_and_do () { | |
| if [ $1 = TRUE ] | |
| then | |
| read -r -p "$(echo -e $2 '\n\b')" response | |
| response=${response,,} | |
| if [[ $response =~ ^(yes|y)$ ]] | |
| then | |
| eval $3 | |
| fi | |
| fi | |
| } | |
| function check_things { | |
| if [ -f /var/tempest/stemcells/bosh-stemcell-2690-aws-xen-ubuntu-trusty-go_agent.tgz ] | |
| then | |
| need_stemcell=TRUE | |
| else | |
| need_stemcell=FALSE | |
| fi | |
| if [ -f /home/tempest-web/tempest/assets/bosh.pem ] | |
| then | |
| need_bosh_pem=FALSE | |
| else | |
| need_bosh_pem=TRUE | |
| fi | |
| if [ -f /tmp/runtime/ccc.zip ] | |
| then | |
| need_download_runtime=FALSE | |
| else | |
| need_download_runtime=TRUE | |
| fi | |
| if [ "$(ls -A /var/tempest/workspaces/default/metadata)" ]; then | |
| need_import_runtime=FALSE | |
| else | |
| need_import_runtime=TRUE | |
| fi | |
| } | |
| function rename_stemcell { | |
| pushd /var/tempest/stemcells | |
| mv bosh-stemcell-2690-aws-xen-ubuntu-trusty-go_agent.tgz bosh-stemcell-2690.6-aws-xen-ubuntu-trusty-go_agent.tgz || true | |
| popd | |
| printf "Stemcell fixed.\n" | |
| } | |
| function grab_runtime { | |
| rm -rf /tmp/runtime | |
| mkdir /tmp/runtime | |
| pushd /tmp/runtime | |
| wget https://s3.amazonaws.com/experimental-runtime-aws/ccc.zip | |
| popd | |
| } | |
| function import_runtime { | |
| printf "Importing experimental runtime to Ops Manager\n" | |
| read -r -p "$(echo -e 'Ops Manager username:\n\b')" ops_man_user | |
| if [ $ops_man_user == "" ] | |
| then | |
| err "No username provided" | |
| else | |
| read -r -p "$(echo -e 'Ops Manager password:\n\b')" ops_man_password | |
| if [ $ops_man_password == "" ] | |
| then | |
| err "No password provided" | |
| fi | |
| fi | |
| printf "This operation will take a few minutes...\n" | |
| curl 'https://localhost/api/products' -F 'product[file]=@/tmp/runtime/ccc.zip' -X POST -u $ops_man_user:$ops_man_password -k | |
| } | |
| function create_keypair { | |
| read -r -p "$(echo -e 'Enter AWS Key ID:\n\b')" aws_key_id | |
| if [ $aws_key_id == "" ] | |
| then | |
| err "No key provided" | |
| else | |
| read -r -p "$(echo -e 'Enter AWS Secret Access Key:\n\b')" aws_secret_key | |
| if [ $aws_secret_key == "" ] | |
| then | |
| err "No secret key provided" | |
| fi | |
| fi | |
| printf "Creating a tmp directory for AWS CLI\n" | |
| rm -rf /tmp/awscli | |
| mkdir /tmp/awscli | |
| pushd /tmp/awscli | |
| wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip > /dev/null | |
| unzip awscli-bundle.zip | |
| ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws | |
| popd | |
| printf "Creating another tmp directory for jq parser\n" | |
| rm -rf /tmp/jq | |
| mkdir /tmp/jq | |
| pushd /tmp/jq | |
| wget http://stedolan.github.io/jq/download/source/jq-1.4.tar.gz | |
| tar -xzvf jq-1.4.tar.gz | |
| cd jq-1.4 | |
| ./configure ; make | |
| sudo make install | |
| popd | |
| aws configure set aws_access_key_id $aws_key_id ; aws configure set aws_secret_access_key $aws_secret_key ; aws configure set region us-east-1 | |
| aws ec2 create-key-pair --key-name 'bosh' > /tmp/out.txt; sleep 5 | |
| if [ -s /tmp/out.txt ] | |
| then | |
| printf "Saving private key /home/tempest/web/assets/bosh.pem\n" | |
| mkdir -p /home/tempest-web/tempest/assets | |
| cat /tmp/out.txt | jq -r '.KeyMaterial' > /home/tempest-web/tempest/assets/bosh.pem | |
| else | |
| err "Something went wrong. Maybe your key was incorrect\n" | |
| fi | |
| } | |
| err () { | |
| printf $1 | |
| printf $2 | |
| exit 1; | |
| } | |
| welcome | |
| printf "\nScript complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment