2016-01-04 03:58:51 +00:00
|
|
|
###
|
|
|
|
Copyright 2016 Resin.io
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
###
|
|
|
|
|
2015-11-10 16:53:34 +00:00
|
|
|
exports.read =
|
|
|
|
signature: 'config read'
|
|
|
|
description: 'read a device configuration'
|
|
|
|
help: '''
|
|
|
|
Use this command to read the config.json file from a provisioned device
|
|
|
|
|
2015-11-10 18:27:01 +00:00
|
|
|
Examples:
|
2015-11-10 16:53:34 +00:00
|
|
|
|
|
|
|
$ resin config read --type raspberry-pi
|
|
|
|
$ 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: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
config = require('resin-config-json')
|
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
umount = Promise.promisifyAll(require('umount'))
|
|
|
|
prettyjson = require('prettyjson')
|
|
|
|
|
2015-11-10 16:53:34 +00:00
|
|
|
Promise.try ->
|
|
|
|
return options.drive or visuals.drive('Select the device drive')
|
|
|
|
.tap(umount.umountAsync)
|
|
|
|
.then (drive) ->
|
2015-11-11 14:04:46 +00:00
|
|
|
return config.read(drive, options.type)
|
|
|
|
.tap (configJSON) ->
|
|
|
|
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
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ resin config write --type raspberry-pi username johndoe
|
|
|
|
$ resin config write --type raspberry-pi --drive /dev/disk2 username johndoe
|
|
|
|
$ resin config write --type raspberry-pi files.network/settings "..."
|
|
|
|
'''
|
|
|
|
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) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
_ = require('lodash')
|
|
|
|
config = require('resin-config-json')
|
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
umount = Promise.promisifyAll(require('umount'))
|
|
|
|
|
2015-11-10 18:27:01 +00:00
|
|
|
Promise.try ->
|
|
|
|
return options.drive or visuals.drive('Select the device drive')
|
|
|
|
.tap(umount.umountAsync)
|
|
|
|
.then (drive) ->
|
2015-11-11 14:04:46 +00:00
|
|
|
config.read(drive, options.type).then (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 ->
|
|
|
|
return umount.umountAsync(drive)
|
2015-11-11 14:04:46 +00:00
|
|
|
.then (configJSON) ->
|
|
|
|
return config.write(drive, options.type, configJSON)
|
2015-11-10 18:27:01 +00:00
|
|
|
.tap ->
|
|
|
|
console.info('Done')
|
2015-11-10 16:53:34 +00:00
|
|
|
.nodeify(done)
|
2015-11-11 14:38:45 +00:00
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
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)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ resin config reconfigure --type raspberry-pi
|
|
|
|
$ resin config reconfigure --type raspberry-pi --advanced
|
|
|
|
$ 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: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
config = require('resin-config-json')
|
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
capitano = Promise.promisifyAll(require('capitano'))
|
|
|
|
umount = Promise.promisifyAll(require('umount'))
|
|
|
|
|
2015-11-11 14:38:45 +00:00
|
|
|
Promise.try ->
|
|
|
|
return options.drive or visuals.drive('Select the device drive')
|
|
|
|
.tap(umount.umountAsync)
|
|
|
|
.then (drive) ->
|
|
|
|
config.read(drive, options.type).get('uuid')
|
|
|
|
.tap ->
|
|
|
|
umount.umountAsync(drive)
|
|
|
|
.then (uuid) ->
|
|
|
|
configureCommand = "os configure #{drive} #{uuid}"
|
|
|
|
if options.advanced
|
|
|
|
configureCommand += ' --advanced'
|
|
|
|
return capitano.runAsync(configureCommand)
|
|
|
|
.then ->
|
|
|
|
console.info('Done')
|
|
|
|
.nodeify(done)
|
2016-02-27 02:37:15 +00:00
|
|
|
|
|
|
|
exports.generate =
|
|
|
|
signature: 'config generate <uuid>'
|
|
|
|
description: 'generate a config.json file'
|
|
|
|
help: '''
|
|
|
|
Use this command to generate a config.json for a device
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ resin config generate 7cf02a6
|
|
|
|
$ resin config generate 7cf02a6 --output config.json
|
|
|
|
'''
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
signature: 'output'
|
|
|
|
description: 'output'
|
|
|
|
parameter: 'output'
|
|
|
|
alias: 'o'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
|
|
|
Promise = require('bluebird')
|
|
|
|
fs = Promise.promisifyAll(require('fs'))
|
|
|
|
resin = require('resin-sdk')
|
|
|
|
_ = require('lodash')
|
|
|
|
form = require('resin-cli-form')
|
|
|
|
deviceConfig = require('resin-device-config')
|
|
|
|
prettyjson = require('prettyjson')
|
|
|
|
|
|
|
|
resin.models.device.get(params.uuid).then (device) ->
|
|
|
|
resin.models.device.getManifestBySlug(device.device_type)
|
|
|
|
.get('options')
|
|
|
|
.then(form.run)
|
2016-03-21 19:01:59 +00:00
|
|
|
.then(_.partial(deviceConfig.getByDevice, device.uuid))
|
2016-02-27 02:37:15 +00:00
|
|
|
.then (config) ->
|
|
|
|
if options.output?
|
|
|
|
return fs.writeFileAsync(options.output, JSON.stringify(config))
|
|
|
|
|
|
|
|
console.log(prettyjson.render(config))
|
|
|
|
.nodeify(done)
|