#部署脚本
type=$1
option=$2
date_dir=`date +%Y-%m-%d`

cd `dirname $0`
pwd

#强更和热更结构
deployUpdate(){
  echo "$(tput setaf 4) $(tput bold)"
  echo "Deploy Update Structure "$1

  branchArray=(hotfix develop feature)
  if [ "$option" == "prod" ]; then  
    branchArray=(master)
  elif [ "$option" == "alpha" ]; then
    branchArray=(hotfix develop feature)
  else
    echo "$(tput setaf 1)"
    echo "Invalid Option "$1" --- alpha: 测试 prod:正式 "
    exit 1
  fi  
  operatorArray=(cash w2 w3)
  clientArray=(pc mobile)
  baseUpdateDir=/data/update/download
  baseHotupdateDir=/data/hotupdate
  #也可以写成for element in ${array[*]}
  for branch in ${branchArray[@]}
  do    
    for operator in ${operatorArray[@]}
    do
      update_dir=$baseUpdateDir/$branch/$operator
      if [ ! -d ${update_dir} ]; then
        sudo mkdir -p ${update_dir}
      fi

      for client in ${clientArray[@]}
      do
        hotupdate_dir=$baseHotupdateDir/$branch/$operator/$client
        if [ ! -d ${hotupdate_dir} ]; then
          sudo mkdir -p ${hotupdate_dir}
        fi
      done
    done
  done
}

if [ "$type" == "update" ]; then      
    deployUpdate $option
elif [ "$type" == "agentM" ]; then    
    echo "UnZip Client...AgentMobile"
fi
