Skip to content

Commit

Permalink
setup builds directories
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Oct 9, 2010
1 parent 2110f53 commit 9198573
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
4 changes: 3 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var action = {
if (argv._.length == 0) {
throw 'Usage: deploy [directory] {options}'
}
setup.deploy(argv._[0]);
setup.deploy(argv._[0], argv, function (err) {
if (err) console.error('Error: ' + err);
});
}
}[cmd];

Expand Down
46 changes: 44 additions & 2 deletions lib/models/setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
var spawn = require('child_process').spawn;
var sys = require('sys');
var fs = require('fs');
var path = require('path');

exports.deploy = function (dir) {
console.log('Deploying StackVM to ' + sys.inspect(dir));
var Step = require('step');

exports.deploy = function (dir, opts, cb) {
var self = this;
console.log('Deploying StackVM to ' + dir);
Step(
function () { self.hasQemu(this) },
function (err, hasQemu) {
if (err) cb(err);
else if (!hasQemu) {
cb('Qemu not detected in $PATH with `which qemu`. '
+ ' If you still want to install, specify --no-qemu');
}
else {
path.exists(dir, this.parallel());
path.exists(dir + '/users', this.parallel());
path.exists(dir + '/data', this.parallel());
}
},
function mkdirs (err, root, users, data) {
if (err) cb(err);
else if (users[0]) {
cb(dir + '/users directory already exists');
}
else if (data[0]) {
cb(dir + '/data directory already exists');
}
else if (!root[0]) {
fs.mkdir(dir, 0700, (function (err) {
mkdirs.bind(this)(err, [true], [false], [false]);
}).bind(this));
}
else {
fs.mkdir(dir + '/users', 0700, this.parallel());
fs.mkdir(dir + '/data', 0700, this.parallel());
}
},
function (err) {
if (err) cb(err);
else cb(null);
}
);
};

exports.hasQemu = function (cb) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"base64" : ">=1.0.1",
"video" : ">=1.0.2",
"supermarket" : ">=1.0.1",
"cart" : ">=1.0.6"
"cart" : ">=1.0.6",
"step" : ">=0.0.3"
},
"engine" : ["node >=0.2.0"],
"bin" : { "stackvm" : "./server.js" }
Expand Down

0 comments on commit 9198573

Please sign in to comment.