Skip to content

Commit

Permalink
proper use of connection exec during update
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Feb 17, 2016
1 parent 5798738 commit c5e138e
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions lib/tessel/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,34 @@ Tessel.prototype.update = function(newImage) {
Tessel.prototype.updateOpenWRT = function(image) {
logs.info('Updating OpenWRT (1/2)');

// Write the new image to a file in the /tmp dir
return this.connection.exec(commands.openStdinToFile(updatePath))
.then((remoteProc) => {
return new Promise(function(resolve) {
logs.info('Transferring image of size', (image.length / 1e6).toFixed(2), 'MB');
// When we finish writing the image
remoteProc.once('close', resolve);
// Write the image
remoteProc.stdin.end(image);
});
})
.then(() => {
return new Promise((resolve, reject) => {
// Write the new image to a file in the /tmp dir
this.connection.exec(commands.openStdinToFile(updatePath), (err, remoteProc) => {
if (err) {
return reject(err);
}

logs.info('Transferring image of size', (image.length / 1e6).toFixed(2), 'MB');
// When we finish writing the image
remoteProc.once('close', resolve);
// Write the image
remoteProc.stdin.end(image);
});
})
.then(() => {
return new Promise((resolve) => {
// Begin the sysupgrade
logs.info('Starting OpenWRT update. Please do not remove power from Tessel.');
// The USBDaemon will cut out or the SSH command will close
return this.connection.exec(commands.sysupgrade(updatePath));
})
.then((remoteProc) => {
// This is the best way I've figured out to tell
// when the update is complete. I realize that tying completion
// of the CLI command to random text output by OpenWRT might not
// be the best thing...
return new Promise(function(resolve) {
this.connection.exec(commands.sysupgrade(updatePath), (err, remoteProc) => {
remoteProc.stdout.on('data', function(d) {
if (d.toString().includes('Upgrade completed')) {
resolve();
}
});
});
});
});
};

Tessel.prototype.updateFirmware = function(image) {
Expand Down

0 comments on commit c5e138e

Please sign in to comment.