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