mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-09 04:14:15 +00:00
Merge pull request #203 from resin-io/jviotti/feature/os-initialize
Implement os initialize command
This commit is contained in:
commit
4072edcced
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Promise, _, capitano, commandOptions, events, form, fs, helpers, init, patterns, resin, rimraf, stepHandler, tmp, umount, vcs, visuals;
|
||||
var Promise, _, capitano, commandOptions, events, form, fs, patterns, resin, rimraf, tmp, vcs, visuals;
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
@ -17,18 +17,12 @@
|
||||
|
||||
events = require('resin-cli-events');
|
||||
|
||||
init = require('resin-device-init');
|
||||
|
||||
fs = Promise.promisifyAll(require('fs'));
|
||||
|
||||
rimraf = Promise.promisify(require('rimraf'));
|
||||
|
||||
umount = Promise.promisifyAll(require('umount'));
|
||||
|
||||
patterns = require('../utils/patterns');
|
||||
|
||||
helpers = require('../utils/helpers');
|
||||
|
||||
tmp = Promise.promisifyAll(require('tmp'));
|
||||
|
||||
tmp.setGracefulCleanup();
|
||||
@ -135,24 +129,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
stepHandler = function(step) {
|
||||
var bar;
|
||||
step.on('stdout', _.bind(process.stdout.write, process.stdout));
|
||||
step.on('stderr', _.bind(process.stderr.write, process.stderr));
|
||||
step.on('state', function(state) {
|
||||
if (state.operation.command === 'burn') {
|
||||
return;
|
||||
}
|
||||
return console.log(helpers.stateToString(state));
|
||||
});
|
||||
bar = new visuals.Progress('Writing Device OS');
|
||||
step.on('burn', _.bind(bar.update, bar));
|
||||
return new Promise(function(resolve, reject) {
|
||||
step.on('error', reject);
|
||||
return step.on('end', resolve);
|
||||
});
|
||||
};
|
||||
|
||||
exports.init = {
|
||||
signature: 'device init',
|
||||
description: 'initialise a device with resin os',
|
||||
@ -171,28 +147,8 @@
|
||||
return capitano.runAsync("os download --output " + temporalPath);
|
||||
}).then(function(temporalPath) {
|
||||
return capitano.runAsync("device register " + application.app_name).then(resin.models.device.get).tap(function(device) {
|
||||
console.log('Configuring operating system');
|
||||
return capitano.runAsync("os configure " + temporalPath + " " + uuid).then(function() {
|
||||
console.log('Initializing device');
|
||||
return resin.models.device.getManifestBySlug(application.device_type).then(function(manifest) {
|
||||
var ref;
|
||||
return form.run((ref = manifest.initialization) != null ? ref.options : void 0);
|
||||
}).tap(function(answers) {
|
||||
var message;
|
||||
if (answers.drive != null) {
|
||||
message = "This will erase " + answers.drive + ". Are you sure?";
|
||||
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umount.umountAsync);
|
||||
}
|
||||
}).then(function(answers) {
|
||||
return init.initialize(temporalPath, device.uuid, answers).then(stepHandler)["return"](answers);
|
||||
}).tap(function(answers) {
|
||||
if (answers.drive == null) {
|
||||
return;
|
||||
}
|
||||
return umount.umountAsync(answers.drive).tap(function() {
|
||||
return console.log("You can safely remove " + answers.drive + " now");
|
||||
});
|
||||
});
|
||||
return capitano.runAsync("os configure " + temporalPath + " " + device.uuid).then(function() {
|
||||
return capitano.runAsync("os initialize " + temporalPath + " " + device.uuid);
|
||||
});
|
||||
}).then(function(device) {
|
||||
console.log('Done');
|
||||
|
@ -1,10 +1,14 @@
|
||||
(function() {
|
||||
var _, form, fs, helpers, init, manager, resin, stepHandler, visuals;
|
||||
var Promise, _, form, fs, helpers, init, manager, patterns, resin, stepHandler, umount, visuals;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
umount = Promise.promisifyAll(require('umount'));
|
||||
|
||||
resin = require('resin-sdk');
|
||||
|
||||
manager = require('resin-image-manager');
|
||||
@ -17,6 +21,8 @@
|
||||
|
||||
helpers = require('../utils/helpers');
|
||||
|
||||
patterns = require('../utils/patterns');
|
||||
|
||||
exports.download = {
|
||||
signature: 'os download <type>',
|
||||
description: 'download an unconfigured os image',
|
||||
@ -83,4 +89,34 @@
|
||||
}
|
||||
};
|
||||
|
||||
exports.initialize = {
|
||||
signature: 'os initialize <image> <uuid>',
|
||||
description: 'initialize an os image',
|
||||
help: 'Use this command to initialize a previously configured operating system image.\n\nExamples:\n\n $ resin os initialize ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
console.info('Initializing device');
|
||||
return resin.models.device.get(params.uuid).then(resin.models.device.getManifestBySlug).then(function(manifest) {
|
||||
var ref;
|
||||
return (ref = manifest.initialization) != null ? ref.options : void 0;
|
||||
}).then(form.run).tap(function(answers) {
|
||||
var message;
|
||||
if (answers.drive == null) {
|
||||
return;
|
||||
}
|
||||
message = "This will erase " + answers.drive + ". Are you sure?";
|
||||
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umount.umountAsync);
|
||||
}).tap(function(answers) {
|
||||
return init.initialize(params.image, params.uuid, answers).then(stepHandler);
|
||||
}).then(function(answers) {
|
||||
if (answers.drive == null) {
|
||||
return;
|
||||
}
|
||||
return umount.umountAsync(answers.drive).tap(function() {
|
||||
return console.info("You can safely remove " + answers.drive + " now");
|
||||
});
|
||||
}).nodeify(done);
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
@ -96,6 +96,8 @@
|
||||
|
||||
capitano.command(actions.os.configure);
|
||||
|
||||
capitano.command(actions.os.initialize);
|
||||
|
||||
capitano.command(actions.logs);
|
||||
|
||||
update.notify();
|
||||
|
@ -74,6 +74,7 @@ Now you have access to all the commands referenced below.
|
||||
|
||||
- [os download <type>](#os-download-60-type-62-)
|
||||
- [os configure <image> <uuid>](#os-configure-60-image-62-60-uuid-62-)
|
||||
- [os initialize <image> <uuid>](#os-initialize-60-image-62-60-uuid-62-)
|
||||
|
||||
- Wizard
|
||||
|
||||
@ -578,6 +579,14 @@ Examples:
|
||||
|
||||
$ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
|
||||
|
||||
## os initialize <image> <uuid>
|
||||
|
||||
Use this command to initialize a previously configured operating system image.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os initialize ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
|
||||
|
||||
# Wizard
|
||||
|
||||
## quickstart [name]
|
||||
|
@ -6,12 +6,9 @@ visuals = require('resin-cli-visuals')
|
||||
vcs = require('resin-vcs')
|
||||
form = require('resin-cli-form')
|
||||
events = require('resin-cli-events')
|
||||
init = require('resin-device-init')
|
||||
fs = Promise.promisifyAll(require('fs'))
|
||||
rimraf = Promise.promisify(require('rimraf'))
|
||||
umount = Promise.promisifyAll(require('umount'))
|
||||
patterns = require('../utils/patterns')
|
||||
helpers = require('../utils/helpers')
|
||||
tmp = Promise.promisifyAll(require('tmp'))
|
||||
tmp.setGracefulCleanup()
|
||||
|
||||
@ -174,23 +171,6 @@ exports.rename =
|
||||
events.send('device.rename', device: params.uuid)
|
||||
.nodeify(done)
|
||||
|
||||
stepHandler = (step) ->
|
||||
|
||||
step.on('stdout', _.bind(process.stdout.write, process.stdout))
|
||||
step.on('stderr', _.bind(process.stderr.write, process.stderr))
|
||||
|
||||
step.on 'state', (state) ->
|
||||
return if state.operation.command is 'burn'
|
||||
console.log(helpers.stateToString(state))
|
||||
|
||||
bar = new visuals.Progress('Writing Device OS')
|
||||
|
||||
step.on('burn', _.bind(bar.update, bar))
|
||||
|
||||
return new Promise (resolve, reject) ->
|
||||
step.on('error', reject)
|
||||
step.on('end', resolve)
|
||||
|
||||
exports.init =
|
||||
signature: 'device init'
|
||||
description: 'initialise a device with resin os'
|
||||
@ -223,25 +203,8 @@ exports.init =
|
||||
capitano.runAsync("device register #{application.app_name}")
|
||||
.then(resin.models.device.get)
|
||||
.tap (device) ->
|
||||
console.log('Configuring operating system')
|
||||
capitano.runAsync("os configure #{temporalPath} #{uuid}").then ->
|
||||
console.log('Initializing device')
|
||||
resin.models.device.getManifestBySlug(application.device_type).then (manifest) ->
|
||||
return form.run(manifest.initialization?.options)
|
||||
.tap (answers) ->
|
||||
if answers.drive?
|
||||
message = "This will erase #{answers.drive}. Are you sure?"
|
||||
patterns.confirm(options.yes, message)
|
||||
.return(answers.drive)
|
||||
.then(umount.umountAsync)
|
||||
.then (answers) ->
|
||||
init.initialize(temporalPath, device.uuid, answers)
|
||||
.then(stepHandler)
|
||||
.return(answers)
|
||||
.tap (answers) ->
|
||||
return if not answers.drive?
|
||||
umount.umountAsync(answers.drive).tap ->
|
||||
console.log("You can safely remove #{answers.drive} now")
|
||||
capitano.runAsync("os configure #{temporalPath} #{device.uuid}").then ->
|
||||
capitano.runAsync("os initialize #{temporalPath} #{device.uuid}")
|
||||
.then (device) ->
|
||||
console.log('Done')
|
||||
return device.uuid
|
||||
|
@ -1,11 +1,14 @@
|
||||
fs = require('fs')
|
||||
_ = require('lodash')
|
||||
Promise = require('bluebird')
|
||||
umount = Promise.promisifyAll(require('umount'))
|
||||
resin = require('resin-sdk')
|
||||
manager = require('resin-image-manager')
|
||||
visuals = require('resin-cli-visuals')
|
||||
form = require('resin-cli-form')
|
||||
init = require('resin-device-init')
|
||||
helpers = require('../utils/helpers')
|
||||
patterns = require('../utils/patterns')
|
||||
|
||||
exports.download =
|
||||
signature: 'os download <type>'
|
||||
@ -83,3 +86,35 @@ exports.configure =
|
||||
.then (answers) ->
|
||||
init.configure(params.image, params.uuid, answers).then(stepHandler)
|
||||
.nodeify(done)
|
||||
|
||||
exports.initialize =
|
||||
signature: 'os initialize <image> <uuid>'
|
||||
description: 'initialize an os image'
|
||||
help: '''
|
||||
Use this command to initialize a previously configured operating system image.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os initialize ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
|
||||
'''
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
console.info('Initializing device')
|
||||
resin.models.device.get(params.uuid)
|
||||
.then(resin.models.device.getManifestBySlug)
|
||||
.then (manifest) ->
|
||||
return manifest.initialization?.options
|
||||
.then(form.run)
|
||||
.tap (answers) ->
|
||||
return if not answers.drive?
|
||||
message = "This will erase #{answers.drive}. Are you sure?"
|
||||
patterns.confirm(options.yes, message)
|
||||
.return(answers.drive)
|
||||
.then(umount.umountAsync)
|
||||
.tap (answers) ->
|
||||
return init.initialize(params.image, params.uuid, answers).then(stepHandler)
|
||||
.then (answers) ->
|
||||
return if not answers.drive?
|
||||
umount.umountAsync(answers.drive).tap ->
|
||||
console.info("You can safely remove #{answers.drive} now")
|
||||
.nodeify(done)
|
||||
|
@ -68,6 +68,7 @@ capitano.command(actions.env.remove)
|
||||
# ---------- OS Module ----------
|
||||
capitano.command(actions.os.download)
|
||||
capitano.command(actions.os.configure)
|
||||
capitano.command(actions.os.initialize)
|
||||
|
||||
# ---------- Logs Module ----------
|
||||
capitano.command(actions.logs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user