2015-11-10 16:53:34 +00:00
|
|
|
(function() {
|
2015-11-11 14:38:45 +00:00
|
|
|
var Promise, _, capitano, config, prettyjson, umount, visuals;
|
2015-11-10 18:27:01 +00:00
|
|
|
|
|
|
|
_ = require('lodash');
|
2015-11-10 16:53:34 +00:00
|
|
|
|
|
|
|
Promise = require('bluebird');
|
|
|
|
|
2015-11-11 14:38:45 +00:00
|
|
|
capitano = Promise.promisifyAll(require('capitano'));
|
|
|
|
|
2015-11-10 16:53:34 +00:00
|
|
|
umount = Promise.promisifyAll(require('umount'));
|
|
|
|
|
|
|
|
visuals = require('resin-cli-visuals');
|
|
|
|
|
2015-11-11 14:04:46 +00:00
|
|
|
config = require('resin-config-json');
|
2015-11-10 18:27:01 +00:00
|
|
|
|
2015-11-11 14:04:46 +00:00
|
|
|
prettyjson = require('prettyjson');
|
2015-11-10 18:27:01 +00:00
|
|
|
|
2015-11-10 16:53:34 +00:00
|
|
|
exports.read = {
|
|
|
|
signature: 'config read',
|
|
|
|
description: 'read a device configuration',
|
2015-11-10 18:27:01 +00:00
|
|
|
help: 'Use this command to read the config.json file from a provisioned device\n\nExamples:\n\n $ resin config read --type raspberry-pi\n $ resin config read --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) {
|
|
|
|
return Promise["try"](function() {
|
|
|
|
return options.drive || visuals.drive('Select the device drive');
|
|
|
|
}).tap(umount.umountAsync).then(function(drive) {
|
2015-11-11 14:04:46 +00:00
|
|
|
return config.read(drive, options.type);
|
|
|
|
}).tap(function(configJSON) {
|
|
|
|
return console.info(prettyjson.render(configJSON));
|
2015-11-10 18:27:01 +00:00
|
|
|
}).nodeify(done);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.write = {
|
|
|
|
signature: 'config write <key> <value>',
|
|
|
|
description: 'write a device configuration',
|
|
|
|
help: 'Use this command to write the config.json file of a provisioned device\n\nExamples:\n\n $ resin config write --type raspberry-pi username johndoe\n $ resin config write --type raspberry-pi --drive /dev/disk2 username johndoe\n $ resin config write --type raspberry-pi files.network/settings "..."',
|
2015-11-10 16:53:34 +00:00
|
|
|
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) {
|
|
|
|
return Promise["try"](function() {
|
|
|
|
return options.drive || visuals.drive('Select the device drive');
|
|
|
|
}).tap(umount.umountAsync).then(function(drive) {
|
2015-11-11 14:04:46 +00:00
|
|
|
return config.read(drive, options.type).then(function(configJSON) {
|
2015-11-10 18:27:01 +00:00
|
|
|
console.info("Setting " + params.key + " to " + params.value);
|
2015-11-11 14:04:46 +00:00
|
|
|
_.set(configJSON, params.key, params.value);
|
|
|
|
return configJSON;
|
2015-11-10 18:27:01 +00:00
|
|
|
}).tap(function() {
|
|
|
|
return umount.umountAsync(drive);
|
2015-11-11 14:04:46 +00:00
|
|
|
}).then(function(configJSON) {
|
|
|
|
return config.write(drive, options.type, configJSON);
|
2015-11-10 16:53:34 +00:00
|
|
|
});
|
2015-11-10 18:27:01 +00:00
|
|
|
}).tap(function() {
|
|
|
|
return console.info('Done');
|
2015-11-10 16:53:34 +00:00
|
|
|
}).nodeify(done);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-11 14:38:45 +00:00
|
|
|
exports.reconfigure = {
|
|
|
|
signature: 'config reconfigure',
|
|
|
|
description: 'reconfigure a provisioned device',
|
|
|
|
help: 'Use this command to reconfigure a provisioned device\n\nExamples:\n\n $ resin config reconfigure --type raspberry-pi\n $ resin config reconfigure --type raspberry-pi --advanced\n $ resin config reconfigure --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'
|
|
|
|
}, {
|
|
|
|
signature: 'advanced',
|
|
|
|
description: 'show advanced commands',
|
|
|
|
boolean: true,
|
|
|
|
alias: 'v'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
permission: 'user',
|
|
|
|
root: true,
|
|
|
|
action: function(params, options, done) {
|
|
|
|
return Promise["try"](function() {
|
|
|
|
return options.drive || visuals.drive('Select the device drive');
|
|
|
|
}).tap(umount.umountAsync).then(function(drive) {
|
|
|
|
return config.read(drive, options.type).get('uuid').tap(function() {
|
|
|
|
return umount.umountAsync(drive);
|
|
|
|
}).then(function(uuid) {
|
|
|
|
var configureCommand;
|
|
|
|
configureCommand = "os configure " + drive + " " + uuid;
|
|
|
|
if (options.advanced) {
|
|
|
|
configureCommand += ' --advanced';
|
|
|
|
}
|
|
|
|
return capitano.runAsync(configureCommand);
|
|
|
|
});
|
|
|
|
}).then(function() {
|
|
|
|
return console.info('Done');
|
|
|
|
}).nodeify(done);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-10 16:53:34 +00:00
|
|
|
}).call(this);
|