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