#!/usr/bin/env bash
CWD=$(cd "$(dirname "$0")"; pwd)

# *****************************************************************************
# @author khy
# @2017.11.15
#
# 打渠道包
# 将目标apk放到scripts/apk-channel文件夹中即可
#
# *****************************************************************************


source ${CWD}/tinker_env.sh

echo ${APK_CHANNEL_PATH}
if [ ! -d ${APK_CHANNEL_PATH} ];
then
    echo "存放apk包的文件夹不存在"
    exit 0
fi

for apkFile in ${APK_CHANNEL_PATH}/*
do
echo ${apkFile}
if [ -f "$apkFile" ];
then
if [[ $apkFile == *.apk ]];
then
APK_COUNT+=($apkFile)
fi
fi
done

if [ ${#APK_COUNT[*]} != 1 ]
then
echo "确保apk_channel文件夹内只有一个apk包, 否则无法确定以哪个包为渠道基础包"
exit 0
fi

if [ ! -d ${APK_CHANNEL_PATH}/channel ]; then
     mkdir -p ${APK_CHANNEL_PATH}/channel
fi

java -jar ${CWD}/ApkChannelPackage.jar put -mtc ${PROJECT_BASE}/channel.txt ${APK_COUNT[0]} ${APK_CHANNEL_PATH}/channel


