1 |
244
|
aaronmk
|
# Make
|
2 |
247
|
aaronmk
|
SHELL := /bin/bash
|
3 |
259
|
aaronmk
|
subMake = $(if $(wildcard $(@D)/Makefile*),$(MAKE) $(@F) --directory=$(@D),)
|
4 |
244
|
aaronmk
|
|
5 |
245
|
aaronmk
|
# OS
|
6 |
247
|
aaronmk
|
os := $(shell uname)
|
7 |
245
|
aaronmk
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
8 |
|
|
|
9 |
241
|
aaronmk
|
# Terminal
|
10 |
247
|
aaronmk
|
esc := '['
|
11 |
|
|
reset := $(esc)'0m'
|
12 |
|
|
emph := $(esc)'7m '
|
13 |
|
|
endEmph := ' '$(reset)
|
14 |
245
|
aaronmk
|
|
15 |
|
|
# User interaction
|
16 |
|
|
|
17 |
|
|
confirm = $(shell read -p $(emph)"$(1) (y/n)"$(endEmph) REPLY; \
|
18 |
|
|
test "$REPLY" = y && echo t)
|
19 |
|
|
|
20 |
|
|
getPassword = $(shell read -s -p $(emph)"Enter your $(1) password:"$(endEmph) \
|
21 |
|
|
REPLY; echo >&2; echo -n "$REPLY")
|
22 |
|
|
|
23 |
247
|
aaronmk
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
24 |
245
|
aaronmk
|
|
25 |
249
|
aaronmk
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
26 |
235
|
aaronmk
|
|
27 |
241
|
aaronmk
|
# Env
|
28 |
225
|
aaronmk
|
export PGOPTIONS = --client-min-messages=WARNING
|
29 |
|
|
|
30 |
241
|
aaronmk
|
#####
|
31 |
225
|
aaronmk
|
|
32 |
235
|
aaronmk
|
all: _not_file install
|
33 |
228
|
aaronmk
|
|
34 |
225
|
aaronmk
|
.SUFFIXES:
|
35 |
|
|
|
36 |
235
|
aaronmk
|
_not_file:
|
37 |
|
|
.PHONY: _not_file
|
38 |
202
|
aaronmk
|
|
39 |
241
|
aaronmk
|
#####
|
40 |
|
|
|
41 |
245
|
aaronmk
|
install: _not_file core mysql inputs test
|
42 |
241
|
aaronmk
|
@$(done)
|
43 |
202
|
aaronmk
|
|
44 |
250
|
aaronmk
|
uninstall: _not_file rm_inputs rm_mysql rm_core
|
45 |
241
|
aaronmk
|
|
46 |
235
|
aaronmk
|
reinstall: _not_file uninstall install
|
47 |
225
|
aaronmk
|
|
48 |
241
|
aaronmk
|
#####
|
49 |
202
|
aaronmk
|
|
50 |
241
|
aaronmk
|
core: _not_file $(call forOs,postgres) postgres_user db
|
51 |
|
|
@$(done)
|
52 |
235
|
aaronmk
|
|
53 |
241
|
aaronmk
|
rm_core: _not_file rm_db rm_postgres_user
|
54 |
|
|
|
55 |
|
|
reinstall_core: _not_file rm_core core
|
56 |
|
|
|
57 |
235
|
aaronmk
|
postgres-Linux: _not_file
|
58 |
253
|
aaronmk
|
-sudo apt-get install postgresql python-dev libpq-dev
|
59 |
237
|
aaronmk
|
-sudo apt-get install python-pip && sudo pip install psycopg2
|
60 |
235
|
aaronmk
|
|
61 |
254
|
aaronmk
|
postgres-Darwin: _not_file
|
62 |
|
|
@echo $(emph)'Installing PostgreSQL on Mac OS X:'$(endEmph)
|
63 |
|
|
@echo 'Download it using the topmost "Mac OS X" link at http://http://www.enterprisedb.com/products-services-training/pgdownload'
|
64 |
|
|
@echo 'Open the disk image'
|
65 |
|
|
@echo 'Run the installer in it'
|
66 |
|
|
@$(wait)
|
67 |
235
|
aaronmk
|
|
68 |
241
|
aaronmk
|
postgres-: _not_file # other OSes
|
69 |
|
|
|
70 |
247
|
aaronmk
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
71 |
249
|
aaronmk
|
psqlAsAdmin := sudo -u postgres psql $(psqlOpts)
|
72 |
247
|
aaronmk
|
psqlAsBien := ./util/psql_vegbien $(psqlOpts)
|
73 |
272
|
aaronmk
|
bienPassword := $(shell cat config/bien_password)
|
74 |
241
|
aaronmk
|
|
75 |
|
|
postgres_user: _not_file
|
76 |
249
|
aaronmk
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
77 |
241
|
aaronmk
|
# ignore errors about user existing
|
78 |
|
|
|
79 |
|
|
rm_postgres_user: _not_file
|
80 |
|
|
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
|
81 |
|
|
|
82 |
|
|
#####
|
83 |
|
|
|
84 |
|
|
db: _not_file
|
85 |
|
|
$(psqlAsAdmin) <../mappings/schemas/vegbien.sql
|
86 |
|
|
|
87 |
|
|
rm_db: _not_file
|
88 |
|
|
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
89 |
|
|
|
90 |
|
|
reinstall_db: _not_file rm_db db
|
91 |
|
|
|
92 |
|
|
empty_db: _not_file
|
93 |
246
|
aaronmk
|
$(psqlAsBien) <../mappings/schemas/vegbien_empty.sql
|
94 |
241
|
aaronmk
|
|
95 |
|
|
#####
|
96 |
|
|
|
97 |
245
|
aaronmk
|
mysql: _not_file $(call forOs,mysql) mysql_user
|
98 |
241
|
aaronmk
|
@$(done)
|
99 |
|
|
|
100 |
245
|
aaronmk
|
rm_mysql: _not_file rm_mysql_user
|
101 |
241
|
aaronmk
|
|
102 |
235
|
aaronmk
|
mysql-Linux: _not_file
|
103 |
244
|
aaronmk
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
104 |
238
|
aaronmk
|
@$(wait)
|
105 |
237
|
aaronmk
|
-sudo apt-get install mysql-server mysql-client python-mysqldb
|
106 |
235
|
aaronmk
|
|
107 |
|
|
mysql-Darwin: _not_file
|
108 |
244
|
aaronmk
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
109 |
235
|
aaronmk
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
110 |
|
|
@echo 'Extract the archive'
|
111 |
|
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
112 |
|
|
@echo 'Run sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
113 |
|
|
@echo 'Run sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
114 |
|
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
115 |
|
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
116 |
|
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
117 |
|
|
@echo 'Change to the directory of the extracted files'
|
118 |
|
|
@echo 'Run sudo python setup.py clean'
|
119 |
|
|
@echo 'Run sudo python setup.py build'
|
120 |
|
|
@echo 'Run sudo python setup.py install'
|
121 |
|
|
@echo "Run python -c 'import MySQLdb'"
|
122 |
238
|
aaronmk
|
@$(wait)
|
123 |
235
|
aaronmk
|
|
124 |
241
|
aaronmk
|
mysql-: _not_file # other OSes
|
125 |
235
|
aaronmk
|
|
126 |
247
|
aaronmk
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
127 |
235
|
aaronmk
|
|
128 |
241
|
aaronmk
|
mysql_user: _not_file
|
129 |
|
|
-$($@_cmd)
|
130 |
|
|
# ignore errors about user existing
|
131 |
244
|
aaronmk
|
mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY \
|
132 |
245
|
aaronmk
|
'$(bienPassword)';"|$(mysqlAsRoot)
|
133 |
202
|
aaronmk
|
|
134 |
241
|
aaronmk
|
rm_mysql_user: _not_file
|
135 |
245
|
aaronmk
|
-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsRoot)
|
136 |
241
|
aaronmk
|
# ignore errors about user not existing
|
137 |
202
|
aaronmk
|
|
138 |
241
|
aaronmk
|
#####
|
139 |
202
|
aaronmk
|
|
140 |
268
|
aaronmk
|
inputs := $(wildcard inputs/*/)
|
141 |
245
|
aaronmk
|
|
142 |
259
|
aaronmk
|
inputs: _not_file $(inputs:%=%install)
|
143 |
250
|
aaronmk
|
|
144 |
259
|
aaronmk
|
rm_inputs: _not_file $(inputs:%=%uninstall)
|
145 |
250
|
aaronmk
|
|
146 |
268
|
aaronmk
|
inputs/%: _not_file
|
147 |
250
|
aaronmk
|
-$(subMake)
|
148 |
|
|
# ignore errors in sub-makes
|
149 |
|
|
|
150 |
245
|
aaronmk
|
#####
|
151 |
|
|
|
152 |
241
|
aaronmk
|
test: _not_file test-map
|
153 |
|
|
@$(done)
|
154 |
202
|
aaronmk
|
|
155 |
235
|
aaronmk
|
test-%: _not_file
|
156 |
176
|
aaronmk
|
./test/$(*F)
|