This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
forked from ralfbiedert/cheats.rs
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdeploy.sh
executable file
·90 lines (66 loc) · 2.56 KB
/
deploy.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#
# Poor man's deploy script in lack of better infrastructure.
#
TOML_BASE=config.toml
FOLDER_PREP=public # Zola output folder
FOLDER_DIST=public.clean # Our own publish folder after asset inlining
# Only these files are allowed to move from $FOLDER_PREP to $FOLDER_DIST (and end up on S3)
FOLDER_DIST_WHITELIST=("index.html" "404.html" "legal" "sitemap.xml" "robots.txt" "fonts/")
# To color our `echo` output
_YELLOW='\033[1;33m'
_GREEN='\033[0;32m'
_RED='\033[0;31m'
_NC='\033[0m' # No Color
# Substituions in generated files
NOW_SITEMAP=`date +"%Y-%m-%dT%H:%M:%S+08:00"`
NOW_HUMAN=`date +"%Y-%m-%d"`
GITHASH=`git rev-parse --short HEAD`
function abort() {
echo "Error executing previous command."
exit 1
}
# Make sure we _only_ allow final (packaged) files as S3 gets messy otherwise
rm -rf "$FOLDER_PREP"; mkdir "$FOLDER_PREP";
rm -rf "$FOLDER_DIST"; mkdir "$FOLDER_DIST";
# zola -c "$TOML_BASE" check || abort
zola -c "$TOML_BASE" build || abort
npm run posthtml_1 || abort # This is absolutely terrible but apparently the asset inliner we use
npm run posthtml_2 || abort # is unable to handle multiple files with different paths gracefully ...
# Update deployment date in sitemap.xml
sed -i -e "s/_NOW_SITEMAP_/$NOW_SITEMAP/g" "$FOLDER_PREP/sitemap.xml"
sed -i -e "s/_NOW_HUMAN_/$NOW_HUMAN/g" "$FOLDER_PREP/index.html"
sed -i -e "s/_GITHASH_/$GITHASH/g" "$FOLDER_PREP/index.html"
# Only more expressly allowed files
for item in ${FOLDER_DIST_WHITELIST[*]}
do
echo "Copying $FOLDER_PREP/$item to $FOLDER_DIST/"
cp -rf "$FOLDER_PREP/$item" "$FOLDER_DIST"
done
# Early debug exit (USE THIS ONE, or there will be pain and suffering)
# exit 0
# Now we can publish
if [[ $1 == "--live" ]]; then
echo -e "Sending to ${_GREEN}LIVE${_NC} environment."
# Make sure we have committed so the public web site shows the right hash.
if [[ -n "$(git status --porcelain)" ]]; then
echo -e "You ${_RED}must commit${_NC} before going --live. Aborting ..."
exit 1
fi
# Publish
# scp -r public.clean/* [email protected]:/data/sites/cheats.rs
fi
if [[ $1 == "--staging" ]]; then
# Staging URL:
# http://cheats.rs-staging.s3-website.eu-central-1.amazonaws.com/
echo -e "Sending to ${_YELLOW}STAGING${_NC} environment."
# Staging
# scp -r public.clean/* [email protected]:/data/sites/cheats.rs
fi
if [[ $1 == "--kingfree" ]]; then
# CN URL:
# http://cheats.rs.kingfree.moe/
echo -e "Sending to ${_YELLOW}kingfree.moe${_NC} environment."
# CN
scp -r public.clean/* [email protected]:/var/www/cheats.rs
fi