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