1
|
root := .
|
2
|
include lib/common.Makefile
|
3
|
|
4
|
|
5
|
##### Vars/functions
|
6
|
|
7
|
# Make
|
8
|
SHELL := /bin/bash
|
9
|
|
10
|
# Paths
|
11
|
bin := bin
|
12
|
|
13
|
##### Environment
|
14
|
|
15
|
export PGOPTIONS = --client-min-messages=WARNING
|
16
|
|
17
|
##### General targets
|
18
|
|
19
|
remake: _always clean
|
20
|
$(MAKE)
|
21
|
# re-run make so that cache of existing files is reset
|
22
|
|
23
|
%/remake: _always
|
24
|
$(MAKE) $(@D)/clean
|
25
|
$(MAKE) $(@D)/
|
26
|
# re-run make so that cache of existing files is reset
|
27
|
|
28
|
%-remake: _always
|
29
|
rm -f $*
|
30
|
$(MAKE) $*
|
31
|
# re-run make so that cache of existing files is reset
|
32
|
|
33
|
##### Installation
|
34
|
|
35
|
# public must be installed *after* inputs because some views depend on inputs
|
36
|
install: _always core mysql inputs/download inputs/install \
|
37
|
schemas/public/install test
|
38
|
@$(done)
|
39
|
|
40
|
uninstall: _always rm_mysql rm_core ;
|
41
|
|
42
|
reinstall: _always uninstall install ;
|
43
|
|
44
|
##### Core: VegBIEN DB and dependencies
|
45
|
|
46
|
core: _always $(call forOs,apache python php postgres misc) db
|
47
|
@$(done)
|
48
|
|
49
|
rm_core: _always rm_db ;
|
50
|
|
51
|
reinstall_core: _always rm_core core ;
|
52
|
|
53
|
##### Apache
|
54
|
|
55
|
apache-Linux: _always
|
56
|
# Apache 2.4
|
57
|
-sudo apt-get --yes install python-software-properties
|
58
|
-sudo apt-add-repository ppa:ptn107/apache
|
59
|
-sudo apt-add-repository ppa:nathan-renniewaldock/apache2.4-php
|
60
|
-sudo apt-get update
|
61
|
-sudo apt-get --yes install apache2
|
62
|
-sudo apt-get --yes purge libapache2-mod-php5
|
63
|
-sudo apt-get --yes install libapache2-mod-php5
|
64
|
|
65
|
apache-Darwin: _always ;
|
66
|
|
67
|
##### Python
|
68
|
|
69
|
python-Linux: _always
|
70
|
-sudo apt-get --yes install python
|
71
|
-sudo apt-get --yes install python3
|
72
|
-sudo apt-get --yes install python-dev
|
73
|
-sudo apt-get --yes install python-dateutil
|
74
|
-sudo apt-get --yes install python-parallel
|
75
|
-sudo apt-get --yes install python-profiler
|
76
|
-sudo apt-get --yes install python-pip
|
77
|
-sudo apt-get --yes install pymetrics
|
78
|
-sudo pip install ordereddict
|
79
|
-sudo pip install pp
|
80
|
|
81
|
python-Darwin: _always
|
82
|
@# Python 2 comes preinstalled
|
83
|
@echo $(emph)'Installing Python 3.2 on Mac OS X:'$(endEmph)
|
84
|
@echo 'Download it: http://www.python.org/ftp/python/3.2.3/python-3.2.3-macosx10.6.dmg'
|
85
|
@echo 'Open the disk image'
|
86
|
@echo 'Run the installer in it'
|
87
|
@$(wait)
|
88
|
@echo $(emph)'Installing python-dateutil on Mac OS X:'$(endEmph)
|
89
|
@echo 'Download it for Python 2: http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz'
|
90
|
@echo 'Extract the archive'
|
91
|
@echo 'Change to the directory of the extracted files'
|
92
|
@echo 'Run python setup.py build'
|
93
|
@echo 'Run sudo python setup.py install'
|
94
|
@echo "Run python -c 'import dateutil'"
|
95
|
@echo 'Download it for Python 3: http://labix.org/download/python-dateutil/python-dateutil-2.0.tar.gz'
|
96
|
@echo 'Extract the archive'
|
97
|
@echo 'Change to the directory of the extracted files'
|
98
|
@echo 'Run python3 setup.py build'
|
99
|
@echo 'Run sudo python3 setup.py install'
|
100
|
@echo "Run python3 -c 'import dateutil'"
|
101
|
@$(wait)
|
102
|
@echo $(emph)'Installing pip on Mac OS X:'$(endEmph)
|
103
|
@echo 'Follow the instructions at http://www.pip-installer.org/en/latest/installing.html'
|
104
|
@$(wait)
|
105
|
|
106
|
##### PHP
|
107
|
|
108
|
php-Linux: _always
|
109
|
-sudo apt-get --yes install php-http-request
|
110
|
|
111
|
php-Darwin: _always
|
112
|
@echo $(emph)'Installing PHP PEAR and HTTP_Request on Mac OS X:'$(endEmph)
|
113
|
@echo 'Download http://pear.php.net/go-pear.phar'
|
114
|
@echo 'Change to the directory of the downloaded file'
|
115
|
@echo 'Run php -d detect_unicode=0 go-pear.phar'
|
116
|
@echo 'Whenever prompted, press Enter to select default options'
|
117
|
@echo 'Add $$HOME/pear/bin to your $$PATH'
|
118
|
@echo 'Add $(HOME)/pear/share/pear to your php.ini include_path'
|
119
|
@echo 'If needed, set $$PHPRC to your php.ini'
|
120
|
@echo "Run pear install HTTP_Request"
|
121
|
@echo 'To run a php command: php -c <php.ini-path> ...'
|
122
|
@$(wait)
|
123
|
|
124
|
##### PostgreSQL
|
125
|
|
126
|
define editPhppgadmin
|
127
|
-sudo patch /etc/phppgadmin/config.inc.php lib/phpPgAdmin.config.inc.php.diff
|
128
|
sudo cp -n /usr/share/phppgadmin/login.php /usr/share/phppgadmin/login.php.old
|
129
|
-sudo patch /usr/share/phppgadmin/login.php lib/phpPgAdmin.login.php.diff
|
130
|
endef
|
131
|
# ignore errors if patch has already been applied
|
132
|
|
133
|
editPhppgadminApacheConf = echo $$'1\n,s/deny from all/allow from all/\nwq'|\
|
134
|
sudo ed --loose-exit-status --verbose /etc/phppgadmin/apache.conf
|
135
|
|
136
|
apacheConf := /etc/apache2/apache2.conf
|
137
|
apacheConfPhppgadminLine := Include /etc/phppgadmin/apache.conf
|
138
|
editApacheConfForPhppgadmin =\
|
139
|
$(if $(shell grep -F "$(apacheConfPhppgadminLine)" $(apacheConf)),,\
|
140
|
$(call sudoAppend,$(apacheConf),\n$(apacheConfPhppgadminLine)))
|
141
|
|
142
|
nonApacheOnPort80 = $(shell sudo lsof -i :80|tail -n +2|grep -v -F apache2)
|
143
|
editApachePortsConf = echo $$'1\n,s/\\b80\\b/8080/g\nwq'|\
|
144
|
sudo ed --loose-exit-status --verbose /etc/apache2/ports.conf
|
145
|
|
146
|
asAdmin := sudo -E -u postgres
|
147
|
asBien := sudo -E -u bien
|
148
|
pgVersion = "$$(env minor=1 bin/pg_version)"
|
149
|
|
150
|
linuxPostgresDir := /etc/postgresql/9.1/main
|
151
|
define pg_ctl-Linux
|
152
|
$(asAdmin) /etc/init.d/postgresql $(1)
|
153
|
endef
|
154
|
|
155
|
macPostgresDir := /Library/PostgreSQL/9.1
|
156
|
define macUsePostgresLib
|
157
|
sudo mv $(libDest) $(libDest).old||sudo rm -f $(libDest)
|
158
|
sudo ln -s $(macPostgresDir)/lib/$(1) $(libDest)
|
159
|
|
160
|
endef
|
161
|
libDest = /usr/lib/$(1)
|
162
|
|
163
|
macPostgresLibs := libcrypto libssl
|
164
|
macPostgresLibs := $(macPostgresLibs) $(macPostgresLibs:%=%.1.0.0)
|
165
|
macPostgresLibs := $(macPostgresLibs:%=%.dylib)
|
166
|
|
167
|
define pg_ctl-Darwin
|
168
|
$(asAdmin) pg_ctl -D $(macPostgresDir)/data -l $(macPostgresDir)/postgres.log $(1)
|
169
|
sleep 2
|
170
|
endef
|
171
|
|
172
|
confirmPostgresReload = $(call confirm,Modifying postgresql.conf and pg_hba.conf)
|
173
|
|
174
|
define postgresReload-Linux
|
175
|
@$(confirmPostgresReload)
|
176
|
@echo $(emph)'kernel.shmmax must be set to at least 4GB minus 1 byte:'$(endEmph)
|
177
|
@echo 'Append the following to /etc/sysctl.conf:'
|
178
|
@echo 'kernel.shmmax=4294967295'
|
179
|
@$(wait)
|
180
|
chmod a+r schemas/*.conf || $(asBien) chmod a+r schemas/*.conf
|
181
|
-$(asAdmin) mv -n $(linuxPostgresDir)/postgresql.conf $(linuxPostgresDir)/postgresql.conf.old
|
182
|
$(asAdmin) cp --preserve=timestamps schemas/postgresql.conf $(linuxPostgresDir)/postgresql.conf
|
183
|
-$(asAdmin) mv -n $(linuxPostgresDir)/pg_hba.conf $(linuxPostgresDir)/pg_hba.conf.old
|
184
|
$(asAdmin) cp --preserve=timestamps schemas/pg_hba.conf $(linuxPostgresDir)/pg_hba.conf
|
185
|
@echo $(emph)'restart PostgreSQL manually:'$(endEmph)
|
186
|
@echo $(call pg_ctl-Linux,restart)
|
187
|
@$(wait)
|
188
|
|
189
|
endef
|
190
|
|
191
|
define postgresReload-Darwin
|
192
|
@$(confirmPostgresReload)
|
193
|
chmod a+r schemas/*.conf
|
194
|
-$(asAdmin) mv -n $(macPostgresDir)/data/postgresql.conf $(macPostgresDir)/data/postgresql.conf.old
|
195
|
$(asAdmin) cp schemas/postgresql.Mac.conf $(macPostgresDir)/data/postgresql.conf
|
196
|
-$(asAdmin) mv -n $(macPostgresDir)/data/pg_hba.conf $(macPostgresDir)/data/pg_hba.conf.old
|
197
|
$(asAdmin) cp schemas/pg_hba.Mac.conf $(macPostgresDir)/data/pg_hba.conf
|
198
|
$(call pg_ctl-Darwin,restart)
|
199
|
|
200
|
endef
|
201
|
|
202
|
postgres_reload: _always
|
203
|
$($(call forOs,postgresReload))
|
204
|
|
205
|
postgres-Linux: _always
|
206
|
-sudo apt-get --yes install postgresql
|
207
|
-sudo apt-get --yes install postgresql-contrib
|
208
|
-sudo apt-get --yes install postgresql-plpython3-$(pgVersion)
|
209
|
-sudo apt-get --yes install libpq-dev
|
210
|
-sudo apt-get --yes install postgresql-$(pgVersion)-postgis
|
211
|
-sudo apt-get --yes install phppgadmin
|
212
|
$(editPhppgadmin)
|
213
|
$(editPhppgadminApacheConf)
|
214
|
$(editApacheConfForPhppgadmin)
|
215
|
$(if $(nonApacheOnPort80),$(editApachePortsConf))
|
216
|
-sudo apache2ctl restart
|
217
|
-sudo pip install psycopg2
|
218
|
-$(MAKE) $(postgresReload-Linux)
|
219
|
# run pg_version inline because it needs postgresql to be installed first
|
220
|
# ignore errors if conf files already edited
|
221
|
|
222
|
postgres-Darwin: _always
|
223
|
@echo $(emph)'Installing PostgreSQL on Mac OS X:'$(endEmph)
|
224
|
@echo 'Download it using the topmost "Mac OS X" link at http://http://www.enterprisedb.com/products-services-training/pgdownload'
|
225
|
@echo 'Open the disk image'
|
226
|
@echo 'Run the installer in it'
|
227
|
@$(wait)
|
228
|
$(foreach lib,$(macPostgresLibs),$(call macUsePostgresLib,$(lib)))
|
229
|
-$(MAKE) $(postgresReload-Darwin)
|
230
|
|
231
|
postgres-: _always ; # other OSes
|
232
|
|
233
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
234
|
psqlAsAdmin := $(asAdmin) psql $(psqlOpts)
|
235
|
# -E preserves env vars so PGOPTIONS is passed to psql
|
236
|
psqlAsAdminVegbien := $(psqlAsAdmin) vegbien
|
237
|
bienPassword := $(shell cat config/bien_password)
|
238
|
bienReadPassword := $(shell cat config/bien_read_password)
|
239
|
|
240
|
##### Misc.
|
241
|
|
242
|
misc-Linux: _always
|
243
|
cp -p "$(shell which dotlockfile)" bin/
|
244
|
|
245
|
misc-Darwin: _always ;
|
246
|
|
247
|
##### VegBIEN DB
|
248
|
|
249
|
#### DB and users
|
250
|
|
251
|
confirmRmDb = $(call confirm,WARNING: This will delete your entire VegBIEN\
|
252
|
DB!,This includes all archived imports and staging tables.)
|
253
|
|
254
|
confirmRmPublicSchema = $(call confirm,WARNING: This will delete the current\
|
255
|
public schema of your VegBIEN DB!,To save it: make schemas/rotate)
|
256
|
|
257
|
rmPublicSchema := $(call rmSchemaCmd,public)
|
258
|
|
259
|
db: mk_db rm_initial_public schemas/install _always ;
|
260
|
|
261
|
mk_db: _always
|
262
|
-echo "CREATE USER public_;"|$(psqlAsAdmin)
|
263
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
264
|
-echo "CREATE USER bien_read PASSWORD '$(bienReadPassword)' IN ROLE bien \
|
265
|
NOINHERIT;"|$(psqlAsAdmin)
|
266
|
-echo "CREATE DATABASE vegbien WITH OWNER bien TEMPLATE template1 \
|
267
|
ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';"|$(psqlAsAdmin)
|
268
|
-echo "CREATE EXTENSION hstore SCHEMA pg_catalog;"|$(psqlAsAdminVegbien)
|
269
|
-$(asAdmin) createlang plpython3u vegbien
|
270
|
-cat config/users.sql|$(psqlAsAdmin)
|
271
|
# ignore errors if user/database/etc. exists
|
272
|
|
273
|
rm_initial_public: _always
|
274
|
@$(confirmRmPublicSchema)
|
275
|
echo $(rmPublicSchema)|$(psqlAsAdminVegbien)
|
276
|
# drop public schema *as admin* because it starts out owned by postgres
|
277
|
|
278
|
rm_db: _always
|
279
|
@$(confirmRmDb)
|
280
|
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
281
|
echo "DROP USER IF EXISTS bien_read;"|$(psqlAsAdmin)
|
282
|
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
|
283
|
echo "DROP USER IF EXISTS public_;"|$(psqlAsAdmin)
|
284
|
|
285
|
reinstall_db: _always rm_db db ;
|
286
|
|
287
|
##### MySQL
|
288
|
|
289
|
mysql: _always $(call forOs,mysql) mysql_users
|
290
|
@$(done)
|
291
|
|
292
|
rm_mysql: _always rm_mysql_users ;
|
293
|
|
294
|
mysql-Linux: _always
|
295
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
296
|
@$(wait)
|
297
|
-sudo apt-get --yes install mysql-server
|
298
|
-sudo apt-get --yes install mysql-client
|
299
|
-sudo apt-get --yes install python-mysqldb
|
300
|
-sudo apt-get --yes install phpmyadmin
|
301
|
|
302
|
mysql-Darwin: _always
|
303
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
304
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
305
|
@echo 'Extract the archive'
|
306
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
307
|
@echo 'Run ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
308
|
@echo 'Run ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
309
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
310
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
311
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
312
|
@echo 'Change to the directory of the extracted files'
|
313
|
@echo 'Run python setup.py clean'
|
314
|
@echo 'Run python setup.py build'
|
315
|
@echo 'Run sudo python setup.py install'
|
316
|
@echo "Run python -c 'import MySQLdb'"
|
317
|
@$(wait)
|
318
|
|
319
|
mysql-: _always # other OSes
|
320
|
|
321
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
322
|
|
323
|
mysql_users: _always
|
324
|
-echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY '$(bienPassword)';"\
|
325
|
|$(mysqlAsRoot)
|
326
|
-echo "CREATE USER 'bien_read'@'%' IDENTIFIED BY '$(bienReadPassword)';"\
|
327
|
|$(mysqlAsRoot)
|
328
|
# ignore errors if user exists
|
329
|
|
330
|
rm_mysql_users: _always
|
331
|
-echo "DROP USER 'bien_read'@'localhost';"|$(mysqlAsRoot)
|
332
|
-echo "DROP USER 'bien'@'%';"|$(mysqlAsRoot)
|
333
|
# ignore errors if user exists
|
334
|
|
335
|
##### Datasources
|
336
|
|
337
|
inputs: _always inputs/all ;
|
338
|
|
339
|
inputs/install: _always
|
340
|
echo '. bin/reinstall_all; wait'|bash -s
|
341
|
|
342
|
import: _always import-msg inputs/import_scrub ;
|
343
|
import-msg: _always
|
344
|
@echo $(emph)"To import all inputs at once:"$(endEmph) . bin/import_all
|
345
|
@echo
|
346
|
|
347
|
scrub: _always inputs/.TNRS/tnrs/tnrs-remake ;
|
348
|
|
349
|
verify: _always inputs/verify
|
350
|
@$(done)
|
351
|
|
352
|
test: _always inputs/test
|
353
|
@$(done)
|
354
|
|
355
|
##### Testing
|
356
|
|
357
|
test-all: _always remake test missing_mappings
|
358
|
@$(done)
|
359
|
|
360
|
##### Subdir forwarding
|
361
|
|
362
|
# Must come last so overridden targets are not forwarded
|
363
|
|
364
|
define subdirTargets
|
365
|
$(subdir): _always
|
366
|
+$$(subMake)
|
367
|
|
368
|
$(subdir)%: _always
|
369
|
+$$(subMake)
|
370
|
.PRECIOUS: $(subdir)% # let subdir's Makefile decide whether to delete on error
|
371
|
|
372
|
$(subdir)reinstall: _always $(subdir)uninstall $(subdir)install ;
|
373
|
endef
|
374
|
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
375
|
|
376
|
Makefile: ;
|
377
|
|
378
|
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
379
|
|
380
|
#### Maps validation
|
381
|
|
382
|
termsSubdirs := $(call no/,$(call wildcard/,inputs/*/))
|
383
|
|
384
|
include lib/mappings.Makefile
|