-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbackend.php
199 lines (171 loc) · 5.55 KB
/
backend.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
<?
/* Narcissus - Online image builder for the angstrom distribution
* Koen Kooi (c) 2008-2010 - all rights reserved
*
*/
$base_pkg_set = " task-base angstrom-version ";
if (isset($_POST["action"]) && $_POST["action"] != "") {
$action = $_POST["action"];
} else {
print "Invalid action: $action";
exit;
}
if (isset($_POST["machine"])) {
$machine = escapeshellcmd(basename($_POST["machine"]));
} else {
print "Invalid machine";
exit;
}
if (isset($_POST["name"]) && $_POST["name"] != "") {
$name = escapeshellcmd(basename($_POST["name"]));
} else {
$name = "unnamed";
}
if (isset($_POST["pkgs"]) && $_POST["pkgs"] != "") {
$pkg = $_POST["pkgs"];
} else {
$pkg = "task-boot";
}
if (isset($_POST["release"]) && $_POST["release"] != "") {
$release = $_POST["release"];
} else {
$release = "stable";
}
if (isset($_POST["imagetype"]) && $_POST["imagetype"] != "") {
$imagetype = $_POST["imagetype"];
} else {
$imagetype = "tgz";
$imagesuffix = "tar.gz";
}
if (isset($_POST["manifest"]) && $_POST["manifest"] != "") {
$manifest = $_POST["manifest"];
} else {
$manifest = "no";
}
if (isset($_POST["sdk"]) && $_POST["sdk"] != "") {
$sdk = $_POST["sdk"];
} else {
$sdk = "no";
}
if (isset($_POST["sdkarch"]) && $_POST["sdkarch"] != "") {
$sdkarch = $_POST["sdkarch"];
} else {
$sdkarch = "none";
}
switch($imagetype) {
case "tgz":
$imagesuffix = "tar.gz";
break;
case "sdimg":
$imagesuffix = "tar.gz";
break;
case "sdimg-ubi":
$imagesuffix = "tar.gz";
break;
case "ubifs":
$imagesuffix = "ubi";
break;
default:
$imagesuffix = $imagetype;
}
switch($action) {
case "assemble_image":
print "assembling\n";
assemble_image($machine, $name, $imagetype, $manifest, $sdk, $sdkarch);
break;
case "configure_image":
print "configuring\n";
configure_image($machine, $name, $release);
break;
case "show_image_link":
show_image_link($machine, $name, $imagesuffix, $manifest, $sdk, $sdkarch);
break;
case "install_package":
print "installing $pkg\n";
install_package($machine, $name, $pkg);
break;
}
function show_image_link($machine, $name, $imagesuffix, $manifest, $sdk, $sdkarch) {
$foundimage = 0;
$foundsdimage = 0;
$foundsdk = 0;
$foundsources = 0;
$printedcacheinfo = 0;
$printstring = "";
switch($sdkarch) {
case "intel32":
$sdkarchname = "i686";
break;
case "intel64":
$sdkarchname = "x86_64";
break;
default:
$sdkarchname = "i686";
break;
}
$randomname = substr(md5(time()), 0, 6);
$deploydir = "deploy/$machine/$randomname";
mkdir($deploydir,0777,TRUE);
$imagefiles = scandir("work/$machine");
print "<br/>";
foreach($imagefiles as $value) {
$location = "work/$machine/$value";
// The !== operator must be used. Using != would not work as expected
// because the position of 'a' is 0. The statement (0 != false) evaluates
// to false.
if(strpos($value, "$name-image-$machine-sd") !== false) {
rename($location, "$deploydir/$value");
$imgsize = round(filesize("$deploydir/$value") / (1024 * 1024),2);
$printstring .= "<a href='$deploydir/$value'>$value</a> [$imgsize MiB]<br/> ";
$foundsdimage = 1;
continue;
}
if(strpos($value, "$name-image-$machine.$imagesuffix") !== false) {
rename($location, "$deploydir/$value");
$imgsize = round(filesize("$deploydir/$value") / (1024 * 1024),2);
$imagestring .= "<br/><a href='$deploydir/$value'>$value</a> [$imgsize MiB]: This is the rootfs '$name' for $machine you just built. This will get automatically deleted after 2 days.<br/>";
rename("work/$machine/$name-image.bb", "$deploydir/$name-image.bb");
rename("work/$machine/$name-image.txt", "$deploydir/$name-image.txt");
if($manifest == "yes") {
rename("work/$machine/$name-image-manifest.html", "$deploydir/$name-image-manifest.html");
$imagestring .= "You can also have a look at the software <a href='$deploydir/$name-image-manifest.html' target='manifest'>manifest</a> for this rootfs<br/>";
}
$foundimage = 1;
}
//Angstrom-2010.05-narcissus-hawkboard-i686-random-d4ddcec6-image-toolchain.tar.gz
if(strpos($value, "narcissus-$machine-$sdkarchname-$name-image-$sdk") !== false) {
rename($location, "$deploydir/$value");
$sdksize = round(filesize("$deploydir/$value") / (1024 * 1024),2);
$imagestring .= "<br/><a href='$deploydir/$value'>$value</a> [$sdksize MiB]: $sdk for the generated rootfs.<br/>";
$foundsdk = 1;
}
//random-ed560fe9-image-sources/
if(strpos($value, "$name-image-sources") !== false) {
rename($location, "$deploydir/sources");
$foundsources = 1;
}
}
if ($foundimage == 0) {
print "Image not found, something went wrong :/";
} else {
print("$imagestring");
}
if($foundsdimage == 1) {
print(" <br/><br/> The raw SD card image(s) below have the intended size for the SD card is encoded in the file name, e.g. 1GiB for a one gigabyte card.<br/><br/> $printstring");
}
}
function configure_image($machine, $name, $release) {
print "Machine: $machine, name: $name\n";
passthru ("scripts/configure-image.sh $machine $name-image $release && exit");
}
function install_package($machine, $name, $pkg) {
print "Machine: $machine, name: $name, pkg: $pkg\n";
passthru ("scripts/install-package.sh $machine $name-image $pkg && exit", $installretval);
print "<div id=\"retval\">$installretval</div>";
}
function assemble_image($machine, $name, $imagetype, $manifest, $sdk, $sdkarch) {
print "Machine: $machine, name: $name, type: $imagetype\n";
passthru ("scripts/assemble-image.sh $machine $name-image $imagetype $manifest $sdk $sdkarch && exit", $installretval);
print "<div id=\"retval-image\">$installretval</div>";
}
?>