-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.sh
More file actions
executable file
·48 lines (35 loc) · 989 Bytes
/
upload.sh
File metadata and controls
executable file
·48 lines (35 loc) · 989 Bytes
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
#!/bin/bash
set -e
if [[ -z $BUCKET ]]; then
echo "BUCKET is not set"
exit 1
fi
rm -rf dist
mkdir dist
printf "Copying files to temporary directory... "
printf "Done"
find images -name ‘*.DS_Store’ -type f -delete
IFS=$'\n'
for filename in $(find images -type f ! -name ".DS_Store")
do
echo $filename
file=`basename "$filename"`
dir=`dirname "$filename"`
if [[ -n $dir ]]; then
dir="$dir/"
fi
mkdir -p dist/$dir
file="${file%.*}"
extension="${filename##*.}"
hash=$(cat "$filename" | sha1sum | cut -f1 -d" ")
hash=${hash:0:7}
cp "$filename" "dist/${dir}${file}-$hash.${extension##*.}"
done
for filename in $(find dist -type f)
do
gzip -t ${filename} > /dev/null 2>&1 || { echo "compressing ${filename}"; gzip -9 ${filename}; mv ${filename}.gz ${filename}; }
done
aws s3 sync dist ${BUCKET} --cache-control="public,max-age=31536000" --content-encoding="gzip"
printf "Cleaning up... "
rm -rf dist
printf "Done"