Implement config inject command

This command allows to user to inject a whole `config.json` file to a
provisioned device.
This commit is contained in:
Juan Cruz Viotti 2016-03-17 16:07:19 -04:00
parent 4fc8b130f8
commit 03d7520de2
5 changed files with 107 additions and 0 deletions

View File

@ -98,6 +98,45 @@ limitations under the License.
}
};
exports.inject = {
signature: 'config inject <file>',
description: 'inject a device configuration file',
help: 'Use this command to inject a config.json file to a provisioned device\n\nExamples:\n\n $ resin config inject my/config.json --type raspberry-pi\n $ resin config inject my/config.json --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, fs, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
fs = Promise.promisifyAll(require('fs'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return fs.readFileAsync(params.file, 'utf8').then(JSON.parse).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
}).tap(function() {
return console.info('Done');
}).nodeify(done);
}
};
exports.reconfigure = {
signature: 'config reconfigure',
description: 'reconfigure a provisioned device',

View File

@ -123,6 +123,8 @@ limitations under the License.
capitano.command(actions.config.write);
capitano.command(actions.config.inject);
capitano.command(actions.config.reconfigure);
capitano.command(actions.config.generate);

View File

@ -81,6 +81,7 @@ Now you have access to all the commands referenced below.
- [config read](#config-read)
- [config write &#60;key&#62; &#60;value&#62;](#config-write-60-key-62-60-value-62-)
- [config inject &#60;file&#62;](#config-inject-60-file-62-)
- [config reconfigure](#config-reconfigure)
- [config generate &#60;uuid&#62;](#config-generate-60-uuid-62-)
@ -685,6 +686,25 @@ device type
drive
## config inject &#60;file&#62;
Use this command to inject a config.json file to a provisioned device
Examples:
$ resin config inject my/config.json --type raspberry-pi
$ resin config inject my/config.json --type raspberry-pi --drive /dev/disk2
### Options
#### --type, -t &#60;type&#62;
device type
#### --drive, -d &#60;drive&#62;
drive
## config reconfigure
Use this command to reconfigure a provisioned device

View File

@ -110,6 +110,51 @@ exports.write =
console.info('Done')
.nodeify(done)
exports.inject =
signature: 'config inject <file>'
description: 'inject a device configuration file'
help: '''
Use this command to inject a config.json file to a provisioned device
Examples:
$ resin config inject my/config.json --type raspberry-pi
$ resin config inject my/config.json --type raspberry-pi --drive /dev/disk2
'''
options: [
{
signature: 'type'
description: 'device type'
parameter: 'type'
alias: 't'
required: 'You have to specify a device type'
}
{
signature: 'drive'
description: 'drive'
parameter: 'drive'
alias: 'd'
}
]
permission: 'user'
root: true
action: (params, options, done) ->
Promise = require('bluebird')
config = require('resin-config-json')
visuals = require('resin-cli-visuals')
umount = Promise.promisifyAll(require('umount'))
fs = Promise.promisifyAll(require('fs'))
Promise.try ->
return options.drive or visuals.drive('Select the device drive')
.tap(umount.umountAsync)
.then (drive) ->
fs.readFileAsync(params.file, 'utf8').then(JSON.parse).then (configJSON) ->
return config.write(drive, options.type, configJSON)
.tap ->
console.info('Done')
.nodeify(done)
exports.reconfigure =
signature: 'config reconfigure'
description: 'reconfigure a provisioned device'

View File

@ -97,6 +97,7 @@ capitano.command(actions.os.initialize)
# ---------- Config Module ----------
capitano.command(actions.config.read)
capitano.command(actions.config.write)
capitano.command(actions.config.inject)
capitano.command(actions.config.reconfigure)
capitano.command(actions.config.generate)