-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
423 lines (366 loc) · 12.9 KB
/
Makefile
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/usr/bin/env make
#
# iocccsubmit - IOCCC submit server tool
#
# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby granted,
# provided that the above copyright, this permission notice and text
# this comment, and the disclaimer below appear in all of the following:
#
# supporting documentation
# source copies
# source works derived from this source
# binaries derived from this source or from derived source
#
# LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
# EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# chongo (Landon Curt Noll, http://www.isthe.com/chongo/index.html) /\oo/\
#
# Share and enjoy! :-)
#############
# utilities #
#############
AWK= awk
CHMOD= chmod
CHOWN= chown
CMP= cmp
CP= cp
ID= id
INSTALL= install
MKDIR= mkdir
TOUCH= touch
PYTHON= python3
RM= rm
SED= sed
SHELL= bash
######################
# target information #
######################
# V=@: do not echo debug statements (quiet mode)
# V=@ echo debug statements (debug / verbose mode)
#
V=@:
#V=@
# package version
#
VERSION= 0.11.9
# Python package name
#
PKG_NAME= iocccsubmit
# Python package source
#
PKG_SRC= ${PKG_NAME}/__init__.py ${PKG_NAME}/ioccc.py ${PKG_NAME}/ioccc_common.py
# polite English language words
#
# NOTE: See the comment in iocccsubmit/ioccc_common.py within the generate_password() function
# about how the polite English language words file is used, and in particular how
# the values of ${MIN_POLITE_WORD_LENGTH} and ${MAX_POLITE_WORD_LENGTH} were selected.
#
# These values are used by the make rebuild_pw_words rule below.
#
POLITE_ENGLISH_WORDS= /usr/local/src/lib/polite.english.words/polite.english.words.txt
MIN_POLITE_WORD_LENGTH= 4
MAX_POLITE_WORD_LENGTH= 10
# etc read-only directory source owned by root
#
ETC_RO_SRC= etc/pw.words etc/requirements.txt
# IOCCC submit server password file
#
# If ${PW} does not list, during install copy it from ${INIT_PW}
#
# IMPORTANT: Do NOT add ${PW} to ${ETC_RW_SRC}, it is created by
# make install and installed by make root_install.
#
INIT_PW= etc/init.iocccpasswd.json
PW= etc/iocccpasswd.json
# IOCCC submit server IOCCC open and close dates
#
# If ${STATE} does not list, during install copy it from ${INIT_STATE}
#
# IMPORTANT: Do NOT add ${STATE} to ${ETC_RW_SRC}, it is created by
# make install and installed by make root_install.
#
INIT_STATE= etc/init.state.json
STATE= etc/state.json
# etc read-write directory source owned by root
#
ETC_RW_SRC= ${INIT_PW} ${INIT_STATE} etc/iocccpasswd.lock etc/state.lock
# all etc src
#
ETC_SRC= ${ETC_RO_SRC} ${ETC_RW_SRC}
# static directory source
#
STATIC_SRC= static/ioccc.css static/ioccc.js static/ioccc.png static/login-example.jpg \
static/favicon.ico static/robots.txt static/apple-touch-icon.png \
static/apple-touch-icon-precomposed.png
# templates directory source
#
TEMPLATES_SRC= templates/login.html templates/not-open.html templates/passwd.html \
templates/submit.html
# wsgi code to install for apache to execute
#
WSGI_SRC= wsgi/ioccc.wsgi
# files to install under ${DOCROOT}
#
INSTALL_UNDER_DOCROOT= ${ETC_SRC} ${STATIC_SRC} ${TEMPLATES_SRC} ${WSGI_SRC}
# Apache document root directory where non-python python package files are installed under
#
# We install ${INSTALL_UNDER_DOCROOT} files under this directory, sometimes in sub-directories.
#
DOCROOT= /var/ioccc
# The tool to perform SELinux setup
#
SELINUX_SET= bin/selinux.set.sh
SELINUX_UNSET= bin/selinux.unset.sh
# executable scripts that are not part of the python module
#
# Executable files to install under ${DESTDIR}.
#
# NOTE: bin/pychk.sh is only needed for testing and thus is not needed under ${DESTDIR}.
#
BIN_SRC= bin/genflaskkey.sh bin/ioccc_date.py bin/ioccc_passwd.py bin/set_slot_status.py \
bin/ioccc_submit.py bin/root_install.sh bin/ls_loaded_slotdir.sh bin/stage.py \
${SELINUX_SET} ${SELINUX_UNSET}
# scripts that are not run, nor installed on the submit server
#
SBIN_SRC = sbin/all-collect.sh sbin/collect.sh sbin/submitted_slots.sh
# tool to generate the secret Flask key
#
GENFLASHKEY= bin/genflaskkey.sh
# location of the secret Flask key
#
FLASK_KEY= etc/.secret
# location of the secret
# Where to install programs that are not part of the python module.
#
# We install ${BIN_SRC} executables under this directory.
#
DESTDIR= /usr/local/bin
# user to root_install under
#
#USER= ioccc
USER= apache
# user to root_install under
#
#GROUP= ioccc
GROUP= apache
# ioccc syslog file
#
IOCCC_SYSLOG= /var/log/ioccc
# what to build
#
TARGETS= dist/${PKG_NAME}-${VERSION}-py3-none-any.whl
######################################
# all - default rule - must be first #
######################################
all: ${TARGETS}
#################################################
# .PHONY list of rules that do not create files #
#################################################
.PHONY: all configure clean clobber nuke install \
root_install root_setup revenv wheel venv_install reflaskkey rebuild_pw_words
###############
# build rules #
###############
setup.cfg: setup.cfg.template etc/requirements.txt
${V} echo DEBUG =-= $@ start =-=
${RM} -f $@ tmp.requirements.txt.tmp
${SED} -e 's/^/ /' < etc/requirements.txt > tmp.requirements.txt.tmp
${SED} -e 's/@@VERSION@@/${VERSION}/' \
-e 's/@@PKG_NAME@@/${PKG_NAME}/' \
-e '/^install_requires =/ {' -e 'r tmp.requirements.txt.tmp' -e '}' \
< setup.cfg.template > $@
${RM} -f tmp.requirements.txt.tmp
${V} echo DEBUG =-= $@ end =-=
venv: etc/requirements.txt setup.cfg
${V} echo DEBUG =-= $@ start =-=
${RM} -rf venv __pycache__
${PYTHON} -m venv venv
# was: pip install --upgrade ...
source ./venv/bin/activate && \
${PYTHON} -m pip install --upgrade pylint pip setuptools wheel build && \
${PYTHON} -m pip install -r etc/requirements.txt
${V} echo DEBUG =-= $@ end =-=
build/lib/submittool: ${PKG_SRC} venv
${V} echo DEBUG =-= $@ start =-=
# was: python3 setup.py build
source ./venv/bin/activate && \
${PYTHON} -c 'import setuptools; setuptools.setup()' sdist
${V} echo DEBUG =-= $@ end =-=
dist/${PKG_NAME}-${VERSION}-py3-none-any.whl: ${PKG_SRC} venv build/lib/submittool
${V} echo DEBUG =-= $@ start =-=
# was: python3 setup.py bdist_wheel
source ./venv/bin/activate && \
${PYTHON} -m build --sdist --wheel
${V} echo DEBUG =-= $@ end =-=
#################
# utility rules #
#################
# wheel - make the python package wheel
#
wheel: dist/${PKG_NAME}-${VERSION}-py3-none-any.whl
${V} echo DEBUG =-= $@ start =-=
${V} echo DEBUG =-= $@ end =-=
# revenv - force to rebuild the python virtual environment
#
revenv:
${V} echo DEBUG =-= $@ start =-=
${RM} -rf venv __pycache__
${PYTHON} -m venv venv
# was: pip3 install --upgrade ...
source ./venv/bin/activate && \
${PYTHON} -m pip install --upgrade pylint pip setuptools wheel build && \
${PYTHON} -m pip install -r etc/requirements.txt
${V} echo DEBUG =-= $@ end =-=
# install the python package under the python virtual environment
#
venv_install: venv dist/${PKG_NAME}-${VERSION}-py3-none-any.whl
${V} echo DEBUG =-= $@ start =-=
# was: python3 setup.py install
source ./venv/bin/activate && \
${PYTHON} -m pip install .
@echo
@echo 'Do not forget to:'
@echo
@echo ' source venv/bin/activate'
@echo
${V} echo DEBUG =-= $@ end =-=
# Flask secret key - generate if missing or empty
#
# NOTE: Because we do not use -F, this rule will do nothing
# if ${FLASK_KEY} is a non-empty file.
#
${FLASK_KEY}:
${V} echo DEBUG =-= $@ start =-=
${GENFLASHKEY} ${FLASK_KEY}
${V} echo DEBUG =-= $@ end =-=
# force Flask secret key to be re-generated
#
reflaskkey:
${V} echo DEBUG =-= $@ start =-=
${GENFLASHKEY} -F ${FLASK_KEY}
${V} echo DEBUG =-= $@ end =-=
# rebuild etc/pw.words from POLITE_ENGLISH_WORDS
#
rebuild_pw_words: ${POLITE_ENGLISH_WORDS}
${RM} -f etc/pw.words
${AWK} '{ if (length($$0) >= ${MIN_POLITE_WORD_LENGTH} && \
length($$0) <= ${MAX_POLITE_WORD_LENGTH}) print $$0; }' \
"${POLITE_ENGLISH_WORDS}" > etc/pw.words
# The polite English language words file
#
${POLITE_ENGLISH_WORDS}:
if [[ ! -f ${POLITE_ENGLISH_WORDS} ]]; then \
echo "ERROR: polite English language words file not found: ${POLITE_ENGLISH_WORDS}" 1>&2; \
echo "Notice: try: git clone https://github.com/lcn2/polite.english.words.git" 1>&2; \
echo "Notice: then do: cd polite.english.words.git && sudo make clobber all install"; 1>&2; \
exit 1; \
fi
###################################
# standard Makefile utility rules #
###################################
configure: setup.cfg
${V} echo DEBUG =-= $@ start =-=
${V} echo DEBUG =-= $@ end =-=
clean:
${V} echo DEBUG =-= $@ start =-=
${RM} -f tmp.requirements.txt.tmp
${V} echo DEBUG =-= $@ end =-=
clobber: clean
${V} echo DEBUG =-= $@ start =-=
${RM} -rf venv __pycache__ ${PKG_NAME}/__pycache__
${RM} -rf dist build ${PKG_NAME}.egg-info
${RM} -f setup.cfg
${V} echo DEBUG =-= $@ end =-=
# remove active working elements including users and staged and unexpected
#
nuke: clobber
${V} echo DEBUG =-= $@ start =-=
${RM} -rf users
${RM} -rf staged unexpected
${V} echo DEBUG =-= $@ end =-=
install: ${FLASK_KEY} ${INIT_PW} ${INIT_STATE} venv_install
${V} echo DEBUG =-= $@ start =-=
@if [[ ! -s ${PW} ]]; then \
echo ${CP} -v -f ${INIT_PW} ${PW}; \
${CP} -v -f ${INIT_PW} ${PW}; \
echo ${CHMOD} -v 0664 ${PW}; \
${CHMOD} -v 0664 ${PW}; \
fi
@if [[ ! -s ${STATE} ]]; then \
echo ${CP} -v -f ${INIT_STATE} ${STATE}; \
${CP} -v -f ${INIT_STATE} ${STATE}; \
echo ${CHMOD} -v 0664 ${STATE}; \
${CHMOD} -v 0664 ${STATE}; \
fi
@mkdir -p staged unexpected
@echo 'This only installs locally into a python virtual environment.'
@echo
@echo 'If you are on the submit sever, next as root, run:'
@echo
@echo ' make root_install'
@echo
${V} echo DEBUG =-= $@ end =-=
sbin_install: ${SBIN_SRC}
${V} echo DEBUG =-= $@ start =-=
@if [[ -d ${DOCROOT} ]]; then echo "ERROR: dir cannot exist: ${DOCROOT}} to make $@" 1>&2; exit 1; fi
@if [[ $$(${ID} -u) != 0 ]]; then echo "ERROR: must be root to make $@" 1>&2; exit 2; fi
${INSTALL} -o root -g root -m 0755 -d ${DESTDIR}
${INSTALL} -o root -g root -m 0555 ${SBIN_SRC} ${DESTDIR}
${V} echo DEBUG =-= $@ start =-=
# as root: after root_setup, setup ${DOCROOT} under for SELinux
#
# NOTE: ${DOCROOT} must be a directory before this rule can function.
# This is a "firewall" against installing on the wrong system.
#
root_install: ${SELINUX_SET} root_setup
${V} echo DEBUG =-= $@ start =-=
@if [[ ! -d ${DOCROOT} ]]; then echo "ERROR: dir must exist: ${DOCROOT}} to make $@" 1>&2; exit 1; fi
@if [[ $$(${ID} -u) != 0 ]]; then echo "ERROR: must be root to make $@" 1>&2; exit 2; fi
@echo
@echo About to setup ${DOCROOT} for SELinux
@echo
${SELINUX_SET}
@echo
@echo finished setup ${DOCROOT} for SELinux
@echo
${V} echo DEBUG =-= $@ start =-=
# as root: setup directories and permissions
#
# NOTE: ${DOCROOT} must be a directory before this rule can function.
# This is a "firewall" against installing on the wrong system.
#
root_setup: ${INSTALL_UNDER_DOCROOT} ${PW} ${STATE} ${BIN_SRC} ${FLASHKEY} dist/${PKG_NAME}-${VERSION}-py3-none-any.whl
${V} echo DEBUG =-= $@ start =-=
@if [[ ! -d ${DOCROOT} ]]; then echo "ERROR: dir must exist: ${DOCROOT} to make $@" 1>&2; exit 1; fi
@if [[ $$(${ID} -u) != 0 ]]; then echo "ERROR: must be root to make $@" 1>&2; exit 2; fi
# was: python3 setup.py install
${PYTHON} -m pip install --force-reinstall .
${INSTALL} -o ${USER} -g ${GROUP} -m 0555 -d ${DOCROOT}
${INSTALL} -o ${USER} -g ${GROUP} -m 0755 -d ${DOCROOT}/etc
${INSTALL} -o ${USER} -g ${GROUP} -m 0444 ${ETC_RO_SRC} ${DOCROOT}/etc
${INSTALL} -o ${USER} -g ${GROUP} -m 0664 ${ETC_RW_SRC} ${PW} ${STATE} ${DOCROOT}/etc
${INSTALL} -o ${USER} -g ${GROUP} -m 0555 -d ${DOCROOT}/static
${INSTALL} -o ${USER} -g ${GROUP} -m 0444 ${STATIC_SRC} ${DOCROOT}/static
${INSTALL} -o ${USER} -g ${GROUP} -m 0555 -d ${DOCROOT}/templates
${INSTALL} -o ${USER} -g ${GROUP} -m 0444 ${TEMPLATES_SRC} ${DOCROOT}/templates
${INSTALL} -o ${USER} -g ${GROUP} -m 0755 -d ${DOCROOT}/users
${INSTALL} -o ${USER} -g ${GROUP} -m 0755 -d ${DOCROOT}/staged
${INSTALL} -o ${USER} -g ${GROUP} -m 0755 -d ${DOCROOT}/unexpected
${INSTALL} -o ${USER} -g ${GROUP} -m 0755 -d ${DOCROOT}/wsgi
${INSTALL} -o ${USER} -g ${GROUP} -m 0555 ${WSGI_SRC} ${DOCROOT}/wsgi
${INSTALL} -o ${USER} -g ${GROUP} -m 0440 ${FLASK_KEY} ${DOCROOT}/etc/.secret
${INSTALL} -o root -g root -m 0755 -d ${DESTDIR}
${INSTALL} -o root -g root -m 0555 ${BIN_SRC} ${DESTDIR}
${TOUCH} ${IOCCC_SYSLOG}
${CHOWN} root:root ${IOCCC_SYSLOG}
${CHMOD} 0600 ${IOCCC_SYSLOG}
${V} echo DEBUG =-= $@ end =-=