mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-21 06:33:28 +00:00
Associate a device before first boot
This commit is contained in:
parent
fdd0e4a966
commit
2bfeb7f42c
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var _, async, capitano, commandOptions, fse, image, inject, manager, path, resin, tmp, vcs, visuals;
|
||||
var _, async, capitano, commandOptions, fse, image, inject, manager, path, pine, registerDevice, resin, tmp, vcs, visuals;
|
||||
|
||||
fse = require('fs-extra');
|
||||
|
||||
@ -23,6 +23,10 @@
|
||||
|
||||
inject = require('resin-config-inject');
|
||||
|
||||
registerDevice = require('resin-register-device');
|
||||
|
||||
pine = require('resin-pine');
|
||||
|
||||
tmp = require('tmp');
|
||||
|
||||
tmp.setGracefulCleanup();
|
||||
@ -211,29 +215,44 @@
|
||||
console.info("Checking application: " + options.application);
|
||||
return resin.models.application.get(options.application, callback);
|
||||
}, function(application, callback) {
|
||||
console.info('Getting device manifest for the application');
|
||||
return resin.models.device.getManifestBySlug(application.device_type, callback);
|
||||
}, function(manifest, callback) {
|
||||
var bar, spinner;
|
||||
params.manifest = manifest;
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS');
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
|
||||
console.info('Fetching application configuration');
|
||||
return resin.models.application.getConfiguration(options.application, networkOptions, function(error, config) {
|
||||
return async.parallel({
|
||||
manifest: function(callback) {
|
||||
console.info('Getting device manifest for the application');
|
||||
return resin.models.device.getManifestBySlug(application.device_type, callback);
|
||||
},
|
||||
config: function(callback) {
|
||||
console.info('Fetching application configuration');
|
||||
return resin.models.application.getConfiguration(options.application, networkOptions, callback);
|
||||
}
|
||||
}, callback);
|
||||
}, function(results, callback) {
|
||||
console.info('Associating the device');
|
||||
return registerDevice.register(pine, results.config, function(error, device) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
console.info('Configuring device operating system image');
|
||||
return manager.configure(params.manifest, config, function(error, imagePath, removeCallback) {
|
||||
spinner.stop();
|
||||
return callback(error, imagePath, removeCallback);
|
||||
}, function(state) {
|
||||
if (state != null) {
|
||||
return bar.update(state);
|
||||
} else {
|
||||
return spinner.start();
|
||||
}
|
||||
});
|
||||
results.config.deviceId = device.id;
|
||||
results.config.uuid = device.uuid;
|
||||
params.uuid = results.config.uuid;
|
||||
return callback(null, results);
|
||||
});
|
||||
}, function(results, callback) {
|
||||
var bar, spinner;
|
||||
console.info('Configuring device operating system image');
|
||||
if (process.env.DEBUG) {
|
||||
console.log(results.config);
|
||||
}
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS');
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
|
||||
return manager.configure(results.manifest, results.config, function(error, imagePath, removeCallback) {
|
||||
spinner.stop();
|
||||
return callback(error, imagePath, removeCallback);
|
||||
}, function(state) {
|
||||
if (state != null) {
|
||||
return bar.update(state);
|
||||
} else {
|
||||
return spinner.start();
|
||||
}
|
||||
});
|
||||
}, function(configuredImagePath, removeCallback, callback) {
|
||||
var bar;
|
||||
@ -252,6 +271,11 @@
|
||||
}, function(temporalImagePath, removeCallback, callback) {
|
||||
console.info('Image written successfully');
|
||||
return removeCallback(callback);
|
||||
}, function(callback) {
|
||||
return resin.models.device.getByUUID(params.uuid, callback);
|
||||
}, function(device, callback) {
|
||||
console.info("Device created: " + device.name);
|
||||
return callback(null, device.name);
|
||||
}
|
||||
], done);
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ vcs = require('resin-vcs')
|
||||
manager = require('resin-image-manager')
|
||||
image = require('resin-image')
|
||||
inject = require('resin-config-inject')
|
||||
registerDevice = require('resin-register-device')
|
||||
pine = require('resin-pine')
|
||||
tmp = require('tmp')
|
||||
|
||||
# Cleanup the temporary files even when an uncaught exception occurs
|
||||
@ -284,29 +286,49 @@ exports.init =
|
||||
resin.models.application.get(options.application, callback)
|
||||
|
||||
(application, callback) ->
|
||||
console.info('Getting device manifest for the application')
|
||||
resin.models.device.getManifestBySlug(application.device_type, callback)
|
||||
async.parallel
|
||||
|
||||
manifest: (callback) ->
|
||||
console.info('Getting device manifest for the application')
|
||||
resin.models.device.getManifestBySlug(application.device_type, callback)
|
||||
|
||||
config: (callback) ->
|
||||
console.info('Fetching application configuration')
|
||||
resin.models.application.getConfiguration(options.application, networkOptions, callback)
|
||||
|
||||
, callback
|
||||
|
||||
(results, callback) ->
|
||||
console.info('Associating the device')
|
||||
|
||||
registerDevice.register pine, results.config, (error, device) ->
|
||||
return callback(error) if error?
|
||||
|
||||
# Associate a device
|
||||
results.config.deviceId = device.id
|
||||
results.config.uuid = device.uuid
|
||||
|
||||
params.uuid = results.config.uuid
|
||||
|
||||
return callback(null, results)
|
||||
|
||||
(results, callback) ->
|
||||
console.info('Configuring device operating system image')
|
||||
|
||||
if process.env.DEBUG
|
||||
console.log(results.config)
|
||||
|
||||
(manifest, callback) ->
|
||||
params.manifest = manifest
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS')
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
|
||||
|
||||
console.info('Fetching application configuration')
|
||||
|
||||
resin.models.application.getConfiguration options.application, networkOptions, (error, config) ->
|
||||
return callback(error) if error?
|
||||
|
||||
console.info('Configuring device operating system image')
|
||||
|
||||
manager.configure params.manifest, config, (error, imagePath, removeCallback) ->
|
||||
spinner.stop()
|
||||
return callback(error, imagePath, removeCallback)
|
||||
, (state) ->
|
||||
if state?
|
||||
bar.update(state)
|
||||
else
|
||||
spinner.start()
|
||||
manager.configure results.manifest, results.config, (error, imagePath, removeCallback) ->
|
||||
spinner.stop()
|
||||
return callback(error, imagePath, removeCallback)
|
||||
, (state) ->
|
||||
if state?
|
||||
bar.update(state)
|
||||
else
|
||||
spinner.start()
|
||||
|
||||
(configuredImagePath, removeCallback, callback) ->
|
||||
console.info('Attempting to write operating system image to drive')
|
||||
@ -324,4 +346,11 @@ exports.init =
|
||||
console.info('Image written successfully')
|
||||
removeCallback(callback)
|
||||
|
||||
(callback) ->
|
||||
resin.models.device.getByUUID(params.uuid, callback)
|
||||
|
||||
(device, callback) ->
|
||||
console.info("Device created: #{device.name}")
|
||||
return callback(null, device.name)
|
||||
|
||||
], done)
|
||||
|
@ -59,12 +59,14 @@
|
||||
"nplugm": "^2.2.0",
|
||||
"npm": "^2.6.1",
|
||||
"open": "0.0.5",
|
||||
"resin-image": "^1.1.3",
|
||||
"resin-settings-client": "^1.1.0",
|
||||
"resin-cli-visuals": "^0.1.1",
|
||||
"resin-config-inject": "^2.0.0",
|
||||
"resin-image": "^1.1.3",
|
||||
"resin-image-manager": "^1.1.0",
|
||||
"resin-pine": "^1.1.1",
|
||||
"resin-register-device": "^1.0.1",
|
||||
"resin-sdk": "^1.7.4",
|
||||
"resin-settings-client": "^1.1.0",
|
||||
"resin-vcs": "^1.2.0",
|
||||
"selfupdate": "^1.1.0",
|
||||
"tmp": "^0.0.25",
|
||||
|
Loading…
Reference in New Issue
Block a user