-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsync.sh
executable file
·55 lines (47 loc) · 1.2 KB
/
sync.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
BUCKET_NAME="yyt-life-website"
jekyll build --future
if [ $? -ne 0 ]; then
echo "Failed to build."
exit 1
fi
# Optimize image resources
du -hcs _site
which convert
if [ $? -eq 0 ]; then
for FILE in $(find _site -name *.jpg -o -name *.png); do
file $FILE;
convert $FILE -resize 1920x1920\> $FILE;
file $FILE;
done
fi
which pngquant
if [ $? -eq 0 ]; then
pngquant --force --ext .png --verbose --quality 80-90 --strip --skip-if-larger $(find _site -type f -name "*.png")
fi
which jpegoptim
if [ $? -eq 0 ]; then
jpegoptim -f -o -v -s -m95 $(find _site -type f -name "*.jpg")
fi
du -hcs _site
# Upload all things to S3
aws s3 rm --recursive "s3://${BUCKET_NAME}" && \
aws s3 cp --recursive "_site/" "s3://${BUCKET_NAME}"
if [ $? -ne 0 ]; then
echo "Sync up is failed."
exit 1
fi
DISTRIBUTION_ID="$(aws cloudfront list-distributions \
| jq -r '.DistributionList.Items[] | select(.Aliases.Items[0]=="www.yyt.life") | .Id' \
)"
if [ -z "${DISTRIBUTION_ID}" ]; then
echo "Distribution id is empty."
exit 1
fi
aws cloudfront create-invalidation \
--distribution-id "${DISTRIBUTION_ID}" \
--paths "/*"
if [ $? -ne 0 ]; then
echo "Cache invalidation is failed."
exit 1
fi