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