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