# PRD or DEV or UAT，与环境文件对应
BUILD_ENV=$(echo $1 | tr '[a-z]' '[A-Z]')

BUILD_TYPE="$(echo ${2:0:1} | tr '[a-z]' '[A-Z]')$(echo ${2:1} | tr '[A-Z]' '[a-z]')"

# yes or no
DD_PUSH=$(echo $3 | tr '[A-Z]' '[a-z]')

if [ ! -n "${BUILD_ENV}" ] ;then
    echo "入参 'BUILD_ENV' 有误！"
    exit 1
fi

if [ ! -n "${BUILD_TYPE}" ] ;then
    echo "入参 'BUILD_TYPE' 有误！"
    exit 1
fi

if [ ! -n "${DD_PUSH}" ] ;then
    echo "入参 'DD_PUSH' 有误！"
    exit 1
fi

# 代码分支
CODE_BRANCH="master"
# 代码仓库
# CODE_SOURCE="http://duanzy_ebiz:duanzhiyong123!@10.32.70.213/Android/esp/ebao/gh-esp-ebao-android.git"
CODE_SOURCE="http://duan.zhiyong:duanzhiyong123!@112.124.100.131/app/guohua/esp/Android.git"
# 脚本仓库
# SCRIPT_SOURCE="http://duanzy_ebiz@duanzhiyong123!10.32.70.213/Android/autopackage.git"
SCRIPT_SOURCE="http://duan.zhiyong:duanzhiyong123!@112.124.100.131/app/Android-AutoPackage.git"
# 蒲公英 API KEY #
PGY_API_KEY="c770c03bf4a1668f3be3cc0c1cd3ae13"
# 蒲公英 USER KEY #
PGY_USER_KEY="4f39753edb22a5bf755b3dd094051e6e"
# 钉钉 机器人 webhook 链接的 access_token 参数值 #
DD_HOST_URL="07eeb45aea9980895eba308a0382b6db304220a200f4e58c04ee097cc56bd4cb"
# 百度加固 密钥参数
JIAGU_AK="Vc2yTGOl2CcJ8ase"
JIAGU_SK="wikoII622um2-O3L"
# APK keystore 签名参数
KS_ALIA="GHEBao"
KS_PASS="ebizghebao"
# 不要改 #
WORKSPACE="/Users/${USER}/AutoPackage/Android/CODE"
# 不要改 #
SCRIPT_PATH="/Users/${USER}/AutoPackage/Android/SCRIPT"

# rm -rf ${WORKSPACE}
# rm -rf ${SCRIPT_PATH}
# git clone --recursive -b ${CODE_BRANCH} ${CODE_SOURCE} ${WORKSPACE}
# git clone -b guohua ${SCRIPT_SOURCE} ${SCRIPT_PATH}
# cp -r ${SCRIPT_PATH}/apk_script ${WORKSPACE}

sh ${WORKSPACE}/apk_script/auto_package_apk.sh ${BUILD_ENV} ${BUILD_TYPE} ${PGY_API_KEY} ${PGY_USER_KEY} ${DD_HOST_URL} ${DD_PUSH} ${JIAGU_AK} ${JIAGU_SK} ${KS_ALIA} ${KS_PASS}