Skip to content
Browse files

narcissus: install packages one by one in the backend instead of doin…

…g an xmlhttprequest for each package
  • Loading branch information...
1 parent a37101b commit 49b1fb8ca3bd6dbd667c5f6a6d81cfc2e1ba02b8 @koenkooi koenkooi committed Jan 3, 2009
Showing with 43 additions and 46 deletions.
  1. +1 −1 index.php
  2. +8 −5 scripts/install-package.sh
  3. +34 −40 scripts/js/internal_request.js
View
2 index.php
@@ -131,7 +131,7 @@ function machine_dropdown() {
<div id="image_link"></div>
<div id="configure_progress"></div>
<div id="image_progress"></div>
-<div id="status"></div>
+<div id="imgstatus"></div>
</body>
View
13 scripts/install-package.sh
@@ -25,12 +25,15 @@ if [ -e ${TARGET_DIR}/log.txt ] ; then
rm ${TARGET_DIR}/log.txt
fi
-packagelist="$(echo ${PACKAGE} | tr -d '[~;:]' | sort | uniq)"
+packagelist="$(echo ${PACKAGE} | tr -d '[~;:]' | sed s:,:\ :g | sort | uniq)"
echo "installing $packagelist"
-echo "running: opkg-cl ${CACHE} -o ${TARGET_DIR} -f ${TARGET_DIR}/etc/opkg.conf install $packagelist"
-yes | bin/opkg-cl ${CACHE} -o ${TARGET_DIR} -f ${TARGET_DIR}/etc/opkg.conf install $packagelist | tee ${TARGET_DIR}/log.txt
+for pkg in $packagelist ; do
+ echo "running: opkg-cl ${CACHE} -o ${TARGET_DIR} -f ${TARGET_DIR}/etc/opkg.conf install $pkg"
+ yes | bin/opkg-cl ${CACHE} -o ${TARGET_DIR} -f ${TARGET_DIR}/etc/opkg.conf install $pkg | tee ${TARGET_DIR}/log.txt
+ grep -e "rror oc" -e "ollected er" ${TARGET_DIR}/log.txt
+ echo "<div id=\"${pkg}-returncode\">$?</div><br/>"
+done
echo "<div id=\"imgsize\">" $(du ${TARGET_DIR} -hs) "</div>"
-grep -e "rror oc" -e "ollected er" ${TARGET_DIR}/log.txt
-exit $?
+
View
74 scripts/js/internal_request.js
@@ -19,23 +19,21 @@ var packagelist = new Array;
var packagestring = "";
var opackage = "";
var progress_text = ""
-var FAIL_image = "<img src=\"img/X_mark.png\">";
-var succes_image = "<img src=\"img/Green_tick\">";
+var FAIL_image = "<img src='img/X_mark.png'>";
+var succes_image = "<img src='img/Green_tick'>";
function configureImage(){
showHideElement('intro',0);
showHideElement('image_progress',0);
-
-
document.getElementById('image_link').innerHTML = "";
document.getElementById('configure_progress').innerHTML = "";
document.getElementById('image_progress').innerHTML = "";
packagestring = concatArray(document.entry_form.pkg);
if (packagestring == "" || packagestring == " ") {
- document.getElementById('status').innerHTML = "You have to select at least one task, try 'task-boot' to get a minimal set.";
+ document.getElementById('imgstatus').innerHTML = "You have to select at least one task, try 'task-boot' to get a minimal set.";
return;
}
@@ -45,7 +43,7 @@ function configureImage(){
var packagelisttemp = packagestring.split(" ");
packagelist = unique(packagelisttemp);
-
+
progress_text = "<br/><br/><table>\n";
progress_text += "<tr><td colspan=\"2\">Preconfiguring image</td><td></td><td id='td-configure'></td></tr>\n";
progress_text += "<tr><td colspan=\"2\">Installing packages:</td><td></td><td id='td-package'></td></tr>\n";
@@ -58,7 +56,7 @@ function configureImage(){
progress_text += "<tr><td colspan=\"2\">Assembling image</td><td></td><td id='td-assemble'></td></tr>\n";
progress_text += "</table>\n";
-
+
document.getElementById('pkg_progress').innerHTML = progress_text;
@@ -80,8 +78,8 @@ function assembleImage(){
}
function installPackage(){
- if (opackage != "" && opackage != " ") {
- var params = 'action=install_package&machine=' + document.entry_form.machine.value + '&name=' + document.entry_form.name.value + '&pkgs=' + opackage;
+ if (packagelist != "" && packagelist != " ") {
+ var params = 'action=install_package&machine=' + document.entry_form.machine.value + '&name=' + document.entry_form.name.value + '&pkgs=' + packagelist;
http.open('post', 'backend.php');
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = installProgress;
@@ -100,39 +98,35 @@ function showImagelink(){
function configureProgress(){
if(http.readyState == 4){
- var response = http.responseText;
+ var response = http.responseText;
showHideElement('configure_progress', 0);
document.getElementById('configure_progress').innerHTML = response;
- document.getElementById('td-configure').innerHTML = succes_image;
- opackage = packagelist.shift();
- installPackage("test");
+ document.getElementById('td-configure').innerHTML = succes_image;
+ installPackage("test");
}
}
function installProgress(){
- if(http.readyState == 4){
+ if(http.readyState == 4){
var response = http.responseText;
document.getElementById('image_progress').innerHTML = response;
if(document.getElementById('imgsize')) {
- document.getElementById('status').innerHTML = "<br/>\nCurrent uncompressed image size: " + document.getElementById('imgsize').innerHTML.split(" ")[1];
- }
- var progress_id = 'td-' + opackage;
- // We grep for an error code, so '0' is indeed an error
- if(document.getElementById('retval').innerHTML == "0") {
- document.getElementById(progress_id).innerHTML = FAIL_image;
- }
- else {
- document.getElementById(progress_id).innerHTML = succes_image;
+ document.getElementById('imgstatus').innerHTML = "<br/>\nCurrent uncompressed image size: " + document.getElementById('imgsize').innerHTML.split(" ")[1];
}
- if (packagelist.length > 1) {
- opackage = packagelist.shift();
- if (opackage != "" && opackage != " ") {
- installPackage(opackage);
- }
- }
- else {
- assembleImage(opackage);
- }
+ for(var i=0; i < packagelist.length; i++){
+ var progress_id = 'td-' + packagelist[i];
+ var return_code = packagelist[i] + '-returncode';
+ // We grep for an error code, so '0' is indeed an error
+ if(document.getElementById(return_code)) {
+ if(document.getElementById(return_code).innerHTML == "0") {
+ document.getElementById(progress_id).innerHTML = FAIL_image;
+ }
+ else {
+ document.getElementById(progress_id).innerHTML = succes_image;
+ }
+ }
+ }
+ assembleImage("test");
}
}
@@ -147,7 +141,7 @@ function assembleProgress(){
else {
document.getElementById('td-assemble').innerHTML = FAIL_image;
}
- showImagelink();
+ showImagelink();
}
}
@@ -156,7 +150,7 @@ function imageDisplay(){
var response = http.responseText;
if(document.getElementById('imgsize')) {
var image_size = "<br/>\nCurrent uncompressed image size: " + document.getElementById('imgsize').innerHTML.split(" ")[1];
- document.getElementById('status').innerHTML = image_size;
+ document.getElementById('imgstatus').innerHTML = image_size;
}
document.getElementById('image_link').innerHTML = response;
pulsate(document.getElementById('image_link'));
@@ -196,12 +190,12 @@ function concatArray(varArray) {
function unique(a)
{
var r = new Array();
- o:for(var i = 0, n = a.length; i < n; i++) {
- for(var x = i + 1 ; x < n; x++)
- {
- if(a[x]==a[i]) continue o;
- }
- r[r.length] = a[i];
+o:for(var i = 0, n = a.length; i < n; i++) {
+ for(var x = i + 1 ; x < n; x++)
+ {
+ if(a[x]==a[i]) continue o;
}
+ r[r.length] = a[i];
+}
return r;
}

0 comments on commit 49b1fb8

Please sign in to comment.
Something went wrong with that request. Please try again.