Project

General

Profile

1 5459 aaronmk
root := .
2 3762 aaronmk
include lib/common.Makefile
3
4
5 784 aaronmk
##### Vars/functions
6
7 244 aaronmk
# Make
8 247 aaronmk
SHELL := /bin/bash
9 244 aaronmk
10 4607 aaronmk
# Paths
11
bin := bin
12
13 784 aaronmk
##### Environment
14
15 225 aaronmk
export PGOPTIONS = --client-min-messages=WARNING
16
17 784 aaronmk
##### General targets
18 225 aaronmk
19 1274 aaronmk
remake: _always clean
20
	$(MAKE)
21
# re-run make so that cache of existing files is reset
22
23 1288 aaronmk
%/remake: _always
24
	$(MAKE) $(@D)/clean
25
	$(MAKE) $(@D)/
26
# re-run make so that cache of existing files is reset
27
28 1813 aaronmk
%-remake: _always
29
	rm -f $*
30
	$(MAKE) $*
31
# re-run make so that cache of existing files is reset
32
33 784 aaronmk
##### Installation
34 241 aaronmk
35 6102 aaronmk
# public must be installed *after* inputs because some views depend on inputs
36 8844 aaronmk
install: _always core mysql inputs/download inputs/install \
37 8081 aaronmk
schemas/public/install test
38 241 aaronmk
	@$(done)
39 202 aaronmk
40 6200 aaronmk
uninstall: _always rm_mysql rm_core ;
41 241 aaronmk
42 418 aaronmk
reinstall: _always uninstall install ;
43 225 aaronmk
44 784 aaronmk
##### Core: VegBIEN DB and dependencies
45 202 aaronmk
46 8817 aaronmk
core: _always $(call forOs,apache python php postgres misc) db
47 241 aaronmk
	@$(done)
48 235 aaronmk
49 1746 aaronmk
rm_core: _always rm_db ;
50 241 aaronmk
51 418 aaronmk
reinstall_core: _always rm_core core ;
52 241 aaronmk
53 8817 aaronmk
##### Apache
54
55
apache-Linux: _always
56
	# Apache 2.4
57 8818 aaronmk
	-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 8817 aaronmk
65
apache-Darwin: _always ;
66
67 784 aaronmk
##### Python
68
69 383 aaronmk
python-Linux: _always
70 6544 aaronmk
	-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 3156 aaronmk
	-sudo pip install ordereddict
79 1845 aaronmk
	-sudo pip install pp
80 284 aaronmk
81 383 aaronmk
python-Darwin: _always
82 7230 aaronmk
	@# Python 2 comes preinstalled
83 6190 aaronmk
	@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 284 aaronmk
	@echo $(emph)'Installing python-dateutil on Mac OS X:'$(endEmph)
89 7231 aaronmk
	@echo 'Download it for Python 2: http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz'
90 284 aaronmk
	@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 7231 aaronmk
	@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 284 aaronmk
	@$(wait)
102 3156 aaronmk
	@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 284 aaronmk
106 1599 aaronmk
##### PHP
107
108
php-Linux: _always
109 6544 aaronmk
	-sudo apt-get --yes install php-http-request
110 1599 aaronmk
111
php-Darwin: _always
112 1600 aaronmk
	@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 1665 aaronmk
	@echo 'If needed, set $$PHPRC to your php.ini'
120 1600 aaronmk
	@echo "Run pear install HTTP_Request"
121
	@echo 'To run a php command: php -c <php.ini-path> ...'
122 1599 aaronmk
	@$(wait)
123
124 784 aaronmk
##### PostgreSQL
125
126 6824 aaronmk
define editPhppgadmin
127 6853 aaronmk
-sudo patch /etc/phppgadmin/config.inc.php lib/phpPgAdmin.config.inc.php.diff
128 6824 aaronmk
sudo cp -n /usr/share/phppgadmin/login.php /usr/share/phppgadmin/login.php.old
129 6853 aaronmk
-sudo patch /usr/share/phppgadmin/login.php lib/phpPgAdmin.login.php.diff
130 6824 aaronmk
endef
131 6853 aaronmk
# ignore errors if patch has already been applied
132 6824 aaronmk
133 1970 aaronmk
editPhppgadminApacheConf = echo $$'1\n,s/deny from all/allow from all/\nwq'|\
134 336 aaronmk
sudo ed --loose-exit-status --verbose /etc/phppgadmin/apache.conf
135 334 aaronmk
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 335 aaronmk
nonApacheOnPort80 = $(shell sudo lsof -i :80|tail -n +2|grep -v -F apache2)
143 336 aaronmk
editApachePortsConf = echo $$'1\n,s/\\b80\\b/8080/g\nwq'|\
144
sudo ed --loose-exit-status --verbose /etc/apache2/ports.conf
145 334 aaronmk
146 6197 aaronmk
asAdmin := sudo -E -u postgres
147 6337 aaronmk
asBien := sudo -E -u bien
148 4752 aaronmk
pgVersion = "$$(env minor=1 bin/pg_version)"
149
150 6198 aaronmk
linuxPostgresDir := /etc/postgresql/9.1/main
151 6201 aaronmk
define pg_ctl-Linux
152
$(asAdmin) /etc/init.d/postgresql $(1)
153
endef
154 6198 aaronmk
155 6196 aaronmk
macPostgresDir := /Library/PostgreSQL/9.1
156 6187 aaronmk
define macUsePostgresLib
157
sudo mv $(libDest) $(libDest).old||sudo rm -f $(libDest)
158 6196 aaronmk
sudo ln -s $(macPostgresDir)/lib/$(1) $(libDest)
159 6187 aaronmk
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 6201 aaronmk
define pg_ctl-Darwin
168
$(asAdmin) pg_ctl -D $(macPostgresDir)/data -l $(macPostgresDir)/postgres.log $(1)
169
sleep 2
170
endef
171 6197 aaronmk
172 6503 aaronmk
confirmPostgresReload = $(call confirm,Modifying postgresql.conf and pg_hba.conf)
173
174 6333 aaronmk
define postgresReload-Linux
175 6503 aaronmk
@$(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 6447 aaronmk
chmod a+r schemas/*.conf || $(asBien) chmod a+r schemas/*.conf
181 6823 aaronmk
-$(asAdmin) mv -n $(linuxPostgresDir)/postgresql.conf $(linuxPostgresDir)/postgresql.conf.old
182 6333 aaronmk
$(asAdmin) cp --preserve=timestamps schemas/postgresql.conf $(linuxPostgresDir)/postgresql.conf
183 6823 aaronmk
-$(asAdmin) mv -n $(linuxPostgresDir)/pg_hba.conf $(linuxPostgresDir)/pg_hba.conf.old
184 6335 aaronmk
$(asAdmin) cp --preserve=timestamps schemas/pg_hba.conf $(linuxPostgresDir)/pg_hba.conf
185 8627 aaronmk
@echo $(emph)'restart PostgreSQL manually:'$(endEmph)
186
@echo $(call pg_ctl-Linux,restart)
187
@$(wait)
188 6333 aaronmk
189
endef
190
191
define postgresReload-Darwin
192 6503 aaronmk
@$(confirmPostgresReload)
193 6336 aaronmk
chmod a+r schemas/*.conf
194 6823 aaronmk
-$(asAdmin) mv -n $(macPostgresDir)/data/postgresql.conf $(macPostgresDir)/data/postgresql.conf.old
195 6333 aaronmk
$(asAdmin) cp schemas/postgresql.Mac.conf $(macPostgresDir)/data/postgresql.conf
196 6823 aaronmk
-$(asAdmin) mv -n $(macPostgresDir)/data/pg_hba.conf $(macPostgresDir)/data/pg_hba.conf.old
197 6335 aaronmk
$(asAdmin) cp schemas/pg_hba.Mac.conf $(macPostgresDir)/data/pg_hba.conf
198 6333 aaronmk
$(call pg_ctl-Darwin,restart)
199
200
endef
201
202 6334 aaronmk
postgres_reload: _always
203
	$($(call forOs,postgresReload))
204
205 6333 aaronmk
postgres-Linux: _always
206 6544 aaronmk
	-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 6824 aaronmk
	$(editPhppgadmin)
213 6333 aaronmk
	$(editPhppgadminApacheConf)
214
	$(editApacheConfForPhppgadmin)
215
	$(if $(nonApacheOnPort80),$(editApachePortsConf))
216
	-sudo apache2ctl restart
217
	-sudo pip install psycopg2
218 6503 aaronmk
	-$(MAKE) $(postgresReload-Linux)
219 6333 aaronmk
# run pg_version inline because it needs postgresql to be installed first
220
# ignore errors if conf files already edited
221
222 383 aaronmk
postgres-Darwin: _always
223 254 aaronmk
	@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 6187 aaronmk
	$(foreach lib,$(macPostgresLibs),$(call macUsePostgresLib,$(lib)))
229 6503 aaronmk
	-$(MAKE) $(postgresReload-Darwin)
230 235 aaronmk
231 418 aaronmk
postgres-: _always ; # other OSes
232 241 aaronmk
233 247 aaronmk
psqlOpts := --set ON_ERROR_STOP=1 --quiet
234 6193 aaronmk
psqlAsAdmin := $(asAdmin) psql $(psqlOpts)
235 1980 aaronmk
    # -E preserves env vars so PGOPTIONS is passed to psql
236 2624 aaronmk
psqlAsAdminVegbien := $(psqlAsAdmin) vegbien
237 272 aaronmk
bienPassword := $(shell cat config/bien_password)
238 6331 aaronmk
bienReadPassword := $(shell cat config/bien_read_password)
239 241 aaronmk
240 7422 aaronmk
##### Misc.
241
242 7423 aaronmk
misc-Linux: _always
243
	cp -p "$(shell which dotlockfile)" bin/
244 7422 aaronmk
245
misc-Darwin: _always ;
246
247 784 aaronmk
##### VegBIEN DB
248 241 aaronmk
249 6331 aaronmk
#### DB and users
250 1967 aaronmk
251 2090 aaronmk
confirmRmDb = $(call confirm,WARNING: This will delete your entire VegBIEN\
252 3374 aaronmk
DB!,This includes all archived imports and staging tables.)
253 2089 aaronmk
254 2633 aaronmk
confirmRmPublicSchema = $(call confirm,WARNING: This will delete the current\
255
public schema of your VegBIEN DB!,To save it: make schemas/rotate)
256 2089 aaronmk
257 2091 aaronmk
rmPublicSchema := $(call rmSchemaCmd,public)
258 1967 aaronmk
259 8844 aaronmk
db: mk_db rm_initial_public schemas/install _always ;
260 1967 aaronmk
261
mk_db: _always
262 6822 aaronmk
	-echo "CREATE USER public_;"|$(psqlAsAdmin)
263 1745 aaronmk
	-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
264 6331 aaronmk
	-echo "CREATE USER bien_read PASSWORD '$(bienReadPassword)' IN ROLE bien \
265
NOINHERIT;"|$(psqlAsAdmin)
266 2037 aaronmk
	-echo "CREATE DATABASE vegbien WITH OWNER bien TEMPLATE template1 \
267 1940 aaronmk
ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';"|$(psqlAsAdmin)
268 6221 aaronmk
	-echo "CREATE EXTENSION hstore SCHEMA pg_catalog;"|$(psqlAsAdminVegbien)
269 6189 aaronmk
	-$(asAdmin) createlang plpython3u vegbien
270 7801 aaronmk
	-cat config/users.sql|$(psqlAsAdmin)
271 2627 aaronmk
# ignore errors if user/database/etc. exists
272 2091 aaronmk
273
rm_initial_public: _always
274 2089 aaronmk
	@$(confirmRmPublicSchema)
275 2624 aaronmk
	echo $(rmPublicSchema)|$(psqlAsAdminVegbien)
276 1967 aaronmk
# drop public schema *as admin* because it starts out owned by postgres
277 241 aaronmk
278 383 aaronmk
rm_db: _always
279 1748 aaronmk
	@$(confirmRmDb)
280
	echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
281 6331 aaronmk
	echo "DROP USER IF EXISTS bien_read;"|$(psqlAsAdmin)
282 1748 aaronmk
	echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
283 6822 aaronmk
	echo "DROP USER IF EXISTS public_;"|$(psqlAsAdmin)
284 241 aaronmk
285 418 aaronmk
reinstall_db: _always rm_db db ;
286 241 aaronmk
287 784 aaronmk
##### MySQL
288 241 aaronmk
289 7572 aaronmk
mysql: _always $(call forOs,mysql) mysql_users
290 241 aaronmk
	@$(done)
291
292 7572 aaronmk
rm_mysql: _always rm_mysql_users ;
293 241 aaronmk
294 383 aaronmk
mysql-Linux: _always
295 244 aaronmk
	@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
296 238 aaronmk
	@$(wait)
297 7574 aaronmk
	-sudo apt-get --yes install mysql-server
298
	-sudo apt-get --yes install mysql-client
299
	-sudo apt-get --yes install python-mysqldb
300 7575 aaronmk
	-sudo apt-get --yes install phpmyadmin
301 235 aaronmk
302 383 aaronmk
mysql-Darwin: _always
303 244 aaronmk
	@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
304 235 aaronmk
	@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 284 aaronmk
	@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 235 aaronmk
	@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 284 aaronmk
	@echo 'Run python setup.py clean'
314
	@echo 'Run python setup.py build'
315 235 aaronmk
	@echo 'Run sudo python setup.py install'
316
	@echo "Run python -c 'import MySQLdb'"
317 238 aaronmk
	@$(wait)
318 235 aaronmk
319 383 aaronmk
mysql-: _always # other OSes
320 235 aaronmk
321 247 aaronmk
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
322 235 aaronmk
323 7572 aaronmk
mysql_users: _always
324 7573 aaronmk
	-echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY '$(bienPassword)';"\
325
|$(mysqlAsRoot)
326
	-echo "CREATE USER 'bien_read'@'%' IDENTIFIED BY '$(bienReadPassword)';"\
327
|$(mysqlAsRoot)
328 364 aaronmk
# ignore errors if user exists
329 202 aaronmk
330 7572 aaronmk
rm_mysql_users: _always
331 7573 aaronmk
	-echo "DROP USER 'bien_read'@'localhost';"|$(mysqlAsRoot)
332
	-echo "DROP USER 'bien'@'%';"|$(mysqlAsRoot)
333 364 aaronmk
# ignore errors if user exists
334 202 aaronmk
335 784 aaronmk
##### Datasources
336 202 aaronmk
337 418 aaronmk
inputs: _always inputs/all ;
338 245 aaronmk
339 6191 aaronmk
inputs/install: _always
340 6194 aaronmk
	echo '. bin/reinstall_all; wait'|bash -s
341 6191 aaronmk
342 7268 aaronmk
import: _always import-msg inputs/import_scrub ;
343 1542 aaronmk
import-msg: _always
344 1550 aaronmk
	@echo $(emph)"To import all inputs at once:"$(endEmph) . bin/import_all
345 1542 aaronmk
	@echo
346 250 aaronmk
347 7836 aaronmk
scrub: _always inputs/.TNRS/tnrs/tnrs-remake ;
348 7264 aaronmk
349 1458 aaronmk
verify: _always inputs/verify
350 1241 aaronmk
	@$(done)
351 386 aaronmk
352 1458 aaronmk
test: _always inputs/test
353 397 aaronmk
	@$(done)
354 1458 aaronmk
355
##### Testing
356
357 1743 aaronmk
test-all: _always remake test missing_mappings
358 1458 aaronmk
	@$(done)
359 1967 aaronmk
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 1999 aaronmk
380
#### Maps validation
381
382 4607 aaronmk
termsSubdirs := $(call no/,$(call wildcard/,inputs/*/))
383
384 3764 aaronmk
include lib/mappings.Makefile