-
Notifications
You must be signed in to change notification settings - Fork 66
/
s3_upload.sh
executable file
·54 lines (46 loc) · 1.23 KB
/
s3_upload.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
#!/bin/bash
set -eo pipefail
s3_upload() {
local filepath=$1
local content_type=$2
if [[ -n $DRYRUN ]]; then
echo "filepath:$filepath content_type:$content_type"
else
aws s3 cp "./$filepath" "s3://hackernewsmobile.com/$filepath" --content-type "$content_type"
fi
}
s3_sync() {
local filepath=$1
if [[ -f $filepath ]]; then
local filename=$(basename "$filepath")
local extension=$(node -e "process.stdout.write(require('path').extname('$filename'))")
if [[ -z "$extension" ]]; then
s3_upload "$filepath" 'text/html'
elif [[ "$extension" == '.html' ]]; then
s3_upload "$filepath" 'text/html'
elif [[ "$extension" == '.js' ]]; then
s3_upload "$filepath" 'application/javascript'
elif [[ "$extension" == '.css' ]]; then
s3_upload "$filepath" 'text/css'
elif [[ "$extension" == '.png' ]]; then
s3_upload "$filepath" 'image/png'
elif [[ "$extension" == '.gif' ]]; then
s3_upload "$filepath" 'image/gif'
elif [[ "$extension" == '.jpg' ]]; then
s3_upload "$filepath" 'image/jpeg'
fi
fi
}
for filepath in public/*
do
cp "$filepath" dist
done
cd dist
for filepath in *
do
s3_sync "$filepath"
done
for filepath in build/*
do
s3_sync "$filepath"
done