summaryrefslogtreecommitdiff
path: root/app-from-scratch.sh
blob: e06be6c3b3d0f3307b86cf425f282b797984fa17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# on a debian 9 fresh VM
ssh -A intarnet@intarnet.fr

# "fork" from CHD' git repos
git config --global -e
git clone root@chd.sx:/var/git/chd_gestion
cd ~/chd_gestion/
git checkout a6104f4
git checkout -b cake36
editor app-from-scratch.sh # Adding notes progressively

# env setup
sudo apt --yes install php-cli apache2 libapache2-mod-php php-mbstring php-intl php-xml php-sqlite3 phpmyadmin mariadb-server unzip
sudo a2disconf phpmyadmin
sudo apache2 restart
sudo mkdir /var/www/intarnet.fr
sudo chown intarnet: /var/www/intarnet.fr

# composer install
wget -q https://getcomposer.org/composer.phar -O ~/bin/composer.phar
chmod +x ~/bin/composer.phar
echo 'export PATH="$PATH:~/bin"' >> ~/.bashrc
source ~/.bashrc
composer.phar --version
# Composer version 1.7-dev (006c921abde5a9fa5ec682014265e3203a0987b1) 2018-07-12 20:08:52

# cake install
cd ~/chd_gestion/
mkdir fai_gestion
yes | composer.phar create-project --prefer-dist cakephp/app fai_gestion
ln -s ~intarnet/chd_gestion/fai_gestion/bin/cake ~/bin/
cd ~/chd_gestion/fai_gestion
cake version
# 3.6.7

# cake first start (embed webserver)
cake server -p 8080
# from desktop linux :
# ssh -L 8080:localhost:8080 intarnet@intarnet.fr
# firefox http://localhost:8080/
# -> everything green except database connection
^C

# prepare for apache2 
ln -s ~intarnet/chd_gestion/fai_gestion /var/www/intarnet.fr/gestion
sudo chgrp -R www-data tmp/ logs/
sudo chmod -R ug=rwX,o=rX tmp/ logs/
# (cake bake runs with intarnet user, web served pages with www-data)
# do NOT allow www-data write elsewhere
sudo mv logs /var/log/fai_gestion
ln -s /var/log/fai_gestion logs

# apache2 vhost excerpt

# Alias "/gestion" "/var/www/intarnet.fr/gestion/webroot"
# <Directory /var/www/intarnet.fr/gestion>
#         Options None
#         AllowOverride None
#         Require all denied
# </Directory>
# <Directory /var/www/intarnet.fr/gestion/webroot>
#         Options SymLinksIfOwnerMatch
#         AllowOverride None
#
#         AuthType Basic
#         AuthName "Partie privee"
#         AuthUserFile /etc/apache2/passwords/intarnet.fr/www_priv.passwd
#         Require valid-user
#
#         SetEnv APP_DEFAULT_LOCALE fr_FR
#         SetEnv DEBUG true
#
#         RequestHeader unset Proxy
#         RewriteEngine On
#         RewriteCond %{REQUEST_FILENAME} !-f
#         RewriteRule ^ index.php [L]
# </Directory>

sudo a2enmod env headers rewrite
sudo service apache2 restart

# from desktop linux :
# firefox https://intarnet.fr/gestion/
# -> everything green except database connection

cd ~/chd_gestion/
cat fai_gestion/.gitignore
git add app-from-scratch.sh fai_gestion
git commit -m "Cake 3.6.7 fresh install"
# 4a3ec0ca3f7d0ca8776a6ee7f2a2615234395eb8

# Cake startup configuration
sed --in-place -e 's#^/config/app.php#/config/app_credentials.php#' fai_gestion/.gitignore
git add app-from-scratch.sh fai_gestion/.gitignore fai_gestion/config/app.php
git commit -m "Config : add app.php to git without credentials"
# 8d39eb3d5ad5baee721a2c6518a8429fb0cbd1bf

cat > config/app_credentials.php <<"EOT"
<?php
return [
    'Security' => [
        'salt' => env('SECURITY_SALT', 'hexhexhexhexhexhexhexhexhexhexhexhexhexhexhexhexhexhexhexhexhexh'),
    ],
    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'my_app',
            'password' => 'secret',
            'database' => 'my_app',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
            'log' => false,
            'quoteIdentifiers' => false,
        ],
    ],
];
EOT

cd ~/chd_gestion/fai_gestion/
editor config/bootstrap.php config/app.php
editor config/app_credentials.php # choose real DB credentials now
git add config/bootstrap.php config/app.php ../app-from-scratch.sh
git commit -m "Config : database, salt, inflections, datetime format"
# 7bf701764ff5661d053244b263cfe0be423faef5


# database init
sudo mariadb --defaults-extra-file=/etc/mysql/debian.cnf <<"EOT"
CREATE DATABASE IF NOT EXISTS fai_gestion;
CREATE DATABASE IF NOT EXISTS fai_gestion_exports;
CREATE USER IF NOT EXISTS 'fai_gestion'@'localhost' IDENTIFIED BY 'XXXXXXXXXXXXXXXX';
GRANT ALL PRIVILEGES ON  fai_gestion.* TO 'fai_gestion'@'localhost';
FLUSH PRIVILEGES;
EOT

# database schema modifications
# base on branch master (chd_gestion) 5709f164402a76dfd0e6ef098a45c73f976b48cd
# Fixup list for ~/chd_gestion/schema/schema-mysql.sql
# - sed -e 's/DEFINER=`gestion`@`localhost`/DEFINER=`fai_gestion`@`localhost`/g'
# - change v_relais SQL SECURITY INVOKER to SECURITY DEFINER=`fai_gestion`@`localhost`
# - move all views (v_*) in fai_gestion_exports because cake bake do bad things with them
# - DROP TABLE tmp_mac_seen;
# - DROP VIEW v_tmp_diff_seen_mac;
# - ALTER TABLE adherents DROP num_adt_ttn;
# - ALTER TABLE villes DROP tel_contact;
# - ALTER TABLE equipement_modeles CHANGE modele title VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
# - ALTER TABLE equipement_modeles ADD INDEX(title);
# - DROP TRIGGER equipements_insert;
# - DROP TRIGGER equipements_update;

cat ~/chd_gestion/schema/schema-mysql.sql | sudo mariadb fai_gestion
cat <<"EOT"
CREATE TABLE lien_filaire (
 id int(11) NOT NULL AUTO_INCREMENT,
 equipement_interface_id_1 int(11) NOT NULL,
 port_1 char(15) NOT NULL,
 equipement_interface_id_2 int(11) NOT NULL,
 port_2 char(15) NOT NULL,
 PRIMARY KEY (id),
 UNIQUE KEY equipement_interface_id_1 (equipement_interface_id_1,port_1,equipement_interface_id_2,port_2),
 KEY equipement_interface_id_2 (equipement_interface_id_2),
 CONSTRAINT lien_filaire_ibfk_1 FOREIGN KEY (equipement_interface_id_1) REFERENCES equipement_interfaces (id) ON UPDATE CASCADE,
 CONSTRAINT lien_filaire_ibfk_2 FOREIGN KEY (equipement_interface_id_2) REFERENCES equipement_interfaces (id) ON UPDATE CASCADE
);

CREATE TABLE lien_radio (
 id int(11) NOT NULL AUTO_INCREMENT,
 title varchar(64) NOT NULL,
 PRIMARY KEY (id),
 UNIQUE KEY title (title)
);

CREATE TABLE lien_tunnel (
 id int(11) NOT NULL AUTO_INCREMENT,
 endpoint_ip_1 varchar(39) NOT NULL,
 endpoint_port_1 int(5) NOT NULL,
 endpoint_ip_2 varchar(39) NOT NULL,
 endpoint_port_2 int(5) NOT NULL,
 equipement_interface_id_1 int(11) NOT NULL,
 equipement_interface_id_2 int(11) NOT NULL,
 tuntype varchar(15) NOT NULL DEFAULT 'tun',
 daemon_options varchar(255) DEFAULT NULL,
 PRIMARY KEY (id),
 UNIQUE KEY equipement_interface_id_1 (equipement_interface_id_1,equipement_interface_id_2),
 UNIQUE KEY endpoint_ip_1 (endpoint_ip_1,endpoint_port_1,endpoint_ip_2,endpoint_port_2),
 KEY equipement_interface_id_2 (equipement_interface_id_2),
 CONSTRAINT lien_tunnel_ibfk_1 FOREIGN KEY (equipement_interface_id_1) REFERENCES equipement_interfaces (id) ON UPDATE CASCADE,
 CONSTRAINT lien_tunnel_ibfk_2 FOREIGN KEY (equipement_interface_id_2) REFERENCES equipement_interfaces (id) ON UPDATE CASCADE
);
EOT
cat ~/chd_gestion/schema/views-mysql.sql | sudo mariadb fai_gestion_exports
cat ~/chd_gestion/schema/enum-tables-data-mysql.sql | sudo mariadb fai_gestion
(
	echo 'INSERT INTO ippubliques (ip4, ip6, secteur_id) VALUES'
	for i in $(seq 1 254)
	do
		[ $i -ne 254 ] && sep=',' || sep=';'
		printf "('185.131.43.%i', '2a03:a0a1:1:%x::', '1')$sep\n" $i $i
	done 
) | sudo mariadb fai_gestion

# Convert equipements.uplink tree to (equipement_interfaces, lien_cable, lien_radio, lien_tunnel)
# - ALTER TABLE equipements DROP uplink_id;
# - ALTER TABLE equipements CHANGE ipmgmt_id ip_management VARCHAR(39) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
# - import PROCEDURE refresh_network_elt(IN root INT)
# - TODO : work on fai_gestion_exports permissions
# - TODO : dump everything cleanly then git

# bake initial setup
cd ~/chd_gestion/fai_gestion/
composer.phar require --dev cakephp/bake:~1.0
yes | cake bake plugin CustomTheme
v=vendor/cakephp/bake/src/Template/Bake
p=plugins/CustomTheme/src/Template/Bake
mkdir -p $p/{Controller,Element/Controller,Model,Template}
cp -a $v/Controller/controller.twig $p/Controller/
cp -a $v/Element/form.twig $p/Element/
cp -a $v/Element/Controller/{add,edit,index}.twig $p/Element/Controller
cp -a $v/Model/{entity,table}.twig $p/Model/
cp -a $v/Template/{index,view}.twig $p/Template/
editor config/bootstrap.php config/bootstrap_cli.php
# load the plugin only in cli mode
git checkout -- config/bootstrap.php
git add ../app-from-scratch.sh composer.json composer.lock config/bootstrap_cli.php plugins/
git commit -m "Bake : setup and create empty CustomTheme"
# 31a40cfc446c9586f89a4aa69ef76d76d469e5a4


# Baking a cake (generate the CRUD)
cake bake all --theme=CustomTheme --everything
editor config/routes.php
# -$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
# +//$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
# +$routes->redirect('/', ['controller' => 'Adherents'], ['full' => false]);
# -$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
git add ../app-from-scratch.sh config/routes.php
git add src/Model/Entity/empty src/Model/Table/empty tests/Fixture/empty
git commit -m "first cake bake, auto-generated files not included for now"
# 18507a4c76abad7cf5e6e9572137d0dc5a977fcc

# Adding debug tool, tweaking date formatting
editor config/app.php config/bootstrap.php
git add ../app-from-scratch.sh config/app.php config/bootstrap.php
git commit -m "Adding debug tool, tweaking date formatting"
# eeb6aee61bc55a95a4d62d354f180d167c6a25fb

# bake : Commit imported&derived files from bake to keep the diffs
cp -a vendor/cakephp/bake/src/Shell/BakeShell.php plugins/CustomTheme/src/Shell/BakeShell.php
editor plugins/CustomTheme/src/Shell/BakeShell.php
git add plugins/CustomTheme/src/Shell/BakeShell.php
git commit -m "bake : Commit imported&derived files from bake to keep the diffs"
# 1eeb6c1ee3b538e2a3f5b940c32725ec068f21ba

# bake: Add config, generate less actions
# https://book.cakephp.org/3.0/fr/bake/development.html#creating-a-bake-theme
editor config/bake_extra.php
git add config/bake_extra.php

editor config/bootstrap_cli.php plugins/CustomTheme/config/bootstrap.php
git add config/bootstrap_cli.php plugins/CustomTheme/config/bootstrap.php

editor plugins/CustomTheme/src/Template/Bake/Element/Controller/_empty.twig
git add plugins/CustomTheme/src/Template/Bake/Element/Controller/_empty.twig

editor plugins/CustomTheme/src/Shell/BakeShell.php
git add plugins/CustomTheme/src/Shell/BakeShell.php

editor plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
git add plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php

git add ../app-from-scratch.sh
git commit -m "bake: Add configurability, generate less actions"
# 0dd134b71539f38d84db3b023ba42d2650df278a


# Add Copyright & GPL3+ notice to Templates
editor $p/Controller/controller.twig $p/Model/entity.twig $p/Model/table.twig $p/Template/index.twig $p/Template/view.twig
git add $p/Controller/controller.twig $p/Model/entity.twig $p/Model/table.twig $p/Template/index.twig $p/Template/view.twig
git commit -m "Add Copyright & GPL3+ notice to Templates"
# 9a73d523ebd6035fac8deaa347ce41e4eda13232

# Date picker in DD/MM/YYYY order
editor src/View/AppView.php
git add ../app-from-scratch.sh src/View/AppView.php
git commit -m "Date picker in DD/MM/YYYY order"
# 7de45a8e4b595856de2f0af78b13e4d2efc5e716

# bake all : skip some models and actions, via configuration
editor plugins/CustomTheme/src/Shell/BakeShell.php
git add ../app-from-scratch.sh plugins/CustomTheme/src/Shell/BakeShell.php
git commit -m "bake all : skip some models and actions, via configuration"
# 76ab63096a25f5bf7b9d076cdc9ab3fc5218d216

# bake: add Search filter support

# https://github.com/FriendsOfCake/search
composer.phar require friendsofcake/search
cake plugin load Search
git add src/Application.php config/bootstrap.php composer.json composer.lock

editor plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php $p/Model/table.twig
git add plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php $p/Model/table.twig

editor plugins/CustomTheme/config/bootstrap.php
git add plugins/CustomTheme/config/bootstrap.php

editor $p/Model/table.twig $p/Element/Controller/index.twig $p/Template/index.twig
git add $p/Model/table.twig $p/Element/Controller/index.twig $p/Template/index.twig

editor src/Template/Layout/default.ctp webroot/css/local.css
git add src/Template/Layout/default.ctp webroot/css/local.css

git add ../app-from-scratch.sh
git commit -m "bake add Search filter support"
# b59164b0b7451905adcca244e6395281eb0633ca

# index: no 'id' column by default
editor plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php plugins/CustomTheme/src/Template/Bake/Template/index.twig
git add plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php plugins/CustomTheme/src/Template/Bake/Template/index.twig
git add ../app-from-scratch.sh
git commit -m "index: no 'id' column by default"
# 5e90ca7ab1cddf94e500397549b85c54aed570da

# make side bar skinny, add shortcuts to main controllers
editor $p/Template/index.twig $p/Template/view.twig $p/Element/form.twig src/Template/Layout/default.ctp
git add $p/Template/index.twig $p/Template/view.twig $p/Element/form.twig src/Template/Layout/default.ctp
git add ../app-from-scratch.sh
git commit -m "make side bar skinny, add shortcuts to main controllers"
# 5cb131935f0e4a8fb4082ed989a17c214d1e4beb

# configure all filters, no align-right on 'view'
editor config/bake_extra.php webroot/css/local.css
git add config/bake_extra.php webroot/css/local.css ../app-from-scratch.sh
git commit -m "configure all filters, no align-right on 'view'"

# rename ippubliques -> ip_publiques, .gitignore autogenerated code for now
# MariaDB side done via phpMyAdmin
editor src/Template/Layout/default.ctp .gitignore
git add src/Template/Layout/default.ctp .gitignore
cake bake all --everything --force --quiet
git add ../app-from-scratch.sh
git commit -m "rename ippubliques -> ip_publiques, .gitignore autogenerated code for now"
# 51f0aacb4d4f2514433139552ac6ab8ab5506653

# no 200 item limit on drop-down lists, index : better codegen 
editor plugins/CustomTheme/src/Template/Bake/Element/Controller/*
git add plugins/CustomTheme/src/Template/Bake/Element/Controller/*
git add ../app-from-scratch.sh
git commit -m "no 200 item limit on drop-down lists, index : better codegen"