1 |
244
|
aaronmk
|
# Make
|
2 |
334
|
aaronmk
|
|
3 |
247
|
aaronmk
|
SHELL := /bin/bash
|
4 |
259
|
aaronmk
|
subMake = $(if $(wildcard $(@D)/Makefile*),$(MAKE) $(@F) --directory=$(@D),)
|
5 |
244
|
aaronmk
|
|
6 |
245
|
aaronmk
|
# OS
|
7 |
247
|
aaronmk
|
os := $(shell uname)
|
8 |
245
|
aaronmk
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
9 |
|
|
|
10 |
241
|
aaronmk
|
# Terminal
|
11 |
247
|
aaronmk
|
esc := '['
|
12 |
|
|
reset := $(esc)'0m'
|
13 |
|
|
emph := $(esc)'7m '
|
14 |
|
|
endEmph := ' '$(reset)
|
15 |
245
|
aaronmk
|
|
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 |
247
|
aaronmk
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
25 |
245
|
aaronmk
|
|
26 |
249
|
aaronmk
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
27 |
235
|
aaronmk
|
|
28 |
241
|
aaronmk
|
# Env
|
29 |
225
|
aaronmk
|
export PGOPTIONS = --client-min-messages=WARNING
|
30 |
|
|
|
31 |
334
|
aaronmk
|
# File editing
|
32 |
|
|
sudoAppend = echo $$'$$\na\n$(2)\n.\nwq'|sudo ed --verbose $(1)
|
33 |
|
|
|
34 |
241
|
aaronmk
|
#####
|
35 |
225
|
aaronmk
|
|
36 |
235
|
aaronmk
|
all: _not_file install
|
37 |
228
|
aaronmk
|
|
38 |
225
|
aaronmk
|
.SUFFIXES:
|
39 |
|
|
|
40 |
235
|
aaronmk
|
_not_file:
|
41 |
|
|
.PHONY: _not_file
|
42 |
202
|
aaronmk
|
|
43 |
241
|
aaronmk
|
#####
|
44 |
|
|
|
45 |
245
|
aaronmk
|
install: _not_file core mysql inputs test
|
46 |
241
|
aaronmk
|
@$(done)
|
47 |
202
|
aaronmk
|
|
48 |
250
|
aaronmk
|
uninstall: _not_file rm_inputs rm_mysql rm_core
|
49 |
241
|
aaronmk
|
|
50 |
235
|
aaronmk
|
reinstall: _not_file uninstall install
|
51 |
225
|
aaronmk
|
|
52 |
241
|
aaronmk
|
#####
|
53 |
202
|
aaronmk
|
|
54 |
284
|
aaronmk
|
core: _not_file $(call forOs,python postgres) postgres_user db
|
55 |
241
|
aaronmk
|
@$(done)
|
56 |
235
|
aaronmk
|
|
57 |
241
|
aaronmk
|
rm_core: _not_file rm_db rm_postgres_user
|
58 |
|
|
|
59 |
|
|
reinstall_core: _not_file rm_core core
|
60 |
|
|
|
61 |
284
|
aaronmk
|
python-Linux: _not_file
|
62 |
334
|
aaronmk
|
-sudo apt-get install python python-dev python-dateutil python-pip
|
63 |
284
|
aaronmk
|
|
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 |
334
|
aaronmk
|
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 |
235
|
aaronmk
|
postgres-Linux: _not_file
|
88 |
329
|
aaronmk
|
-sudo apt-get install postgresql libpq-dev phppgadmin
|
89 |
334
|
aaronmk
|
-$(editPhppgadminApacheConf)
|
90 |
|
|
$(editApacheConfForPhppgadmin)
|
91 |
|
|
-$(if $(shell sudo lsof -i :80),$(editApachePortsConf))
|
92 |
|
|
-sudo apache2ctl restart
|
93 |
284
|
aaronmk
|
-sudo pip install psycopg2
|
94 |
334
|
aaronmk
|
# ignore errors if conf files already edited
|
95 |
235
|
aaronmk
|
|
96 |
254
|
aaronmk
|
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 |
235
|
aaronmk
|
|
103 |
241
|
aaronmk
|
postgres-: _not_file # other OSes
|
104 |
|
|
|
105 |
247
|
aaronmk
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
106 |
249
|
aaronmk
|
psqlAsAdmin := sudo -u postgres psql $(psqlOpts)
|
107 |
274
|
aaronmk
|
psqlAsBien := ./bin/psql_vegbien $(psqlOpts)
|
108 |
272
|
aaronmk
|
bienPassword := $(shell cat config/bien_password)
|
109 |
241
|
aaronmk
|
|
110 |
|
|
postgres_user: _not_file
|
111 |
249
|
aaronmk
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
112 |
241
|
aaronmk
|
# 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 |
275
|
aaronmk
|
$(psqlAsAdmin) <mappings/schemas/vegbien.sql
|
121 |
241
|
aaronmk
|
|
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 |
275
|
aaronmk
|
$(psqlAsBien) <mappings/schemas/vegbien_empty.sql
|
129 |
241
|
aaronmk
|
|
130 |
|
|
#####
|
131 |
|
|
|
132 |
245
|
aaronmk
|
mysql: _not_file $(call forOs,mysql) mysql_user
|
133 |
241
|
aaronmk
|
@$(done)
|
134 |
|
|
|
135 |
245
|
aaronmk
|
rm_mysql: _not_file rm_mysql_user
|
136 |
241
|
aaronmk
|
|
137 |
235
|
aaronmk
|
mysql-Linux: _not_file
|
138 |
244
|
aaronmk
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
139 |
238
|
aaronmk
|
@$(wait)
|
140 |
237
|
aaronmk
|
-sudo apt-get install mysql-server mysql-client python-mysqldb
|
141 |
235
|
aaronmk
|
|
142 |
|
|
mysql-Darwin: _not_file
|
143 |
244
|
aaronmk
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
144 |
235
|
aaronmk
|
@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 |
284
|
aaronmk
|
@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 |
235
|
aaronmk
|
@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 |
284
|
aaronmk
|
@echo 'Run python setup.py clean'
|
154 |
|
|
@echo 'Run python setup.py build'
|
155 |
235
|
aaronmk
|
@echo 'Run sudo python setup.py install'
|
156 |
|
|
@echo "Run python -c 'import MySQLdb'"
|
157 |
238
|
aaronmk
|
@$(wait)
|
158 |
235
|
aaronmk
|
|
159 |
241
|
aaronmk
|
mysql-: _not_file # other OSes
|
160 |
235
|
aaronmk
|
|
161 |
247
|
aaronmk
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
162 |
235
|
aaronmk
|
|
163 |
241
|
aaronmk
|
mysql_user: _not_file
|
164 |
|
|
-$($@_cmd)
|
165 |
|
|
# ignore errors about user existing
|
166 |
244
|
aaronmk
|
mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY \
|
167 |
245
|
aaronmk
|
'$(bienPassword)';"|$(mysqlAsRoot)
|
168 |
202
|
aaronmk
|
|
169 |
241
|
aaronmk
|
rm_mysql_user: _not_file
|
170 |
245
|
aaronmk
|
-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsRoot)
|
171 |
241
|
aaronmk
|
# ignore errors about user not existing
|
172 |
202
|
aaronmk
|
|
173 |
241
|
aaronmk
|
#####
|
174 |
202
|
aaronmk
|
|
175 |
268
|
aaronmk
|
inputs := $(wildcard inputs/*/)
|
176 |
245
|
aaronmk
|
|
177 |
259
|
aaronmk
|
inputs: _not_file $(inputs:%=%install)
|
178 |
250
|
aaronmk
|
|
179 |
259
|
aaronmk
|
rm_inputs: _not_file $(inputs:%=%uninstall)
|
180 |
250
|
aaronmk
|
|
181 |
268
|
aaronmk
|
inputs/%: _not_file
|
182 |
250
|
aaronmk
|
-$(subMake)
|
183 |
|
|
# ignore errors in sub-makes
|
184 |
|
|
|
185 |
245
|
aaronmk
|
#####
|
186 |
|
|
|
187 |
241
|
aaronmk
|
test: _not_file test-map
|
188 |
|
|
@$(done)
|
189 |
202
|
aaronmk
|
|
190 |
235
|
aaronmk
|
test-%: _not_file
|
191 |
176
|
aaronmk
|
./test/$(*F)
|