#!/bin/bash

echo "extract_apk_and_upload arg1:$buildArg"


java -jar ~/dev/android/bundletool-all.jar build-apks --bundle=build/app/outputs/bundle/release/app-release.aab --output=build/app/outputs/bundle/release/app-release.apks --ks=./android/app/fungame.keystore --ks-pass=pass:fUngame2627 --ks-key-alias=fungame --overwrite --mode=universal

mkdir build/app/outputs/bundle/release/apk

unzip build/app/outputs/bundle/release/app-release.apks -d build/app/outputs/bundle/release/apk

mv build/app/outputs/bundle/release/apk/universal.apk build/app/outputs/bundle/release/app-release.apk

touch build/app/outputs/bundle/release/app-release.apk

rm -fr build/app/outputs/bundle/release/apk/

rm -fr build/app/outputs/bundle/release/app-release.apks

result=$?
if [ $result == 0 ]
then
    # export http_proxy=;export https_proxy=;
    curl -F "file=@build/app/outputs/bundle/release/app-release.apk" -F "uKey=3fcd8479c8a50cbaf39119d88d887912" -F "_api_key=20a3d1106b802abbd84ec687eedf17eb" -F "buildInstallType=2" -F "buildPassword=112358" https://www.pgyer.com/apiv2/app/upload
    result=$?
    if [ $result == 0 ]
    then
        echo "upload pgyer success!"
        cd android
        # export http_proxy=http://127.0.0.1:4780;
        # export https_proxy=http://127.0.0.1:4780;
        # export http_proxy=;export https_proxy=;
        cd ..
    else
        echo "upload pgyer failed"
        exit 1
    fi
fi

