Newer
Older
Import / projects / Gameloft / bne_lib / build / scripts / CreateSegment.sh
#!/bin/bash

#
# This script creates a CRM game segment
# This script is tested to work under cygwin bash on windows too
#
if [ $# -lt 6 ]
then
  echo "Wrong number of arguments"
  echo "Usage:"
  echo "    $0  ClientId  UserType:UserName  Password  DataCenter segment_id segment_name"
  echo "Example:"
  echo "    $0  2204:58739:0.1.0r:ios:appstore  game:surv_gs_user  password  mdc  R010_GAME  R_010_BUILD"
  exit 0
fi

CLIENT_ID=$1
USERNAME=$2
PASSWORD=$3
SCOPE="config config_structure"
DATACENTER=$4
SEGMENT_ID=$5
SEGMENT=$6

# Servers
EVE_URL=http://eve.gameloft.com:20001
# Get Pandora URL from EVE
PANDORA_URL=`curl -s $EVE_URL/config/$CLIENT_ID/datacenters/$DATACENTER/urls | sed 's/\,/,\'$'\n/g' | grep "pandora" | cut -d '"' -f 4`
# Translate/redirect beta/gold address to the beta or gold master address to ensure it can work and it will be replicated to all DCs
# Note: .com -> .org  (http://palantir.gameloft.org/master_fed.html)
PANDORA_URL=`echo $PANDORA_URL | sed 's/vbeta\.gameloft\.com/vbeta-master\.gameloft\.org/' | sed 's/vgold\.gameloft\.com/vgold-master\.gameloft\.org/'`
# Get Janus URL from Pandora
AUTH_URL=`curl -s $PANDORA_URL/locate/auth`
# Get Hestia URL from Pandora
CONFIG_URL=`curl -s $PANDORA_URL/locate/config`
# Authorize and get access-token
ACCESS_TOKEN=`curl -k -s -d '' https://$AUTH_URL/authorize -d "username=$USERNAME&password=$PASSWORD&scope=$SCOPE&client_id=$CLIENT_ID" | cut -d '"' -f 4`

echo
echo "Creating CRM game segment $SEGMENT"
echo
echo "  Client ID:    $CLIENT_ID"
echo "  Data Center:  $DATACENTER"
echo "  Username:     $USERNAME"
echo "  Eve:          $EVE_URL"
echo "  Pandora:      $PANDORA_URL"
echo "  Janus:        $AUTH_URL"
echo "  Hestia:       $CONFIG_URL"
echo "  Access token: $ACCESS_TOKEN"
echo

# Make the POST request to hestia to create the game segment
echo
echo "Server response:"
echo
curl -k -s -d '' https://$CONFIG_URL/configs/campaigns/segments/$SEGMENT_ID \
  --data-urlencode "access_token=$ACCESS_TOKEN" \
  --data-urlencode "category=game" \
  --data-urlencode "name=$SEGMENT" \
  --data-urlencode "matcher=expr: (profile.current_client_id == '$CLIENT_ID')"