update script

This commit is contained in:
pratik
2025-10-22 11:22:53 -05:00
parent 304a781c19
commit f1910b36cb

View File

@@ -45,6 +45,11 @@ CF_SKIP_SSL="false" # Use "true" for self-signed certificates
POLL_INTERVAL=5 # seconds between status checks
MAX_WAIT=600 # maximum wait time in seconds (10 minutes)
# Security configuration (optional)
CERT_FILE="" # Path to client certificate file (leave empty to skip)
X_FORWARDED_FOR="" # X-Forwarded-For header value (leave empty to skip)
MY_APIM_KEY="" # My-APIM-KEY header value (leave empty to skip)
#############################################################################
# SCRIPT - Do not modify below this line
#############################################################################
@@ -90,6 +95,24 @@ if ! command -v curl &> /dev/null; then
exit 1
fi
# Build curl options based on configuration
CURL_OPTS=""
if [ -n "$CERT_FILE" ]; then
if [ ! -f "$CERT_FILE" ]; then
log_error "Certificate file not found: $CERT_FILE"
exit 1
fi
CURL_OPTS="$CURL_OPTS --cert $CERT_FILE"
fi
if [ -n "$X_FORWARDED_FOR" ]; then
CURL_OPTS="$CURL_OPTS -H \"X-Forwarded-For: $X_FORWARDED_FOR\""
fi
if [ -n "$MY_APIM_KEY" ]; then
CURL_OPTS="$CURL_OPTS -H \"My-APIM-KEY: $MY_APIM_KEY\""
fi
# Build CF configuration JSON
CF_CONFIG=$(cat <<EOF
{
@@ -115,9 +138,10 @@ echo ""
#############################################################################
log_info "Step 1/5: Initializing upload session..."
INIT_RESPONSE=$(curl -s -X POST "$API_BASE/upload/init" \
INIT_RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/init" \
-H "Content-Type: application/json" \
-d "$CF_CONFIG")
$CURL_OPTS \
-d "'$CF_CONFIG'")
if [ $? -ne 0 ]; then
log_error "Failed to initialize upload session"
@@ -152,7 +176,7 @@ upload_file_in_chunks() {
fi
local total_chunks=$(( ($file_size + $CHUNK_SIZE - 1) / $CHUNK_SIZE ))
local file_size_mb=$(echo "scale=2; $file_size / 1048576" | bc)
local file_size_mb=$(awk "BEGIN {printf \"%.2f\", $file_size / 1048576}")
log_info "Uploading $file_type: $file_name (${file_size_mb}MB, $total_chunks chunks)"
@@ -166,7 +190,8 @@ upload_file_in_chunks() {
for chunk_file in "$temp_dir"/chunk_*; do
printf " Chunk %3d/%3d... " "$((chunk_index + 1))" "$total_chunks"
RESPONSE=$(curl -s -X POST "$API_BASE/upload/chunk" \
RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/chunk" \
$CURL_OPTS \
-F "uploadSessionId=$SESSION_ID" \
-F "fileType=$file_type" \
-F "chunkIndex=$chunk_index" \
@@ -211,7 +236,8 @@ upload_file_in_chunks "$MANIFEST_FILE" "manifest"
#############################################################################
log_info "Step 4/5: Starting async deployment..."
FINALIZE_RESPONSE=$(curl -s -X POST "$API_BASE/upload/finalize?uploadSessionId=$SESSION_ID&async=true")
FINALIZE_RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/finalize?uploadSessionId=$SESSION_ID&async=true" \
$CURL_OPTS)
STATUS=$(echo "$FINALIZE_RESPONSE" | grep -o '"status":"[^"]*' | cut -d'"' -f4)
if [ "$STATUS" != "IN_PROGRESS" ]; then
@@ -234,7 +260,8 @@ while [ $elapsed -lt $MAX_WAIT ]; do
sleep $POLL_INTERVAL
elapsed=$((elapsed + POLL_INTERVAL))
STATUS_RESPONSE=$(curl -s "$API_BASE/deployment/status/$SESSION_ID" 2>/dev/null)
STATUS_RESPONSE=$(eval curl -s "$API_BASE/deployment/status/$SESSION_ID" \
$CURL_OPTS 2>/dev/null)
if [ $? -ne 0 ]; then
log_warning "Failed to fetch status, retrying..."