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


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

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

init(){
    #api混淆
    if [[ -e "script/api_mapping" ]]; then
        cd code
        ./rename_api.py || { echo "rename_api error!"; exit 1; }
        cd ..
    fi


    cd garble
    #字符串混淆
    python string_decrypt.py || { echo "string_decrypt error!"; exit 1; }
    #四大组件混淆
    ./rename_project.sh || { echo "rename_project error!"; exit 1; }
    #代码结构混淆
#    ./insert.py || { echo "insert_code error!"; exit 1; }
    cd ../../../
}

cd lib_base/script

if((${action}=='1'))
then
    ./sdk_manager.py 'close' 'NOLOG' || { echo "sdk_manager error!"; exit 1; }
    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
#    LC_CTYPE=C && LANG=C && 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
#    LC_CTYPE=C && LANG=C && 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
#    LC_CTYPE=C && LANG=C && 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
