. ../../gradle.properties

echo "脚本使用帮助"
echo "0、修改包名、版本号+1"
echo "1、编译release版本"
echo "2、创建新的签名文件"
echo "3、commit 和 push Base代码"
echo "4、commit 和 push UI代码 (需手动修改分支)"
echo "5、pull lib_base + tool_box "
echo "6、pull tool_box 代码 "
echo "7、为 resGuardApks 目录下的 *_release.apk 打渠道包"
echo "8、提交一个渠道包Tag"
echo "9、开始四大组件混淆"
echo "10、插入乱码"
echo "11、还原代码"
echo "12、SDK插拔"
echo "13、copy apk"
echo "14、生成工具包"
echo "15、功能代码同步"
echo "16、压缩切图"
echo "17、给GP图片添加水印"
echo "18、加固"
echo "19、混淆api"
echo "20、更新GP状态"
echo "21、获取签名秘钥散列"
echo "22、更新gateway"
echo "23、字符串加密"
echo "24、添加toolbox库"
echo "25、马甲包切换"
echo "26、打印checklist"
echo "27、更换隐私协议"

echo " "
if [[ "$app_name" == "$majia_name" ]];then
    echo "****** 当前为马甲包 ******"
else
    echo "****** 当前为主包 ******"
fi

echo -n "请输入指令编号："
read commod

if (($commod == '0'))
then
    chmod a+x pkgname_generator.py
    ./pkgname_generator.py

elif (($commod == '1'))
then
    chmod a+x release_builder.sh
    ./release_builder.sh

elif (($commod == '2'))
then
    chmod a+x creat_keystore.sh
    ./creat_keystore.sh
elif (($commod == '3'))
then
    chmod a+x base_push.sh
    ./base_push.sh

elif (($commod == '4'))
then
    chmod a+x module_push.sh
    ./module_push.sh

elif (($commod == '5'))
then
    cd ../..
    git submodule update --remote
    cd lib_base
    git checkout master
    git pull
    cd ..
    git submodule update --remote
    cd cash_plugin_toolbox
    git checkout master
    git pull
    cd ..
    git submodule update --remote
    cd lib_yitu || { echo "lib_yitu not exist"; exit 1; }
    git checkout master
    git pull

elif (($commod == '6'))
then
    cd ../../
    git submodule update --remote
    cd cash_plugin_toolbox
    git checkout master
    git pull

elif (($commod == '7'))
then
    chmod a+x make_channel.sh
    ./make_channel.sh

elif (($commod == '8'))
then
    chmod a+x push_with_tag.sh
    ./push_with_tag.sh

elif (($commod == '9'))
then
    cd garble
    chmod a+x rename_project.sh
    ./rename_project.sh

elif (($commod == '10'))
then
    cd garble
    chmod a+x insert.sh
    ./insert.sh

elif (($commod == '11'))
then
    cd garble
    chmod a+x reset_name.sh
    ./reset_name.sh

elif (($commod == '12'))
then
    echo "1、开启SDK"
    echo "2、关闭SDK"
    echo -n "请选择操作："
    read action

    echo "TD(同盾)、AF(Appsflyer)"
    echo -n "输入要操作的SDK代码："
    read sdk

    chmod a+x sdk_manager.py
    if (($action == '1'))
    then
        ./sdk_manager.py 'open' ${sdk}
    elif (($action == '2'))
    then
        ./sdk_manager.py 'close' ${sdk}
    fi

elif (($commod == '13'))
then
    chmod a+x move_apk.sh
    ./move_apk.sh

elif (($commod == '14'))
then
    chmod a+x build_tool_apk.sh
    ./build_tool_apk.sh

elif (($commod == '15'))
then
    cd code
    chmod a+x code_sync.sh
    ./code_sync.sh

elif (($commod == '16'))
then
    chmod a+x tinypng.py
    ./tinypng.py -d ../../app/src/main/res/drawable-xxhdpi

elif (($commod == '17'))
then
    chmod a+x mark_screen_img.py
    ./mark_screen_img.py "${corp_id}" "${signing_keyAlias}"

elif (($commod == '18'))
then
    chmod a+x jiagu.sh
    ./jiagu.sh

elif (($commod == '19'))
then
    cd code
    chmod a+x rename_api.py
    ./rename_api.py

elif (($commod == '20'))
then
    chmod a+x refresh_gponline.sh
    if((${#1} > 0))
    then
        ./refresh_gponline.sh "${corp_id}${1}"
    else
        ./refresh_gponline.sh
    fi

elif (($commod == '21'))
then
    echo -n "散列："
    keytool -exportcert -alias ${signing_keyAlias} -keystore "app/${signing_certificate}" -storepass "${signing_keyAlias}" | openssl sha1 -binary | openssl base64
    cd print
    echo "包名：${app_id}"
    python print_splash_path.py

elif (($commod == '22'))
then
    cd res
    chmod a+x update_gateway.py
    python update_gateway.py

elif (($commod == '23'))
then
    cd garble
#    chmod a+x string_decrypt.py
#    python string_decrypt.py

elif (($commod == '24'))
then
    cd code
    chmod a+x update_setting_gradle.py
    python update_setting_gradle.py
    cd ../../../
    git submodule add https://git.starwin.tech/sikang/cash_plugin_toolbox.git

elif (($commod == '25'))
then
    cd ../..

    echo "1、切换到主包"
    echo "2、切换到马甲包"
    echo -n "请选择操作："
    read action

    if (($action == '1'))
    then
        #主包Logo
        cp app/src/main/res/drawable-xxhdpi/logo_main.png  app/src/main/res/drawable-xxhdpi/logo.png || { echo "logo_main.png not exist"; exit 1; }
        #主包混淆文件
        rm script/api_mapping
        cp script/api_mapping_main script/api_mapping
#        rm app/src/main/assets/web/privacy.html
#        cp app/src/main/assets/web/privacy_main.html app/src/main/assets/web/privacy.html
        #APP名替换

        LC_CTYPE=C && LANG=C && sed -i "" "s#^app_name=.*#app_name='${main_name}'#g"  gradle.properties
        LC_CTYPE=C && LANG=C && sed -i "" "s#^gateway_url=.*#gateway_url=\"${gateway_main}\"#g"  gradle.properties
        LC_CTYPE=C && LANG=C && sed -i "" "s#^host_app=.*#host_app=true#g"  gradle.properties
        #更新gw
        cd lib_base/script/res
        chmod a+x update_gateway.py
        python update_gateway.py

    elif (($action == '2'))
    then
        #马甲logo替换主logo
        cp app/src/main/res/drawable-xxhdpi/logo_majia.png  app/src/main/res/drawable-xxhdpi/logo.png || { echo "logo_majia.png not exist"; exit 1; }
        #马甲混淆文件替换
        rm script/api_mapping
        cp script/api_mapping_majia script/api_mapping
#        rm app/src/main/assets/web/privacy.html
#        cp app/src/main/assets/web/privacy_majia.html app/src/main/assets/web/privacy.html
        #APP名替换
        LC_CTYPE=C && LANG=C && sed -i "" "s#^app_name=.*#app_name='${majia_name}'#g"  gradle.properties
        LC_CTYPE=C && LANG=C && sed -i "" "s#^gateway_url=.*#gateway_url=\"${gateway_mj}\"#g"  gradle.properties
        LC_CTYPE=C && LANG=C && sed -i "" "s#^host_app=.*#host_app=false#g"  gradle.properties
        #更新gw
        cd lib_base/script/res
        chmod a+x update_gateway.py
        python update_gateway.py
    fi

elif (($commod == '26')) || (($commod == '266'));then
    params=""
    if (($commod == '266'));then
        params="?name=${app_name// /%20}";fi
    echo " "
    echo "${corp_id}  ${app_name} "
    echo "包名：${app_id}"
    echo "对内协议：${agreement_url}${params}"
    echo "对外协议：${home}/privacy.html${params}"
    echo "gateway：${gateway_url}"
#    echo "官网：${home}"
    echo " "
    cd print
    code=${desc_code}

    if [[ ! ${code} ]];then
        code=-1
    fi

    python create_desc.py "${app_name}" "${cus_email}" "${hot_line}" "${cus_adress}" "${corp_id}" "${home}/privacy.html" "${home}" ${code}
    echo " "
    file_name="${corp_id}_${app_name}"
    mv /Users/connor/Documents/apks/"${file_name}.apk" /Users/connor/Documents/apks/"${file_name}/app.apk"
    cp ../../../app/src/main/res/drawable-xxhdpi/logo.png /Users/connor/Documents/apks/"${file_name}/logo.png"

elif (($commod == '27'));then
    cd privacy
    python update_privacy.py "${corp_id}" "${app_name}" "${agreement_url}" "true"

elif (($commod == '10000'))
then
    cd ..
    git reset --hard origin/master

else
    echo "找不到编号"
fi