Files
BotExt/publish-addon.sh
T

83 lines
2.5 KiB
Bash

#!/bin/bash
client_id="ff7d5a3b-a020-46f5-8d97-b996c3c64f0e"
client_secret="5B~8Q~xrpV1-eBkZIPaNL0r6apMbWaFMtAoaSdz6"
product_id="f65aed0e-55f6-4b68-9c1b-60bb7000e1e4"
file_name="crx.zip"
zip $file_name crx/*
echo "Zip file created."
# get token
token_response=$(curl -s -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=${client_id}" \
-d "scope=https://api.addons.microsoftedge.microsoft.com/.default" \
-d "client_secret=${client_secret}" \
-d "grant_type=client_credentials" \
https://login.microsoftonline.com/5c9eedce-81bc-42f3-8823-48ba6258b391/oauth2/v2.0/token)
token=$(echo $token_response | jq -r '.access_token')
echo "get token success"
# echo token
# Upload zip file
upload_response=$(curl -s -D - \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/zip" \
-X POST \
-T $file_name \
https://api.addons.microsoftedge.microsoft.com/v1/products/$product_id/submissions/draft/package)
# Get Location
operation_id=$(echo "$upload_response" | grep -Fi Location | awk '{print $2}' | tr -d '\r')
# echo $operation_id
check_response=$(curl -s \
-H "Authorization: Bearer $token" \
-X GET \
https://api.addons.microsoftedge.microsoft.com/v1/products/$product_id/submissions/draft/package/operations/$operation_id)
# echo $check_response
errorCode=$(echo $check_response | jq -r '.errorCode')
if [ "$errorCode" = "null" ]; then
echo "Upload successful."
else
echo "Upload failed. Error code: $errorCode"
errors=$(echo $check_response | jq -r '.errors')
echo "Error details: $errors"
exit 1
fi
publish_response=$(curl -s -D - \
-H "Authorization: Bearer $token" \
-X POST \
-d '{ "notes"="Add some features" }' \
https://api.addons.microsoftedge.microsoft.com/v1/products/$product_id/submissions)
# echo $publish_response
operation_id=$(echo "$publish_response" | grep -Fi Location | awk '{print $2}' | tr -d '\r')
# echo $operation_id
check_publish_response=$(curl -s \
-H "Authorization: Bearer $token" \
https://api.addons.microsoftedge.microsoft.com/v1/products/$product_id/submissions/operations/{$operation_id})
# echo $check_publish_response
# 使用 jq 提取 errorCode
errorCode=$(echo $check_publish_response | jq -r '.errorCode')
# 检查 errorCode 是否为 null
if [ "$errorCode" = "null" ]; then
echo "Submit successful."
else
echo "Operation failed. Error code: $errorCode"
errors=$(echo $check_publish_response | jq -r '.message')
echo "Error details: $errors"
fi