#!/bin/bash

set -u -e
export http_port=7618

function init() {
  error=`wget -q -O - http://127.0.0.1:${http_port}/initialize/initomp`
  echo -e $error
  errcode=`echo $error|grep -q '"errcode": 0'; echo $?`
  # 0表示存在
  if [ $errcode -ne 0 ];
  then
    echo -e "init omp failed"
    exit 1
  fi

  echo -e "init omp success"
}

function sync() {
  error=`wget -q -O - http://127.0.0.1:${http_port}/initialize/sync`
  echo -e $error
  errcode=`echo $error|grep -q '"errcode": 0'; echo $?`
  # 0表示存在
  if [ $errcode -ne 0 ];
  then
    echo -e "sync cosmic failed"
    exit 2
  fi

  echo -e "sync cosmic success"
}

echo -e "\033[38;4;94m>>>>开始初始化omp\033[0m"
sleep 60
init
echo -e "\033[38;4;94m>>>>开始同步cosmic\033[0m"
sync
echo -e "\033[38;5;35m>>>>初始化gpaas完成\033[0m"