Skip to content

Commit bf9c2c1

Browse files
committed
Merge branch 'release/1.0.5'
2 parents c45da52 + f6ab16c commit bf9c2c1

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

deploy.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@
7878
<title>Simple PHP GIT deploy script</title>
7979
<style>
8080
body { padding: 0 1em; background: #222; color: #fff; }
81-
h2 { color: #c33; }
81+
h2, .error { color: #c33; }
8282
.prompt { color: #6be234; }
8383
.command { color: #729fcf; }
84+
.output { color: #999; }
8485
</style>
8586
</head>
8687
<body>
@@ -104,7 +105,7 @@
104105
foreach (array('git', 'rsync') as $command) {
105106
$path = trim(shell_exec('which '.$command));
106107
if ($path == '') {
107-
die(sprintf('<b>%s</b> not available. It need to be installed on the server for this script to work.', $command));
108+
die(sprintf('<div class="error"><b>%s</b> not available. It need to be installed on the server for this script to work.</div>', $command));
108109
} else {
109110
$binaries[$command] = $path;
110111
$version = explode("\n", shell_exec($path.' --version'));
@@ -174,7 +175,7 @@
174175
);
175176

176177
// Remove the TMP_DIR
177-
$commands[] = sprintf(
178+
$commands['cleanup'] = sprintf(
178179
'rm -rf %s'
179180
, TMP_DIR
180181
);
@@ -185,16 +186,43 @@
185186
if (file_exists(TMP_DIR) && is_dir(TMP_DIR)) {
186187
chdir(TMP_DIR); // Ensure that we're in the right directory
187188
}
188-
$tmp = shell_exec($command.' 2>&1'); // Execute the command
189+
$tmp = array();
190+
exec($command.' 2>&1', $tmp, $return_code); // Execute the command
189191
// Output the result
190192
printf('
191193
<span class="prompt">$</span> <span class="command">%s</span>
192-
%s
194+
<div class="output">%s</div>
193195
'
194196
, htmlentities(trim($command))
195-
, htmlentities(trim($tmp))
197+
, htmlentities(trim(implode("\n", $tmp)))
196198
);
197199
flush(); // Try to output everything as it happens
200+
201+
// Error handling and cleanup
202+
if ($return_code !== 0) {
203+
$tmp = shell_exec($commands['cleanup']);
204+
printf('
205+
<div class="error">
206+
Error encountered!
207+
Stopping the script to prevent possible data loss.
208+
CHECK THE DATA IN YOUR TARGET DIR!
209+
</div>
210+
211+
212+
Cleaning up temporary files ...
213+
214+
<span class="prompt">$</span> <span class="command">%s</span>
215+
<div class="output">%s</div>
216+
'
217+
, htmlentities(trim($commands['cleanup']))
218+
, htmlentities(trim($tmp))
219+
);
220+
error_log(sprintf(
221+
'Deployment error! %s'
222+
, __FILE__
223+
));
224+
break;
225+
}
198226
}
199227
?>
200228

0 commit comments

Comments
 (0)