mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-08 20:04:14 +00:00
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:
parent
4fc8b130f8
commit
03d7520de2
@ -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',
|
||||
|
@ -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);
|
||||
|
@ -81,6 +81,7 @@ Now you have access to all the commands referenced below.
|
||||
|
||||
- [config read](#config-read)
|
||||
- [config write <key> <value>](#config-write-60-key-62-60-value-62-)
|
||||
- [config inject <file>](#config-inject-60-file-62-)
|
||||
- [config reconfigure](#config-reconfigure)
|
||||
- [config generate <uuid>](#config-generate-60-uuid-62-)
|
||||
|
||||
@ -685,6 +686,25 @@ device type
|
||||
|
||||
drive
|
||||
|
||||
## config inject <file>
|
||||
|
||||
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 <type>
|
||||
|
||||
device type
|
||||
|
||||
#### --drive, -d <drive>
|
||||
|
||||
drive
|
||||
|
||||
## config reconfigure
|
||||
|
||||
Use this command to reconfigure a provisioned device
|
||||
|
@ -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'
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user