summaryrefslogtreecommitdiff
path: root/maj/gen.php
diff options
context:
space:
mode:
Diffstat (limited to 'maj/gen.php')
-rw-r--r--maj/gen.php15
1 files changed, 10 insertions, 5 deletions
diff --git a/maj/gen.php b/maj/gen.php
index e6bb308..cf46a4f 100644
--- a/maj/gen.php
+++ b/maj/gen.php
@@ -107,7 +107,7 @@ switch ($_POST['profile']) {
$profile="DEVICE_$target";
$user_filename="mise-a-jour-routeur-$target.bin";
-$gen_filename="bin/targets/ar71xx/generic/lede-17.01.2-ar71xx-generic-$target-squashfs-factory$region.bin";
+$gen_fileglob="bin/targets/ar71xx/generic/lede-*-ar71xx-generic-$target-squashfs-factory$region.bin";
if ( !$res ) {
echo "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"utf-8\" />\n</head>\n<body>\n<h2>Oops, une erreur s'est produite</h2><div>Il y a un problème avec les renseignements fournis<br><ul>\n";
@@ -153,21 +153,26 @@ if ( ! flock($fh, LOCK_EX) ) {
exit();
}
+// Run the imagebuilder make command
putenv("CACHE_DIR=$basepath/");
putenv("BUILD_DIR=$basepath/build/");
exec($command, $output, $return_val);
+// Match produced file against expected filename
+$gen_matchedfiles = glob("$basepath/build/$gen_fileglob");
+
// Dump script output in /tmp for troobleshooting
file_put_contents(tempnam('/tmp' , $scriptfile.'_'), array($command, "\n", print_r($output,true), "\n",$return_val,"\n"));
-
-if ( $return_val === 0 ) {
+if ( $return_val === 0 && count($gen_matchedfiles) === 1) {
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=$user_filename");
- readfile("$basepath/build/$gen_filename");
+ readfile($gen_matchedfiles[0]);
} else {
echo "<pre>\n$command\n\n";
echo join($output, "\n") . "\n\n";
- echo "Command return value : "; var_dump($return_val);
+ echo "Expected file pattern : '$basepath/build/$gen_fileglob'"; echo "\n";
+ echo "Matched files : "; print_r($gen_matchedfiles); echo "\n";
+ echo "Command return value : "; var_dump($return_val); echo "\n";
}
fclose($fh);