-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate_latest.sh
executable file
·69 lines (53 loc) · 2 KB
/
update_latest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
readonly script_name=${0##*/}
set -eu
function script_failure {
echo "failed at $script_name:$1"
exit 1
}
trap 'script_failure $LINENO' ERR
function print_usage {
echo "" >&2
echo "Usage: ${script_name} aws_access_key_id aws_secret_access_key cloudfront_id webgl_cloudfront_id" >&2
}
if [[ "$#" -ne 4 ]] || [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]] || [[ -z "$4" ]]; then
echo "$# arguments provided, expected 4 arguments" >&2
print_usage
exit 1
fi
readonly aws_access_key_id=$1
readonly aws_secret_access_key=$2
readonly invalidate=$3
readonly invalidate_webgl=$4
readonly s3_bucket="s3://myworld_developer_destination_resources"
readonly versions_file="versions.json"
echo "Obtaining latest version from S3..."
AWS_ACCESS_KEY_ID="$aws_access_key_id" \
AWS_SECRET_ACCESS_KEY="$aws_secret_access_key" \
aws s3 cp \
--region us-east-1 \
"${s3_bucket}/mobile-themes-new/latest/${versions_file}" \
"${versions_file}.gz"
gunzip -f ${versions_file}.gz
echo "Copying theme manifests to 'latest'..."
jq -rc 'keys[]' ${versions_file} | tr -d "\r" | while read theme ; do
theme_directory=$(jq -rc .\"${theme}\" ${versions_file})
AWS_ACCESS_KEY_ID="$aws_access_key_id" \
AWS_SECRET_ACCESS_KEY="$aws_secret_access_key" \
aws s3 cp \
--region us-east-1 \
--recursive \
--acl public-read \
"${s3_bucket}/${theme_directory}" \
"${s3_bucket}/mobile-themes-new/latest/${theme}"
done
echo "Issuing cache invalidations for 'latest' directory..."
AWS_ACCESS_KEY_ID="$aws_access_key_id" \
AWS_SECRET_ACCESS_KEY="$aws_secret_access_key" \
aws configure set preview.cloudfront true
AWS_ACCESS_KEY_ID="$aws_access_key_id" \
AWS_SECRET_ACCESS_KEY="$aws_secret_access_key" \
aws cloudfront create-invalidation --distribution-id $invalidate --paths /mobile-themes-new/latest/*
AWS_ACCESS_KEY_ID="$aws_access_key_id" \
AWS_SECRET_ACCESS_KEY="$aws_secret_access_key" \
aws cloudfront create-invalidation --distribution-id $invalidate_webgl --paths /mobile-themes-new/latest/*