-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate.php
476 lines (360 loc) · 15.1 KB
/
update.php
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/usr/bin/php
<?php
// ------------------------------------------------------------
// (c) 2023/2025 by WRXB288 lagmrs.com all rights reserved
//
// Node image live upgrade system. for GMRSHUB Louisiana Image
// Merges from old code into new image
// -------------------------------------------------------------
// 1.9 09/18/23 added cleanup of license files and linefeeds
// 2.1 10/02/23 Stop backing up the log
// 2.3 11/12/23 make extra backups rpt iax
// 2.7 1/24 Support for new sounds.
// 3.1 6/14/24 There was a bug in the reistall of our nodes audio file.
// 3.2 2/10/25 Rebuild for automated upgrade for image
$verInstaller= "3.2"; $verRt="2-10-2025"; $changeall=false;
$year = date("Y");
print "
-----------------------------------------------------------------------------
System Update Module $verInstaller Release Date:$verRt
(c) 2023/$year by WRXB288 lagmrs.com all rights reserved
-----------------------------------------------------------------------------
This will Update the Louisiana Node image to the currect release.
Be sure you have backups. Use Win32DiskImager in read mode to make backups.
If you dont have a backup STOP and make one now PLEASE.
If you need help just ask.
u) Update (any other key to abort!)\n
";
$a = readline('Enter your command: ');
if ($a <> "u"){die;}
$docRouteP="/srv/http";
$path = "/etc/asterisk/local/mm-software";
$repoURL= "https://raw.githubusercontent.com/tmastersmart/gmrs_live/main";
$pathS = "$path/sounds";//if(!is_dir($pathS)){ mkdir($pathS, 0755);}
$pathR = "$path/repo"; // if(!is_dir($pathR)){ mkdir($pathR, 0755);}
$pathB = "$path/backup";if(!is_dir($pathB)){ mkdir($pathB, 0755);}
$pathG = "$docRouteP/status";//if(!is_dir($pathG)){ mkdir($pathG, 0755);}
$pathGA= "$docRouteP/admin";//if(!is_dir($pathGA)){ mkdir($pathGA, 0755);}
$pathGE= "$docRouteP/images";//if(!is_dir($pathGE)){ mkdir($pathGE, 0755);}
$pathI = "$docRouteP/status/images";//if(!is_dir($pathI)){ mkdir($pathI, 0755);}
$pathF = "/usr/local/sbin/firsttime";
$pathN = "/var/lib/asterisk/sounds/rpt/nodenames";
print "Running Live upgrade system ...........\n";
chdir($pathR);
if (file_exists("$pathR/version.txt")) {rename ("$pathR/version.txt", "$path/version-pending.txt"); }
// first check for core
if (file_exists("$pathR/core-download.zip")) {
exec("unzip $pathR/core-download.zip",$output,$return_var);
foreach (glob("*.php") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing php file:$path/$file ";
if (file_exists("$path/$file")){unlink("$path/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){
rename ("$pathR/$file", "$path/$file");
exec("sudo chmod +x $path/$file",$output,$return_var);
}
print"ok\n";
}
}
foreach (glob("*.csv") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing csv file:$path/$file ";
if (file_exists("$path/$file")){unlink("$path/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$path/$file"); }
print"ok\n";
}
}
foreach (glob("*.txt") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing txt file:$path/$file ";
if (file_exists("$path/$file")){unlink("$path/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$path/$file"); }
print"ok\n";
}
}
}
// end of the core files.
// sounds files
if (file_exists("$pathR/sounds.zip")){
// for this version we are only installing new files
// chdir($pathS); clean_repo($pathS);
chdir($pathR);
exec("unzip $pathR/sounds.zip",$output,$return_var);
foreach (glob("*.wav") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing wav file:$pathS/$file ";
if (file_exists("$pathS/$file")){unlink("$pathS/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathS/$file");} // Move it into the SOUNDS
print"ok\n";
}
}
foreach (glob("*.ul") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ul file:$pathS/$file ";
if (file_exists("$pathS/$file")){unlink("$pathS/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathS/$file");} // Move it into the SOUNDS
print"ok\n";
}
}
foreach (glob("*.gsm") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing gsm file:$pathS/$file ";
if (file_exists("$pathS/$file")){unlink("$pathS/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathS/$file");} // Move it into the SOUNDS
print"ok\n";
}
}
}
// end new sounds
// install the status page updates
if (file_exists("$pathR/status.zip")){
exec("unzip $pathR/status.zip",$output,$return_var);
chdir($pathR);
//if (file_exists("$pathR/setup.edit.php")){unlink("$pathR/setup.edit.php");}// Make sure this file is not in non admin area.
foreach (glob("*.php") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing php file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.css") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing css file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.js") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing js file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.csv") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing csv file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
foreach (glob("*.txt") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing txt file:$pathG/$file ";
if (file_exists("$pathG/$file")){unlink("$pathG/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathG/$file");}
print"ok\n";
}
}
}
// end of status page updates
if (file_exists("$pathR/admin.zip")){
exec("unzip $pathR/admin.zip",$output,$return_var);
//$pathGA = "$pathG/admin";
chdir($pathR);
foreach (glob("*.php") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing php file:$pathGA/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
foreach (glob("*.css") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing css file:$pathGE/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
foreach (glob("*.js") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing js file:$pathGE/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
foreach (glob("*.csv") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ini file:$pathGA/$file ";
if (file_exists("$pathGA/$file")){unlink("$pathGA/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathGA/$file");}
print"ok\n";
}
}
}
// end of admin
if (file_exists("$pathR/images-s.zip")){
exec("unzip $pathR/images-s.zip",$output,$return_var);
//$pathI = "$pathG/images";
chdir($pathR);
foreach (glob("*.gif") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing gif file:$pathI/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
foreach (glob("*.jpg") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing jpg file:$pathI/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
foreach (glob("*.png") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing png file:$pathI/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
foreach (glob("*.ico") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ico file:$pathGA/$file ";
if (file_exists("$pathI/$file")){unlink("$pathI/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI/$file");}
print"ok\n";
}
}
}
// end images
if (file_exists("$pathR/images.zip")){
exec("unzip $pathR/images.zip",$output,$return_var);
//$pathI = "$pathG/images";
chdir($pathR);
foreach (glob("*.gif") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing gif file:$pathI/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
foreach (glob("*.jpg") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing jpg file:$pathI/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
foreach (glob("*.png") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing png file:$pathI/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
foreach (glob("*.ico") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ico file:$pathGA/$file ";
if (file_exists("$pathI2/$file")){unlink("$pathI2/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathI2/$file");}
print"ok\n";
}
}
}
// end images
//======================================
// "/var/lib/asterisk/sounds/rpt/nodenames"; $pathN
if (file_exists("$pathR/nodenames.zip")){
exec("unzip $pathR/nodenames.zip",$output,$return_var);
foreach (glob("*.ul") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing ul file:$pathN/$file ";
if (file_exists("$pathN/$file")){unlink("$pathN/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathN/$file");print"--";} // Move it into the SOUNDS
print"ok\n";
}
}
}
// end nodenames. we wont update this very often
// this is the admin menu install
if (file_exists("$pathR/firsttime.zip")){
exec("unzip $pathR/firsttime.zip",$output,$return_var);
foreach (glob("*.sh") as $file) {
if($file == '.' || $file == '..') continue;
if (is_file($file)) {
print"Installing sh file:$pathN/$file ";
if (file_exists("$pathF/$file")){unlink("$pathF/$file");print"Replacing ";}// kill existing file
if (file_exists("$pathR/$file")){rename ("$pathR/$file", "$pathF/$file");print"--";} // Move it into the SOUNDS
exec("sudo chmod 755 $pathF/$file",$output,$return_var); print"CHMOD 755";
print"ok\n";
}
}
}
// end menus. Admin may need to be added later
// --------------------- expansion replace others at later date -----------------------
$pathB = "$path/backup";
// make backups, erase the old ones to save space
$file = "$path/setup.txt"; $file2= "$pathB/setup.txt"; if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "$path/mm-node.txt"; $file2= "$pathB/mm-node.txt";if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "$path/logs/log.txt";$file2= "$pathB/log.txt"; if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "/etc/asterisk/rpt.conf";$file2= "$pathB/rpt.cfg";if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "/etc/asterisk/iax.conf";$file2= "$pathB/iax.cfg";if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
$file = "/etc/asterisk/manager.conf";$file2= "$pathB/manager.cfg"; if (file_exists($file2)){unlink($file2);}
copy($file, $file2);print "Backup $file2\n";
chdir($pathR); clean_repo($pathR);
// cleanup old unused files
$file="$path/license-sounds.txt";if (file_exists($file)){unlink($file);}
$file="$path/license-core.txt"; if (file_exists($file)){unlink($file);}
$file="$path/license-web.txt"; if (file_exists($file)){unlink($file);}
$file="$path/version.txt"; if (file_exists($file)){unlink($file);}
rename ("$path/version-pending.txt", "$file");
print "----\n";
print "Finished Upgrade. In most cases this is a live update. No reboot needed.!\n";
print "Admin screens wont change unless you logout and back in. \n";
print "Louisiana Image its just better!\n\n";
print "Press ANY Key\n";
$a = readline('Ready: ');
die;
function clean_repo($in){
chdir($in);
$files = glob($in.'/*');
foreach($files as $filed) {
if($filed == '.' || $filed == '..') continue;
if (is_file($filed)) { unlink($filed);print"del $filed\n"; }
}
}
?>