-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcli_install.php
192 lines (156 loc) · 8.21 KB
/
cli_install.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
<?php
/*
* This file is part of the installation process. The first part is the install.sh file.
*/
if ($argc < 3) {
echo "usage: " . $argv[0] . " <php_path> <ffmpeg_path>" .
"\n <php_path> the path to the php binary";
"\n <ffmpeg_path> the path to the ffmpeg binary";
die;
}
require_once(__DIR__."/lib_install.php");
$in_install = true; //check usage in global_config.inc, this allow including the global_config_sample without failing
echo "Is this recorder a [M]aster or a [R]emote recorder?" . PHP_EOL;
echo "The master controls the recording and serve the web interface, while the slave is used only as an second video source." . PHP_EOL;
$choice = "";
while($choice != "M" && $choice != "R")
$choice = strtoupper(read_line("[M/R]: "));
$master = $choice == "M";
if (file_exists("global_config.inc") && filesize("global_config.inc") > 0) {
require_once 'global_config.inc';
echo "Would you like to setup EZrecorder's global configuration now? (global_config.inc)" . PHP_EOL;
while(strtoupper($choice) != "Y" && strtoupper($choice) != "N" && $choice !== "")
$choice = read_line("[Y/n]: ");
$create_global_config = strtoupper($choice) == "Y" || $choice == "";
} else {
require_once 'global_config_sample.inc';
$php_cli_cmd = $argv[1];
$ffmpeg_cli_cmd = $argv[2];
$create_global_config = true;
}
/*
* First, we add user's configuration in global-config.inc
*/
if ($create_global_config) {
echo "Please enter now the requested values: " . PHP_EOL;
$value = read_line("Name of the classroom where the recorder is installed ['$classroom']: ");
if ($value != "")
$classroom = $value;
$value = read_line("Static IP address of this recorder ['$ezrecorder_ip']: ");
if ($value != "")
$ezrecorder_ip = $value;
if(!test_connect($ezrecorder_ip, 2000))
echo "This IP does not seems to be valid. You should double-check it and fix it in the final config file if needed." . PHP_EOL;
$value = read_line("Recorder username (used to launch bash scripts) ['$ezrecorder_username']: ");
if ($value != "")
$ezrecorder_username = $value;
$value = read_line("Path to the local video storage ['$ezrecorder_recorddir']: ");
if ($value != "")
$ezrecorder_recorddir = $value;
$value = read_line("Path to the webspace (where the static web files will be placed) ['$web_basedir']: ");
if ($value != "")
$web_basedir = $value;
$value = read_line("URL to EZmanager server ['$ezcast_manager_url']: ");
if ($value != "")
$ezcast_manager_url = $value;
$value = read_line("EZrecorder's alerts destination mail address ['$mailto_admins']: ");
if ($value != "")
$mailto_admins = $value;
$value = read_line("Apache's username [" .$ezrecorder_web_user. "]: ");
if ($value != "")
$ezrecorder_web_user = $value;
if($master) {
$value = read_line("Remote recorder IP. This IP must be accessible from EZmanager server. (leave empty if you don't use a remote) [" .$remote_recorder_ip. "]: ");
if ($value != "")
$remote_recorder_ip = $value;
$value = read_line("Remote recorder username (leave empty if you don't use a remote) [" .$remote_recorder_username. "]: ");
if ($value != "")
$remote_recorder_username = $value;
}
$config = file_get_contents(__DIR__ . "/global_config_sample.inc");
$config = preg_replace('/\$classroom = (.+);/', '\$classroom = "' . $classroom . '";', $config);
$config = preg_replace('/\$ezrecorder_ip = (.+);/', '\$ezrecorder_ip = "' . $ezrecorder_ip . '";', $config);
$config = preg_replace('/\$ezrecorder_username = (.+);/', '\$ezrecorder_username = "' . $ezrecorder_username . '";', $config);
$config = preg_replace('/\$ezrecorder_recorddir = (.+);/', '\$ezrecorder_recorddir = "' . $ezrecorder_recorddir . '";', $config);
$config = preg_replace('/\$web_basedir = (.+);/', '\$web_basedir = "' . $web_basedir . '";', $config);
$config = preg_replace('/\$ezrecorder_web_user = (.+);/', '\$ezrecorder_web_user = "' . $ezrecorder_web_user . '";', $config);
$config = preg_replace('/\$ezcast_manager_url = (.+);/', '\$ezcast_manager_url = "' . $ezcast_manager_url . '";', $config);
$config = preg_replace('/\$mailto_admins = (.+);/', '\$mailto_admins = "' . $mailto_admins . '";', $config);
$config = preg_replace('/\$php_cli_cmd = (.+);/', '\$php_cli_cmd = "' . $php_cli_cmd . '";', $config);
$config = preg_replace('/\$ffmpeg_cli_cmd = (.+);/', '\$ffmpeg_cli_cmd = "' . $ffmpeg_cli_cmd . '";', $config);
$config = preg_replace('/\$remote_recorder_ip = (.+);/', '\$remote_recorder_ip = "' . $remote_recorder_ip . '";', $config);
$config = preg_replace('/\$remote_recorder_username = (.+);/', '\$remote_recorder_username = "' . $remote_recorder_username . '";', $config);
file_put_contents(__DIR__. "/global_config.inc", $config);
echo PHP_EOL . __DIR__ . "/global_config.inc" . " was created with given values." . PHP_EOL;
}
/*
* Then, we adapt some paths in configuration files
*/
echo "Modification of global values in ./sbin/localdefs" . PHP_EOL;
$sbin_file = file_get_contents($basedir . "/sbin/localdefs_sample");
$sbin_file = str_replace("!PATH", $basedir, $sbin_file);
$sbin_file = str_replace("!CLASSROOM", $classroom, $sbin_file);
$sbin_file = str_replace("!MAIL_TO", $mailto_admins, $sbin_file);
file_put_contents($basedir . "/sbin/localdefs", $sbin_file);
echo "Modification of global values in ./setperms.sh" . PHP_EOL;
$perms_file = file_get_contents("$basedir/setperms_sample.sh");
$perms_file = str_replace("!USER", $ezrecorder_username, $perms_file);
$perms_file = str_replace("!WEB_USER", $ezrecorder_web_user, $perms_file);
file_put_contents("$basedir/setperms.sh", $perms_file);
/*
* Then, we create working directories in RECORD_PATH
*/
echo "Creation of working directories in $ezrecorder_recorddir" . PHP_EOL;
system("mkdir -p $ezrecorder_recorddir/upload_ok");
system("mkdir -p $ezrecorder_recorddir/upload_to_server");
system("mkdir -p $ezrecorder_recorddir/local_processing");
system("mkdir -p $ezrecorder_recorddir/trash");
system("chown -R $ezrecorder_username $ezrecorder_recorddir");
system("chmod -R 777 $ezrecorder_recorddir");
/*
* Finaly, we copy htdocs from BASEDIR to WEB_BASEDIR
*/
echo "Creation of web content in $web_basedir" . PHP_EOL;
system("mkdir -p $web_basedir");
system("cp -rp $basedir/htdocs/* $web_basedir/.");
system("chown -R $ezrecorder_username:$ezrecorder_web_user $web_basedir");
system("chown -R $ezrecorder_username:$ezrecorder_web_user $basedir");
system("chmod 755 $basedir/setperms.sh");
$web_file_path = $web_basedir . "/services/root.inc";
$web_file = file_get_contents($web_file_path);
$web_file = str_replace("!ROOT", $basedir, $web_file);
file_put_contents($web_file_path, $web_file);
echo "Modification of global values in $web_basedir/index.php" . PHP_EOL;
$web_file = file_get_contents($web_basedir . "/index.php");
$web_file = str_replace("!PATH", $basedir, $web_file);
file_put_contents($web_basedir . "/index.php", $web_file);
if($master) {
require("cli_install_modules_selection.php");
require("cli_install_modules_config.php");
} else {
echo "Nothing else to configure for remote recorders" . PHP_EOL;
echo "\033[31mIf you're using the old remote_fmle_cutlist/remote_fmle_regular/remote_qtb, you'll still need to execute remote_modules/*/cli_install.php.'\033[0m" . PHP_EOL;
}
echo PHP_EOL;
echo "*******************************************************************" . PHP_EOL;
echo "* T E M P L A T E S G E N E R A T I O N *" . PHP_EOL;
echo "*******************************************************************" . PHP_EOL;
echo PHP_EOL;
//regenerate template files
require_once("lib_template.php");
echo "Templates for all languages will be generated in folder 'tmpl'" . PHP_EOL;
$res = template_generate("tmpl_sources/", "fr", "tmpl", $error);
if(!$res) {
echo $error . PHP_EOL;
}
$res = template_generate("tmpl_sources/", "en", "tmpl", $error);
if(!$res) {
echo $error . PHP_EOL;
}
echo "Templates generation done" . PHP_EOL;
//Try to connect on port 80. return 0 on failure, 1 on success
function test_connect($host, $timeout) {
if(fSockOpen($host, 80, $errno, $errstr, $timeout))
return 1;
return 0;
}