upload-nightly

 1#!/bin/bash
 2
 3# Based on the template in: https://docs.digitalocean.com/reference/api/spaces-api/
 4
 5
 6# Step 1: Define the parameters for the Space you want to upload to.
 7SPACE="zed-nightly-host" # Find your endpoint in the control panel, under Settings.
 8REGION="nyc3" # Must be "us-east-1" when creating new Spaces. Otherwise, use the region in your endpoint (e.g. nyc3).
 9STORAGETYPE="STANDARD" # Storage type, can be STANDARD, REDUCED_REDUNDANCY, etc.
10KEY="???????" # Access key pair. You can create access key pairs using the control panel or API.
11SECRET="$SECRET" # Secret access key defined through an environment variable.
12
13# Step 2: Define a function that uploads your object via cURL.
14function putS3
15{
16  path="." # The local path to the file you want to upload.
17  file="hello-world.txt" # The file you want to upload.
18  space_path="/" # The path within your Space where you want to upload the new file.
19  space="${SPACE}"
20  date=$(date +"%a, %d %b %Y %T %z")
21  acl="x-amz-acl:private" # Defines Access-control List (ACL) permissions, such as private or public.
22  content_type="text/plain" # Defines the type of content you are uploading.
23  storage_type="x-amz-storage-class:${STORAGETYPE}"
24  string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$space$space_path$file"
25  signature=$(echo -en "${string}" | openssl sha1 -hmac "${SECRET}" -binary | base64)
26  curl -s -X PUT -T "$path/$file" \ # The cURL command that uploads your file.
27    -H "Host: $space.${REGION}.digitaloceanspaces.com" \
28    -H "Date: $date" \
29    -H "Content-Type: $content_type" \
30    -H "$storage_type" \
31    -H "$acl" \
32    -H "Authorization: AWS ${KEY}:$signature" \
33    "https://$space.${REGION}.digitaloceanspaces.com$space_path$file"
34}
35
36# Step 3: mkdir for file based on release sha
37# :/sha-of- -commit/Zed.dmg
38
39# Step 4: Put Zed.dmg in that directory
40for file in "$path"/*; do
41  putS3 "$path" "${file##*/}" "nyc-tutorial-space/"
42done
43
44# Step 5: Output that directory for next step