-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.inc.sh
175 lines (146 loc) · 5.2 KB
/
bootstrap.inc.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Shared infrastructure for websites
set -eu
# BOOTSTRAP variable is defined in the standard site prolog.
# 1. Update BOOTSTRAP_VERSION to the published tag or commitish to use
# 2. Update BOOTSTRAP path as necessary
#
# ## START STANDARD SITE BUILD SCRIPT INCLUDE
# readonly THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
# readonly BOOTSTRAP="$(dirname "$THIS_SCRIPT")/resources/bootstrap.inc.sh"
# readonly BOOTSTRAP_VERSION=v0.3
# [ -f "$BOOTSTRAP" ] && source "$BOOTSTRAP" || source <(curl -fs https://raw.githubusercontent.com/keymanapp/shared-sites/$BOOTSTRAP_VERSION/bootstrap.inc.sh)
# ## END STANDARD SITE BUILD SCRIPT INCLUDE
#
# Sanity checks on start
#
if [[ -z ${BOOTSTRAP+x} ]]; then
echo "FATAL: \$BOOTSTRAP must be defined according to standard site build.sh script prolog"
exit 2
fi
if [[ -z ${BOOTSTRAP_VERSION+x} ]]; then
echo "FATAL: \$BOOTSTRAP_VERSION must be defined according to standard site build.sh script prolog"
exit 2
fi
if [[ -z ${THIS_SCRIPT+x} ]]; then
echo "FATAL: \$THIS_SCRIPT must be defined according to standard site build.sh script prolog"
exit 2
fi
#
# Define globals (if not already defined)
#
if [[ -z ${BOOTSTRAP_ROOT+x} ]]; then
readonly BOOTSTRAP_ROOT="$(dirname "$BOOTSTRAP")/.."
fi
if [[ -z ${BOOTSTRAP_CURRENT_VERSION_FILE+x} ]]; then
readonly BOOTSTRAP_CURRENT_VERSION_FILE="$(dirname "$BOOTSTRAP")/.bootstrap-version"
fi
#
# Helper function to download a file from the shared-sites repository 'main' branch
#
function _bootstrap_download() {
local remote_file="$1"
local local_file="$2"
_bootstrap_echo " Downloading $remote_file"
curl -fs "https://raw.githubusercontent.com/keymanapp/shared-sites/$BOOTSTRAP_VERSION/$remote_file" -o "$local_file" || (
_bootstrap_echo "FATAL: Failed to download $remote_file"
exit 3
)
}
function _bootstrap_echo() {
echo "[bootstrap] $*"
}
#
# Initialize required files, including downloading common, if those files are
# not present. Note that on first run bootstrap.inc.sh will be downloaded twice,
# once by the prolog, and again in _bootstrap_init, but as this is a low-cost
# operation, it makes the build script prolog cleaner to do it this way.
#
# This will be called on first run on a clean repo, and should also be called
# on `build.sh configure`.
#
function bootstrap_configure() {
_bootstrap_echo "Bootstrap starting"
_bootstrap_download bootstrap.inc.sh "$BOOTSTRAP"
# Record the version we downloaded -- before we re-source the script!
echo $BOOTSTRAP_VERSION > "$BOOTSTRAP_CURRENT_VERSION_FILE"
# Load the new bootstrap before doing additional downloads. The bootstrap
# include script has been designed to cope with being run multiple times;
# this ensures that the latest version of _bootstrap_configure_common is
# run.
source "$BOOTSTRAP"
_bootstrap_configure_common
_bootstrap_echo "Bootstrap complete"
}
#
# Download all files in _common, removing existing files
#
function _bootstrap_configure_common() {
local BOOTSTRAP_COMMON="$BOOTSTRAP_ROOT/_common"
local ASSET_IMGS="assets/img"
local ASSET_LOGOS="assets/sil-logos-2024"
local COMMON_FILES=(
builder.inc.sh
docker.inc.sh
keyman-local-ports.inc.sh
GFMAlerts.php
JsonApiFailure.php
KeymanHosts.php
KeymanSentry.php
KeymanVersion.php
MarkdownHost.php
ImageRandomizer.php
)
local IMG_FILES=(
gfmalerts.png
)
local LOGO_FILES=(
sil-logo-abbysinica.png
sil-logo-andika-v1.png
sil-logo-andika-v2.png
sil-logo-annapurna.png
sil-logo-tai-heritage-pro.png
)
local common_file=
local img_file=
_bootstrap_echo "Downloading _common files"
rm -rf "$BOOTSTRAP_COMMON"
mkdir -p "$BOOTSTRAP_COMMON"
for common_file in "${COMMON_FILES[@]}"; do
_bootstrap_download "_common/$common_file" "$BOOTSTRAP_COMMON/$common_file"
done
for img_file in "${IMG_FILES[@]}"; do
mkdir -p "$BOOTSTRAP_COMMON/$ASSET_IMGS/"
_bootstrap_download "_common/$ASSET_IMGS/$img_file" "$BOOTSTRAP_COMMON/$ASSET_IMGS/$img_file"
done
for logo_file in "${LOGO_FILES[@]}"; do
mkdir -p "$BOOTSTRAP_COMMON/$ASSET_LOGOS/"
_bootstrap_download "_common/$ASSET_LOGOS/$logo_file" "$BOOTSTRAP_COMMON/$ASSET_LOGOS/$logo_file"
done
_bootstrap_echo "All _common files downloaded"
}
#
# Check the bootstrap files against the .bootstrap-version file
#
function _bootstrap_new_version_requested() {
if [[ ! -f $BOOTSTRAP_CURRENT_VERSION_FILE ]]; then
# unknown version, version file doesn't exist, should rebuild
return 0
fi
if [[ "$(cat "$BOOTSTRAP_CURRENT_VERSION_FILE")" != "$BOOTSTRAP_VERSION" ]]; then
# version is different, should rebuild
return 0
fi
return 1
}
# Test if resources need to be downloaded
if [[ ! -f "$BOOTSTRAP" ]] || _bootstrap_new_version_requested; then
_bootstrap_echo "Bootstrap required"
bootstrap_configure
fi
# Finally, we need to run builder.inc.sh, if it hasn't already been run
if [[ -z ${THIS_SCRIPT_PATH+x} ]] && [[ -f "$(dirname "$THIS_SCRIPT")/_common/builder.inc.sh" ]]; then
source "$(dirname "$THIS_SCRIPT")/_common/builder.inc.sh"
# Bootstrapped scripts always run from their own folder (probably $REPO_ROOT),
# but only do this on first-run, not if re-sourced with bootstrap_configure
cd "$THIS_SCRIPT_PATH"
fi