-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
266 lines (206 loc) · 6.2 KB
/
justfile
File metadata and controls
266 lines (206 loc) · 6.2 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
##
# Build Tasks
##
cache_dir := justfile_directory() + "/cache"
chk_dir := justfile_directory() + "/chk"
tmp_dir := "/tmp/wp-core-checksums"
# Build and Clean.
default: build clean
# Build!
@build: _prereq
just _download-list
just _download-cores
just _hash-cores
# Generate a version list.
find "{{ chk_dir }}" -name '*.md5' -type f -exec basename {} \; | sed 's/.md5//g' | sort -u > "{{ justfile_directory() }}/versions.txt"
# Fix permissions (in case of Docker, etc.)
just _fix-chown "{{ cache_dir }}"
just _fix-chown "{{ chk_dir }}"
# Cleanup.
[ ! -f "{{ tmp_dir }}/list.txt" ] || rm "{{ tmp_dir }}/list.txt"
echo "Success! All checksums have been generated."
# Clean Cache.
@clean: _prereq
echo "Cleaning Up…"
find "{{ cache_dir }}" -type f -delete
# Checksum Directory.
_chk-dir VERSION:
#!/usr/bin/env bash
set -e
if [[ "{{ VERSION }}" =~ ^[0-9]+\. ]]; then
echo -n "{{ chk_dir }}/$( echo "{{ VERSION }}" | cut -d. -f1 )"
exit 0
fi
echo "Version doesn't look right: {{ VERSION }}"
exit 1
# Fetch Release List.
_download-list:
#!/usr/bin/env bash
set -e
# Already have it?
if [ -f "{{ tmp_dir }}/list.txt" ]; then
exit 0
fi
echo "Fetching Release List"
# Download!
wget -q -O- https://wordpress.org/download/releases/ | \
grep -oh -E '"https://wordpress.org/wordpress-[0-9.a-zA-Z-]+.zip"' | \
grep -v IIS | \
grep -v '\-mu\-' | \
sed 's/"//g' | \
sort -u > "{{ tmp_dir }}/list2.txt"
# Compare with what we already have.
[ ! -f "{{ tmp_dir }}/list.txt" ] || rm "{{ tmp_dir }}/list.txt"
while read URL; do
FILE="$( basename "$URL" )"
VERSION="${FILE%%.zip}"
VERSION="${VERSION:10}"
DIR="$( just _chk-dir "$VERSION" )"
if [ ! -f "$DIR/$VERSION.md5" ]; then
echo "$URL" >> "{{ tmp_dir }}/list.txt"
fi
done <"{{ tmp_dir }}/list2.txt"
# Clean up.
rm "{{ tmp_dir }}/list2.txt"
exit 0
# Fetch Packages.
_download-cores:
#!/usr/bin/env bash
set -e
# Already have everything?
if [ ! -f "{{ tmp_dir }}/list.txt" ]; then
exit 0
fi
echo "Fetching Core Packages"
while read URL; do
FILE="$( basename "$URL" )"
VERSION="${FILE%%.zip}"
VERSION="${VERSION:10}"
if [ ! -f "{{ cache_dir }}/$VERSION.zip" ]; then
echo " Downloading $VERSION"
wget -q -O "{{ cache_dir }}/$VERSION.zip" "$URL"
wget -q -O "{{ cache_dir }}/$VERSION.md5" "$URL.md5"
md5sum "{{ cache_dir }}/$VERSION.zip" | grep -q "$( cat "{{ cache_dir }}/$VERSION.md5" )"
if [ $? -ne 0 ]; then
echo "The archive did not match its own checksum!"
exit 1
fi
fi
done <"{{ tmp_dir }}/list.txt"
exit 0
# Generate the Hashes!
_hash-cores:
#!/usr/bin/env bash
set -e
# Already have everything?
if [ ! -f "{{ tmp_dir }}/list.txt" ]; then
exit 0
fi
while read URL; do
FILE="$( basename "$URL" )"
VERSION="${FILE%%.zip}"
VERSION="${VERSION:10}"
if [ -f "{{ cache_dir }}/$VERSION.zip" ]; then
just _hash-core "$VERSION"
fi
done <"{{ tmp_dir }}/list.txt"
exit 0
# Generate the Hashes (Single)!
_hash-core VERSION:
#!/usr/bin/env bash
set -e
if [ ! -f "{{ cache_dir }}/{{ VERSION }}.zip" ]; then
echo "Invalid version: {{ VERSION }}"
exit 1
fi
# Skip it? If we already have all the checksums, there's nothing to do.
DIR="$( just _chk-dir "{{ VERSION }}" )"
if [ -f "$DIR/{{ VERSION }}.b3" ]; then
if [ -f "$DIR/{{ VERSION }}.md5" ]; then
if [ -f "$DIR/{{ VERSION }}.sha256" ]; then
if [ -f "$DIR/{{ VERSION }}.sha512" ]; then
exit 0
fi
fi
fi
fi
echo " Hashing {{ VERSION }}"
# Unpack it.
[ ! -d "{{ tmp_dir }}/extract" ] || rm -rf "{{ tmp_dir }}/extract"
mkdir "{{ tmp_dir }}/extract"
unzip -q "{{ cache_dir }}/{{ VERSION }}.zip" -d "{{ tmp_dir }}/extract"
ROOT="$( find "{{ tmp_dir }}/extract/" -mindepth 1 -maxdepth 1 -type d | head -n 1 )"
if [ -n "$ROOT" ]; then
# Get rid of bundled plugins and themes, and the sample config.
[ ! -f "$ROOT/wp-config-sample.php" ] || rm "$ROOT/wp-config-sample.php"
if [ -d "$ROOT/wp-content/plugins" ]; then
if [ -f "$ROOT/wp-content/plugins/index.php" ]; then
mv "$ROOT/wp-content/plugins/index.php" "{{ tmp_dir }}/index.php"
rm -rf "$ROOT/wp-content/plugins"
mkdir "$ROOT/wp-content/plugins"
mv "{{ tmp_dir }}/index.php" "$ROOT/wp-content/plugins/index.php"
else
rm -rf "$ROOT/wp-content/plugins"
fi
fi
if [ -d "$ROOT/wp-content/themes" ]; then
if [ -f "$ROOT/wp-content/themes/index.php" ]; then
mv "$ROOT/wp-content/themes/index.php" "{{ tmp_dir }}/index.php"
rm -rf "$ROOT/wp-content/themes"
mkdir "$ROOT/wp-content/themes"
mv "{{ tmp_dir }}/index.php" "$ROOT/wp-content/themes/index.php"
else
rm -rf "$ROOT/wp-content/themes"
fi
fi
cd "$ROOT"
# Generate checksums.
[ -d "$DIR" ] || mkdir "$DIR"
find . -type f -print0 | sort -z | xargs -0 b3sum > "$DIR/{{ VERSION }}.b3"
find . -type f -print0 | sort -z | xargs -0 md5sum > "$DIR/{{ VERSION }}.md5"
find . -type f -print0 | sort -z | xargs -0 sha256sum > "$DIR/{{ VERSION }}.sha256"
find . -type f -print0 | sort -z | xargs -0 sha512sum > "$DIR/{{ VERSION }}.sha512"
# Strip leading ./ from paths.
sd -s " ./" " " "$DIR/{{ VERSION }}.b3"
sd -s " ./" " " "$DIR/{{ VERSION }}.md5"
sd -s " ./" " " "$DIR/{{ VERSION }}.sha256"
sd -s " ./" " " "$DIR/{{ VERSION }}.sha512"
fi
cd "{{ justfile_directory() }}"
rm -rf "{{ tmp_dir }}/extract"
exit 0
# Setup and Requirements Checks.
_prereq:
#!/usr/bin/env bash
set -e
[ -d "{{ cache_dir }}" ] || mkdir "{{ cache_dir }}"
[ -d "{{ chk_dir }}" ] || mkdir "{{ chk_dir }}"
[ -d "{{ tmp_dir }}" ] || mkdir "{{ tmp_dir }}"
if [ ! -d "{{ tmp_dir }}" ]; then
echo "Missing tmp dir!"
exit 1
fi
if [ -z "$( command -v b3sum)" ]; then
if [ -n "$( command -v cargo )" ]; then
cargo install b3sum
fi
fi
just _prereq-app b3sum || exit 1
just _prereq-app md5sum || exit 1
just _prereq-app sha256sum || exit 1
just _prereq-app sha512sum || exit 1
just _prereq-app sd || exit 1
just _prereq-app wget || exit 1
exit 0
# Make Sure Required App Exists.
_prereq-app BIN:
#!/usr/bin/env bash
set -e
if [ -z "$( command -v {{ BIN }} )" ]; then
echo "Missing {{ BIN }}."
exit 1
fi
exit 0
# Fix file/directory ownership.
@_fix-chown PATH:
[ ! -e "{{ PATH }}" ] || chown -R --reference="{{ justfile() }}" "{{ PATH }}"