#!/bin/bash function showUsage { cat << EOF This script will install and configure the ocx-config stack for a specific environment usage: ${0##*/} [-h] ENV -h Display this help and exit Environments currently include QA{1..2} STG{1..3} OR{1..3} or OCI Defaults to installing the 'production' variant if ENV cannot be found. EOF } while getopts "h" opt; do case $opt in h) showUsage exit 0 ;; *) echo "how did I get here?" showUsage exit 1 ;; esac done shift $((OPTIND -1)) #[ -z "$1" ] && showUsage && exit 1 ENV=$1 ## make sure we are Centos7 grep -e "CentOS.*7" -e "Red.*7" /etc/redhat-release || exit 1 ## Get instanceId from metadata ## If no argument specified, see if we can find out for ourselves. ## Make sure jq is installed rpm -qa |grep jq || yum install jq -y ## We need to figure out what account we are in. prodAccountId="603249479586" qaAccountId="673483625697" myAccountId=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document |jq -r .accountId ) case "$myAccountId" in 603249479586) ## Production accountId apiUrl="https://ocx-config-api.ocx-int.com/v1/" ;; 673483625697) ## QA AccountId apiUrl="https://ocx-config-api.qa.ocx-int.net/v1/" ENV=QA ;; esac if [ -z "${ENV}" ] then instanceId=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) region=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document |jq -r .region ) ENV=$(curl -s --data '{ "func": "tags", "args": [ '\"${instanceId}\"', '\"${region}\"' ] }' ${apiUrl} | jq -r '.result' | base64 -d | jq -M '.'|jq -r .Location ) echo -e "Found current instance is in $ENV" fi rpm -qa |grep oceanx-release || /bin/yum -y -q install http://repo.ocx-int.net/rpm/centos7/ocx-int/Packages/oceanx-release-latest.el7.noarch.rpm yum clean all yum -y update oceanx-release PACKAGE=ocx-config-policy-production ## Define DNS servers case ${ENV} in QA*) PACKAGE=ocx-config-policy-qa ;; STG*) PACKAGE=ocx-config-policy-staging ;; *) PACKAGE=ocx-config-policy-production ;; esac yum -y install ocx-misc-scripts ocx-config-service $PACKAGE && \ systemctl daemon-reload && \ systemctl enable ocx-config && \ systemctl start ocx-config && \ /etc/ocx-config/build/bin/cf-agent -KI && \ /sbin/bootstrapSecureRepo >/dev/null || \ echo "an error occured" && exit 127