Skip to content

Commit

Permalink
Updated direct for older versions of cURL.
Browse files Browse the repository at this point in the history
  • Loading branch information
ladar committed Nov 3, 2023
1 parent bbb524f commit 1245f35
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions res/scripts/direct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ function upload_box() {
DEFAULT_ARCH="true"
fi

WRITEOUT="\nFILE: $FILENAME\nREPO: $ORG/$BOX\nCODE: %{http_code}\nIP: %{remote_ip}\nBYTES: %{size_upload}\nRATE: %{speed_upload}\nTOTAL TIME: %{time_total}\n%{onerror}ERROR: %{errormsg}\n"

if [ "$(${CURL} -so /dev/null --write-out "%{onerror}" https://lavabit.com 2>&1)" ] || \
[ "$(${CURL} -so /dev/null --write-out "%{errormsg}" https://lavabit.com 2>&1)" ]then
WRITEOUT="\nFILE: $FILENAME\nREPO: $ORG/$BOX\nCODE: %{http_code}\nIP: %{remote_ip}\nBYTES: %{size_upload}\nRATE: %{speed_upload}\nTOTAL TIME: %{time_total}\n"
fi

# Checks whether the version exists already, and creates it if necessary.
[ "`${CURL} --tlsv1.2 --silent --retry 4 --retry-delay 2 --max-time 180 --request GET --fail \
--output /dev/null --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" --write-out "%{http_code}" \
Expand Down Expand Up @@ -358,8 +365,7 @@ function upload_box() {
{ printf "${T_BYEL} Provider delete failed. [ $ORG $BOX $PROVIDER $ARCH $VERSION ]${T_RESET}\n" >&2 ; exit 1 ; } ; }

# Create the provider/arch.
## TODO: We should be setting default_architecture to true, based on the org + arch values.
${CURL} --tlsv1.2 --silent --retry 4 --retry-delay 2 --max-time 180 --request POST --fail \
retry ${CURL} --tlsv1.2 --silent --retry 4 --retry-delay 2 --max-time 180 --request POST --fail \
--output /dev/null --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"provider\":{ \"name\":\"$PROVIDER\",\"checksum\":\"$HASH\",\"architecture\":\"$ARCH\",\"default_architecture\":\"$DEFAULT_ARCH\",\"checksum_type\":\"SHA256\"}}" \
Expand All @@ -384,7 +390,7 @@ function upload_box() {

retry ${CURL} --tlsv1.2 --silent --retry 4 --retry-delay 2 --max-time 7200 --request PUT --fail \
--speed-time 60 --speed-limit 1024 --expect100-timeout 7200 \
--write-out "FILE: $FILENAME\nREPO: $ORG/$BOX\nCODE: %{http_code}\nIP: %{remote_ip}\nBYTES: %{size_upload}\nRATE: %{speed_upload}\nTOTAL TIME: %{time_total}\n%{onerror}ERROR: %{errormsg}\n" \
--write-out "$WRITEOUT" \
--header "Connection: keep-alive" --upload-file "$FILEPATH" "$UPLOAD_PATH"

RESULT=$?
Expand All @@ -396,11 +402,11 @@ function upload_box() {
# Submit the callback twice. hopefully this will reduce the number of boxes without valid download URLs.
${CURL} --tlsv1.2 --silent --retry 4 --retry-delay 2 --max-time 180 --request PUT --fail \
--output "/dev/null" --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
--write-out "%{onerror}FILE: $FILENAME\nREPO: $ORG/$BOX\nCODE: %{http_code}\nIP: %{remote_ip}\nBYTES: %{size_upload}\nRATE: %{speed_upload}\nTOTAL TIME: %{time_total}\nERROR: %{errormsg}\n" \
--write-out "$WRITEOUT" \
"$UPLOAD_CALLBACK" || \
{ sleep 16 ; ${CURL} --tlsv1.2 --silent --retry 4 --retry-delay 2 --max-time 180 --request PUT --fail \
--output "/dev/null" --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
--write-out "%{onerror}FILE: $FILENAME\nREPO: $ORG/$BOX\nCODE: %{http_code}\nIP: %{remote_ip}\nBYTES: %{size_upload}\nRATE: %{speed_upload}\nTOTAL TIME: %{time_total}\nERROR: %{errormsg}\n" \
--write-out "$WRITEOUT" \
"$UPLOAD_CALLBACK" ; } || \
{ printf "${T_BYEL} Upload failed. The callback returned an error. [ $ORG $BOX $PROVIDER $ARCH $VERSION / RESULT = $RESULT ]${T_RESET}\n" >&2 ; exit 1 ; }

Expand Down

0 comments on commit 1245f35

Please sign in to comment.