#!/usr/bin/env bash
echo "1、GP包（无权限）"
echo "2、渠道包（有权限）"
echo "3、马甲包 1"
echo "4、马甲包 2"
echo "5、马甲包 3"


echo -n "选择打包方式："
read action

cd ../../
. gradle.properties
rm -rf resGuardApks
gradlew clean

init(){
    cd lib_base/script
    #同盾插拔
    if((${#tongdun_parent_key}>5));then
        ./sdk_manager.py "open" "TD"
    else
        ./sdk_manager.py "close" "TD"
    fi

    #FB插拔
    if((${facebook_analytics}=='false'));then
        ./sdk_manager.py "close" "FACEBOOK"
    else
        ./sdk_manager.py "open" "FACEBOOK"
    fi

    #api混淆
    if ((${rename_api}=='true'))
    then
        cd code
        chmod a+x rename_api.py
        ./rename_api.py
        cd ..
    fi

    cd garble
    #四大组件混淆
    ./rename_project.sh
    #代码结构混淆
    ./insert.py
    cd ../../../
}


if((${action}=='1'))
then
    init
    gradlew resguardAppProductGoogleplayRelease

elif((${action}=='2'))
then
    init
    gradlew resguardAppProductWebsiteRelease

elif((${action}=='3'))
then
    mv app/src/main/res/drawable-xxhdpi/logo_majia1.png  app/src/main/res/drawable-xxhdpi/logo.png
    mv script/api_mapping_majia1 script/api_mapping
    sed -i "" "s#^app_name=.*#app_name=${majia_name1}#g"  gradle.properties
    init
    gradlew resguardAppProductGoogleplayRelease

elif((${action}=='4'))
then
    mv app/src/main/res/drawable-xxhdpi/logo_majia2.png  app/src/main/res/drawable-xxhdpi/logo.png
    sed -i "" "s#^app_name=.*#app_name=${majia_name2}#g"  gradle.properties
    mv script/api_mapping_majia2 script/api_mapping
    init
    gradlew resguardAppProductGoogleplayRelease

elif((${action}=='5'))
then
    mv app/src/main/res/drawable-xxhdpi/logo_majia3.png  app/src/main/res/drawable-xxhdpi/logo.png
    sed -i "" "s#^app_name=.*#app_name=${majia_name3}#g"  gradle.properties
    mv script/api_mapping_majia3 script/api_mapping
    init
    gradlew resguardAppProductGoogleplayRelease


else
    echo "未知的打包方式"
fi

gradlew clean
cd lib_base/script/garble/
./reset_name.sh
