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