#!/bin/bash DIRECTORIES=( weather, abc ) usage() { CMD=`basename $0` echo "Usage:" echo "$CMD [-P admin-password] [-U admin-user] [-m Maven-profile] [-w which-maven] [-p APIgee profile] [-e enviroment] [-o organization] [-a APIgee address]" echo " admin-password: password of global system admin" echo " admin-user-name: email of admin user" echo " maven profile: the name of the maven profile accordingly with parent-pom/pom.xml file" echo " which maven: please provide either the full path or base path of the maven installation [e.g. mvn3]" echo " APIgee profile: should correspond to an entry in the config.json file [e.g. lab1]" echo " environment: the environment where these API bundles will be deployed" echo " organization: the organization where these API bundles will be installed" echo " APIgee address: IP/port of APIgee management server" exit 1 } while getopts "P:U:m:w:p:e:o:a:h" opt; do case $opt in # variable options P) APIGEE_PASSWORD=$OPTARG ;; U) APIGEE_USERNAME=$OPTARG ;; m) MAVEN_PROFILE=$OPTARG ;; w) WHICH_MAVEN=$OPTARG ;; # these variables could have been already defined in the MAVEN profile, unless you use the generic one p) APIGEE_PROFILE=$OPTARG ;; e) ENVIRONMENT=$OPTARG ;; o) ORGANIZATION=$OPTARG ;; a) APIGEE_HOST=$OPTARG ;; h) usage esac done [ -z "${MAVEN_PROFILE}" ] && MAVEN_PROFILE=weather [ -z "${APIGEE_PROFILE}" ] && APIGEE_PROFILE=weather [ -z "${APIGEE_HOST}" ] && APIGEE_HOST=https://api.enterprise.apigee.com [ -z "${ENVIRONMENT}" ] && ENVIRONMENT=test [ -z "${ORGANIZATION}" ] && ORGANIZATION=XXXXXXXXXXXXX [ -z "${APIGEE_USERNAME}" ] && APIGEE_USERNAME=XXXXXXXXXXXXX [ -z "${APIGEE_PASSWORD}" ] && APIGEE_PASSWORD=XXXXXXXXXXXXX [ -z "${WHICH_MAVEN}" ] && WHICH_MAVEN=mvn echo $WHICH_MAVEN echo $MAVEN_PROFILE LOG_FILE=deployment_espilon.log echo "Preparing to deploy the following proxies: " for DIR in ${DIRECTORIES[*]} do echo $DIR done echo " using $MAVEN_PROFILE as Maven profile, $APIGEE_USERNAME/$APIGEE_PASSWORD as APIgee credentials." echo "Are you sure? y/n [ENTER]" read confirmation if [ "$confirmation" != "y" ]; then echo "EXIT here!" exit 1 fi current_dir=`pwd` > $LOG_FILE date >> $LOG_FILE echo "Deploying ${#DIRECTORIES[@]} proxies ... " counter=0 for DIR in ${DIRECTORIES[*]} do cd $DIR pwd echo "Package proxy $DIR using $MAVEN_PROFILE maven profile ... " "$WHICH_MAVEN" package -P $MAVEN_PROFILE -Dapigee.profile=$APIGEE_PROFILE -Dapigee.env=$ENVIRONMENT -Dapigee.hosturl=$APIGEE_HOST -Dapigee.org=$ORGANIZATION >> $current_dir/$LOG_FILE #echo "Deploy proxy $DIR using $MAVEN_PROFILE maven profile ... " "$WHICH_MAVEN" install -P $MAVEN_PROFILE -Dapigee.profile=$APIGEE_PROFILE -Dapigee.env=$ENVIRONMENT -Dapigee.hosturl=$APIGEE_HOST -Dapigee.org=$ORGANIZATION -Dapigee.username=$APIGEE_USERNAME -Dapigee.password=$APIGEE_PASSWORD >> $current_dir/$LOG_FILE echo "Deployment successful!" && let "counter=counter+1" cd - done echo "$counter/${#DIRECTORIES[@]} successful deployments!" echo "Check $LOG_FILE for more information." exit 0