1 |
784
|
aaronmk
|
##### Vars/functions
|
2 |
|
|
|
3 |
244
|
aaronmk
|
# Make
|
4 |
247
|
aaronmk
|
SHELL := /bin/bash
|
5 |
625
|
aaronmk
|
pathParts = $(shell path="$(1)"; echo "$${path%%/*}" "$${path\#*/}")
|
6 |
739
|
aaronmk
|
topDir = $(word 1,$(pathParts))
|
7 |
|
|
subPath = $(word 2,$(pathParts))
|
8 |
625
|
aaronmk
|
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@)
|
9 |
244
|
aaronmk
|
|
10 |
245
|
aaronmk
|
# OS
|
11 |
247
|
aaronmk
|
os := $(shell uname)
|
12 |
245
|
aaronmk
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
13 |
|
|
|
14 |
241
|
aaronmk
|
# Terminal
|
15 |
247
|
aaronmk
|
esc := '['
|
16 |
|
|
reset := $(esc)'0m'
|
17 |
|
|
emph := $(esc)'7m '
|
18 |
|
|
endEmph := ' '$(reset)
|
19 |
245
|
aaronmk
|
|
20 |
|
|
# User interaction
|
21 |
|
|
|
22 |
|
|
confirm = $(shell read -p $(emph)"$(1) (y/n)"$(endEmph) REPLY; \
|
23 |
|
|
test "$REPLY" = y && echo t)
|
24 |
|
|
|
25 |
|
|
getPassword = $(shell read -s -p $(emph)"Enter your $(1) password:"$(endEmph) \
|
26 |
|
|
REPLY; echo >&2; echo -n "$REPLY")
|
27 |
|
|
|
28 |
247
|
aaronmk
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
29 |
245
|
aaronmk
|
|
30 |
249
|
aaronmk
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
31 |
235
|
aaronmk
|
|
32 |
335
|
aaronmk
|
# File editing
|
33 |
|
|
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
|
34 |
|
|
|
35 |
784
|
aaronmk
|
##### Environment
|
36 |
|
|
|
37 |
225
|
aaronmk
|
export PGOPTIONS = --client-min-messages=WARNING
|
38 |
|
|
|
39 |
784
|
aaronmk
|
##### General targets
|
40 |
225
|
aaronmk
|
|
41 |
414
|
aaronmk
|
all:
|
42 |
228
|
aaronmk
|
|
43 |
225
|
aaronmk
|
.SUFFIXES:
|
44 |
|
|
|
45 |
383
|
aaronmk
|
_always:
|
46 |
|
|
.PHONY: _always
|
47 |
202
|
aaronmk
|
|
48 |
402
|
aaronmk
|
define subdirTargets
|
49 |
|
|
$(subdir): _always
|
50 |
|
|
+$$(subMake)
|
51 |
388
|
aaronmk
|
|
52 |
402
|
aaronmk
|
$(subdir)%: _always
|
53 |
|
|
+$$(subMake)
|
54 |
|
|
endef
|
55 |
|
|
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
56 |
388
|
aaronmk
|
|
57 |
416
|
aaronmk
|
Makefile: ;
|
58 |
|
|
|
59 |
414
|
aaronmk
|
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
60 |
|
|
|
61 |
784
|
aaronmk
|
##### Installation
|
62 |
241
|
aaronmk
|
|
63 |
411
|
aaronmk
|
install: _always core mysql inputs/install test
|
64 |
241
|
aaronmk
|
@$(done)
|
65 |
202
|
aaronmk
|
|
66 |
418
|
aaronmk
|
uninstall: _always inputs/uninstall rm_mysql rm_core ;
|
67 |
241
|
aaronmk
|
|
68 |
418
|
aaronmk
|
reinstall: _always uninstall install ;
|
69 |
225
|
aaronmk
|
|
70 |
784
|
aaronmk
|
##### Core: VegBIEN DB and dependencies
|
71 |
202
|
aaronmk
|
|
72 |
383
|
aaronmk
|
core: _always $(call forOs,python postgres) postgres_user db
|
73 |
241
|
aaronmk
|
@$(done)
|
74 |
235
|
aaronmk
|
|
75 |
418
|
aaronmk
|
rm_core: _always rm_db rm_postgres_user ;
|
76 |
241
|
aaronmk
|
|
77 |
418
|
aaronmk
|
reinstall_core: _always rm_core core ;
|
78 |
241
|
aaronmk
|
|
79 |
784
|
aaronmk
|
##### Python
|
80 |
|
|
|
81 |
383
|
aaronmk
|
python-Linux: _always
|
82 |
334
|
aaronmk
|
-sudo apt-get install python python-dev python-dateutil python-pip
|
83 |
284
|
aaronmk
|
|
84 |
383
|
aaronmk
|
python-Darwin: _always
|
85 |
284
|
aaronmk
|
@echo $(emph)'Installing python-dateutil on Mac OS X:'$(endEmph)
|
86 |
|
|
@echo 'Download it: http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz'
|
87 |
|
|
@echo 'Extract the archive'
|
88 |
|
|
@echo 'Change to the directory of the extracted files'
|
89 |
|
|
@echo 'Run python setup.py build'
|
90 |
|
|
@echo 'Run sudo python setup.py install'
|
91 |
|
|
@echo "Run python -c 'import dateutil'"
|
92 |
|
|
@$(wait)
|
93 |
|
|
|
94 |
784
|
aaronmk
|
##### PostgreSQL
|
95 |
|
|
|
96 |
337
|
aaronmk
|
editPhppgadminApacheConf = echo $$'1\n,s/\# \(allow from all\)/\1/\nwq'|\
|
97 |
336
|
aaronmk
|
sudo ed --loose-exit-status --verbose /etc/phppgadmin/apache.conf
|
98 |
334
|
aaronmk
|
|
99 |
|
|
apacheConf := /etc/apache2/apache2.conf
|
100 |
|
|
apacheConfPhppgadminLine := Include /etc/phppgadmin/apache.conf
|
101 |
|
|
editApacheConfForPhppgadmin =\
|
102 |
|
|
$(if $(shell grep -F "$(apacheConfPhppgadminLine)" $(apacheConf)),,\
|
103 |
|
|
$(call sudoAppend,$(apacheConf),\n$(apacheConfPhppgadminLine)))
|
104 |
|
|
|
105 |
335
|
aaronmk
|
nonApacheOnPort80 = $(shell sudo lsof -i :80|tail -n +2|grep -v -F apache2)
|
106 |
336
|
aaronmk
|
editApachePortsConf = echo $$'1\n,s/\\b80\\b/8080/g\nwq'|\
|
107 |
|
|
sudo ed --loose-exit-status --verbose /etc/apache2/ports.conf
|
108 |
334
|
aaronmk
|
|
109 |
383
|
aaronmk
|
postgres-Linux: _always
|
110 |
329
|
aaronmk
|
-sudo apt-get install postgresql libpq-dev phppgadmin
|
111 |
336
|
aaronmk
|
$(editPhppgadminApacheConf)
|
112 |
334
|
aaronmk
|
$(editApacheConfForPhppgadmin)
|
113 |
336
|
aaronmk
|
$(if $(nonApacheOnPort80),$(editApachePortsConf))
|
114 |
334
|
aaronmk
|
-sudo apache2ctl restart
|
115 |
284
|
aaronmk
|
-sudo pip install psycopg2
|
116 |
334
|
aaronmk
|
# ignore errors if conf files already edited
|
117 |
235
|
aaronmk
|
|
118 |
383
|
aaronmk
|
postgres-Darwin: _always
|
119 |
254
|
aaronmk
|
@echo $(emph)'Installing PostgreSQL on Mac OS X:'$(endEmph)
|
120 |
|
|
@echo 'Download it using the topmost "Mac OS X" link at http://http://www.enterprisedb.com/products-services-training/pgdownload'
|
121 |
|
|
@echo 'Open the disk image'
|
122 |
|
|
@echo 'Run the installer in it'
|
123 |
|
|
@$(wait)
|
124 |
235
|
aaronmk
|
|
125 |
418
|
aaronmk
|
postgres-: _always ; # other OSes
|
126 |
241
|
aaronmk
|
|
127 |
247
|
aaronmk
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
128 |
249
|
aaronmk
|
psqlAsAdmin := sudo -u postgres psql $(psqlOpts)
|
129 |
274
|
aaronmk
|
psqlAsBien := ./bin/psql_vegbien $(psqlOpts)
|
130 |
272
|
aaronmk
|
bienPassword := $(shell cat config/bien_password)
|
131 |
241
|
aaronmk
|
|
132 |
383
|
aaronmk
|
postgres_user: _always
|
133 |
249
|
aaronmk
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
134 |
364
|
aaronmk
|
# ignore errors if user exists
|
135 |
241
|
aaronmk
|
|
136 |
383
|
aaronmk
|
rm_postgres_user: _always
|
137 |
241
|
aaronmk
|
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
|
138 |
|
|
|
139 |
784
|
aaronmk
|
##### VegBIEN DB
|
140 |
241
|
aaronmk
|
|
141 |
389
|
aaronmk
|
db: _always schemas/vegbien.sql
|
142 |
383
|
aaronmk
|
-$($@_create_cmd)
|
143 |
389
|
aaronmk
|
$(psqlAsBien) <schemas/vegbien.sql
|
144 |
364
|
aaronmk
|
# ignore errors if database exists
|
145 |
383
|
aaronmk
|
db_create_cmd = echo "CREATE DATABASE vegbien OWNER bien ENCODING 'UTF8' \
|
146 |
381
|
aaronmk
|
TEMPLATE template1;"|$(psqlAsAdmin)
|
147 |
241
|
aaronmk
|
|
148 |
383
|
aaronmk
|
rm_db: _always
|
149 |
241
|
aaronmk
|
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
150 |
|
|
|
151 |
418
|
aaronmk
|
reinstall_db: _always rm_db db ;
|
152 |
241
|
aaronmk
|
|
153 |
389
|
aaronmk
|
empty_db: _always schemas/vegbien_empty.sql
|
154 |
|
|
$(psqlAsBien) <schemas/vegbien_empty.sql
|
155 |
241
|
aaronmk
|
|
156 |
784
|
aaronmk
|
##### MySQL
|
157 |
241
|
aaronmk
|
|
158 |
383
|
aaronmk
|
mysql: _always $(call forOs,mysql) mysql_user
|
159 |
241
|
aaronmk
|
@$(done)
|
160 |
|
|
|
161 |
418
|
aaronmk
|
rm_mysql: _always rm_mysql_user ;
|
162 |
241
|
aaronmk
|
|
163 |
383
|
aaronmk
|
mysql-Linux: _always
|
164 |
244
|
aaronmk
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
165 |
238
|
aaronmk
|
@$(wait)
|
166 |
237
|
aaronmk
|
-sudo apt-get install mysql-server mysql-client python-mysqldb
|
167 |
235
|
aaronmk
|
|
168 |
383
|
aaronmk
|
mysql-Darwin: _always
|
169 |
244
|
aaronmk
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
170 |
235
|
aaronmk
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
171 |
|
|
@echo 'Extract the archive'
|
172 |
|
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
173 |
284
|
aaronmk
|
@echo 'Run ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
174 |
|
|
@echo 'Run ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
175 |
235
|
aaronmk
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
176 |
|
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
177 |
|
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
178 |
|
|
@echo 'Change to the directory of the extracted files'
|
179 |
284
|
aaronmk
|
@echo 'Run python setup.py clean'
|
180 |
|
|
@echo 'Run python setup.py build'
|
181 |
235
|
aaronmk
|
@echo 'Run sudo python setup.py install'
|
182 |
|
|
@echo "Run python -c 'import MySQLdb'"
|
183 |
238
|
aaronmk
|
@$(wait)
|
184 |
235
|
aaronmk
|
|
185 |
383
|
aaronmk
|
mysql-: _always # other OSes
|
186 |
235
|
aaronmk
|
|
187 |
247
|
aaronmk
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
188 |
235
|
aaronmk
|
|
189 |
383
|
aaronmk
|
mysql_user: _always
|
190 |
241
|
aaronmk
|
-$($@_cmd)
|
191 |
364
|
aaronmk
|
# ignore errors if user exists
|
192 |
244
|
aaronmk
|
mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY \
|
193 |
245
|
aaronmk
|
'$(bienPassword)';"|$(mysqlAsRoot)
|
194 |
202
|
aaronmk
|
|
195 |
383
|
aaronmk
|
rm_mysql_user: _always
|
196 |
245
|
aaronmk
|
-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsRoot)
|
197 |
364
|
aaronmk
|
# ignore errors if user exists
|
198 |
202
|
aaronmk
|
|
199 |
784
|
aaronmk
|
##### Datasources
|
200 |
202
|
aaronmk
|
|
201 |
418
|
aaronmk
|
inputs: _always inputs/all ;
|
202 |
245
|
aaronmk
|
|
203 |
418
|
aaronmk
|
import: _always inputs/import ;
|
204 |
250
|
aaronmk
|
|
205 |
418
|
aaronmk
|
verify: _always inputs/verify ;
|
206 |
386
|
aaronmk
|
|
207 |
418
|
aaronmk
|
test2: _always inputs/test ;
|
208 |
397
|
aaronmk
|
@$(done)
|
209 |
375
|
aaronmk
|
|
210 |
784
|
aaronmk
|
##### Testing
|
211 |
245
|
aaronmk
|
|
212 |
383
|
aaronmk
|
test: _always test-map
|
213 |
241
|
aaronmk
|
@$(done)
|
214 |
202
|
aaronmk
|
|
215 |
383
|
aaronmk
|
test-%: _always
|
216 |
176
|
aaronmk
|
./test/$(*F)
|