2016-01-04 03:58:51 +00:00
|
|
|
###
|
2018-10-19 14:38:50 +00:00
|
|
|
Copyright 2016-2017 Balena
|
2016-01-04 03:58:51 +00:00
|
|
|
|
|
|
|
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-01-15 17:10:14 +00:00
|
|
|
commandOptions = require('./command-options')
|
2017-06-08 19:58:37 +00:00
|
|
|
_ = require('lodash')
|
2018-02-01 15:48:01 +00:00
|
|
|
{ normalizeUuidProp } = require('../utils/normalization')
|
2014-11-19 17:38:15 +00:00
|
|
|
|
2018-05-18 18:00:30 +00:00
|
|
|
expandForAppName = {
|
|
|
|
$expand: belongs_to__application: $select: 'app_name'
|
|
|
|
}
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.list =
|
|
|
|
signature: 'devices'
|
|
|
|
description: 'list all devices'
|
|
|
|
help: '''
|
2015-04-27 15:20:53 +00:00
|
|
|
Use this command to list all devices that belong to you.
|
|
|
|
|
|
|
|
You can filter the devices by application by using the `--application` option.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena devices
|
|
|
|
$ balena devices --application MyApp
|
|
|
|
$ balena devices --app MyApp
|
|
|
|
$ balena devices -a MyApp
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-04-27 15:20:53 +00:00
|
|
|
options: [ commandOptions.optionalApplication ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2015-08-17 13:49:59 +00:00
|
|
|
Promise.try ->
|
|
|
|
if options.application?
|
2018-10-19 14:38:50 +00:00
|
|
|
return balena.models.device.getAllByApplication(options.application, expandForAppName)
|
|
|
|
return balena.models.device.getAll(expandForAppName)
|
2015-04-27 15:20:53 +00:00
|
|
|
|
2015-08-17 13:49:59 +00:00
|
|
|
.tap (devices) ->
|
2016-01-21 14:26:13 +00:00
|
|
|
devices = _.map devices, (device) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
device.dashboard_url = balena.models.device.getDashboardUrl(device.uuid)
|
2019-12-11 12:18:58 +00:00
|
|
|
device.application_name =
|
|
|
|
if device.belongs_to__application?[0] then device.belongs_to__application[0].app_name else 'N/a'
|
2016-01-21 14:26:13 +00:00
|
|
|
device.uuid = device.uuid.slice(0, 7)
|
|
|
|
return device
|
|
|
|
|
2015-07-29 13:34:31 +00:00
|
|
|
console.log visuals.table.horizontal devices, [
|
2015-12-02 13:06:41 +00:00
|
|
|
'id'
|
2015-11-13 18:06:55 +00:00
|
|
|
'uuid'
|
2018-05-18 18:00:30 +00:00
|
|
|
'device_name'
|
2015-01-22 17:20:20 +00:00
|
|
|
'device_type'
|
2015-01-22 17:06:02 +00:00
|
|
|
'application_name'
|
|
|
|
'status'
|
2016-02-10 12:51:00 +00:00
|
|
|
'is_online'
|
2016-08-10 13:12:34 +00:00
|
|
|
'supervisor_version'
|
|
|
|
'os_version'
|
2017-04-19 23:27:10 +00:00
|
|
|
'dashboard_url'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
2015-08-17 13:49:59 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.info =
|
2015-07-22 22:06:53 +00:00
|
|
|
signature: 'device <uuid>'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'list a single device'
|
|
|
|
help: '''
|
|
|
|
Use this command to show information about a single device.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device 7cf02a6
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.device.get(params.uuid, expandForAppName)
|
2018-05-18 18:00:30 +00:00
|
|
|
.then (device) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.device.getStatus(device).then (status) ->
|
2016-01-26 16:16:55 +00:00
|
|
|
device.status = status
|
2018-10-19 14:38:50 +00:00
|
|
|
device.dashboard_url = balena.models.device.getDashboardUrl(device.uuid)
|
2019-12-11 12:18:58 +00:00
|
|
|
device.application_name =
|
|
|
|
if device.belongs_to__application?[0] then device.belongs_to__application[0].app_name else 'N/a'
|
2018-05-24 13:43:45 +00:00
|
|
|
device.commit = device.is_on__commit
|
2016-01-26 16:16:55 +00:00
|
|
|
|
|
|
|
console.log visuals.table.vertical device, [
|
2018-05-18 18:00:30 +00:00
|
|
|
"$#{device.device_name}$"
|
2016-01-26 16:16:55 +00:00
|
|
|
'id'
|
|
|
|
'device_type'
|
|
|
|
'status'
|
|
|
|
'is_online'
|
|
|
|
'ip_address'
|
|
|
|
'application_name'
|
|
|
|
'last_seen'
|
|
|
|
'uuid'
|
|
|
|
'commit'
|
|
|
|
'supervisor_version'
|
|
|
|
'is_web_accessible'
|
|
|
|
'note'
|
2016-08-10 13:12:34 +00:00
|
|
|
'os_version'
|
2017-04-19 23:27:10 +00:00
|
|
|
'dashboard_url'
|
2016-01-26 16:16:55 +00:00
|
|
|
]
|
2015-07-22 22:06:53 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-09-29 18:33:31 +00:00
|
|
|
exports.register =
|
|
|
|
signature: 'device register <application>'
|
|
|
|
description: 'register a device'
|
|
|
|
help: '''
|
|
|
|
Use this command to register a device to an application.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device register MyApp
|
|
|
|
$ balena device register MyApp --uuid <uuid>
|
2015-09-29 18:33:31 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
2015-10-19 18:16:47 +00:00
|
|
|
options: [
|
2017-04-19 03:19:04 +00:00
|
|
|
{
|
|
|
|
signature: 'uuid'
|
|
|
|
description: 'custom uuid'
|
|
|
|
parameter: 'uuid'
|
|
|
|
alias: 'u'
|
|
|
|
}
|
2015-10-19 18:16:47 +00:00
|
|
|
]
|
2015-09-29 18:33:31 +00:00
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
|
2017-04-19 03:19:04 +00:00
|
|
|
Promise.join(
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.application.get(params.application)
|
|
|
|
options.uuid ? balena.models.device.generateUniqueKey()
|
2018-06-28 22:42:29 +00:00
|
|
|
(application, uuid) ->
|
2018-09-13 22:36:46 +00:00
|
|
|
console.info("Registering to #{application.app_name}: #{uuid}")
|
2018-10-19 14:38:50 +00:00
|
|
|
return balena.models.device.register(application.id, uuid)
|
2017-04-19 03:19:04 +00:00
|
|
|
)
|
2015-09-29 18:33:31 +00:00
|
|
|
.get('uuid')
|
|
|
|
.nodeify(done)
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.remove =
|
2015-07-22 22:06:53 +00:00
|
|
|
signature: 'device rm <uuid>'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'remove a device'
|
|
|
|
help: '''
|
2018-10-19 14:38:50 +00:00
|
|
|
Use this command to remove a device from balena.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
Notice this command asks for confirmation interactively.
|
|
|
|
You can avoid this by passing the `--yes` boolean option.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device rm 7cf02a6
|
|
|
|
$ balena device rm 7cf02a6 --yes
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
|
|
|
options: [ commandOptions.yes ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
patterns = require('../utils/patterns')
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.device.remove(params.uuid)
|
2015-08-17 13:49:59 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.identify =
|
|
|
|
signature: 'device identify <uuid>'
|
|
|
|
description: 'identify a device with a UUID'
|
|
|
|
help: '''
|
|
|
|
Use this command to identify a device.
|
|
|
|
|
|
|
|
In the Raspberry Pi, the ACT led is blinked several times.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device identify 23c73a1
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.identify(params.uuid).nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2016-03-04 13:38:11 +00:00
|
|
|
exports.reboot =
|
|
|
|
signature: 'device reboot <uuid>'
|
|
|
|
description: 'restart a device'
|
|
|
|
help: '''
|
|
|
|
Use this command to remotely reboot a device
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device reboot 23c73a1
|
2016-03-04 13:38:11 +00:00
|
|
|
'''
|
2016-10-26 14:46:20 +00:00
|
|
|
options: [ commandOptions.forceUpdateLock ]
|
2016-03-04 13:38:11 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.reboot(params.uuid, options).nodeify(done)
|
2016-10-26 14:46:20 +00:00
|
|
|
|
|
|
|
exports.shutdown =
|
|
|
|
signature: 'device shutdown <uuid>'
|
|
|
|
description: 'shutdown a device'
|
|
|
|
help: '''
|
|
|
|
Use this command to remotely shutdown a device
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device shutdown 23c73a1
|
2016-10-26 14:46:20 +00:00
|
|
|
'''
|
|
|
|
options: [ commandOptions.forceUpdateLock ]
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.shutdown(params.uuid, options).nodeify(done)
|
2016-03-04 13:38:11 +00:00
|
|
|
|
2016-08-09 13:14:50 +00:00
|
|
|
exports.enableDeviceUrl =
|
2016-08-09 17:14:40 +00:00
|
|
|
signature: 'device public-url enable <uuid>'
|
|
|
|
description: 'enable public URL for a device'
|
2016-08-09 13:14:50 +00:00
|
|
|
help: '''
|
2016-08-09 17:14:40 +00:00
|
|
|
Use this command to enable public URL for a device
|
2016-08-09 13:14:50 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device public-url enable 23c73a1
|
2016-08-09 13:14:50 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.enableDeviceUrl(params.uuid).nodeify(done)
|
2016-08-09 13:14:50 +00:00
|
|
|
|
|
|
|
exports.disableDeviceUrl =
|
2016-08-09 17:14:40 +00:00
|
|
|
signature: 'device public-url disable <uuid>'
|
|
|
|
description: 'disable public URL for a device'
|
2016-08-09 13:14:50 +00:00
|
|
|
help: '''
|
2016-08-09 17:14:40 +00:00
|
|
|
Use this command to disable public URL for a device
|
2016-08-09 13:14:50 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device public-url disable 23c73a1
|
2016-08-09 13:14:50 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.disableDeviceUrl(params.uuid).nodeify(done)
|
2016-08-09 13:14:50 +00:00
|
|
|
|
|
|
|
exports.getDeviceUrl =
|
2016-08-09 17:14:40 +00:00
|
|
|
signature: 'device public-url <uuid>'
|
|
|
|
description: 'gets the public URL of a device'
|
2016-08-09 13:14:50 +00:00
|
|
|
help: '''
|
2016-08-09 17:14:40 +00:00
|
|
|
Use this command to get the public URL of a device
|
2016-08-09 13:14:50 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device public-url 23c73a1
|
2016-08-09 13:14:50 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.getDeviceUrl(params.uuid).then (url) ->
|
2016-08-09 13:14:50 +00:00
|
|
|
console.log(url)
|
|
|
|
.nodeify(done)
|
|
|
|
|
|
|
|
exports.hasDeviceUrl =
|
2016-08-09 17:14:40 +00:00
|
|
|
signature: 'device public-url status <uuid>'
|
|
|
|
description: 'Returns true if public URL is enabled for a device'
|
2016-08-09 13:14:50 +00:00
|
|
|
help: '''
|
2016-08-09 17:14:40 +00:00
|
|
|
Use this command to determine if public URL is enabled for a device
|
2016-08-09 13:14:50 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device public-url status 23c73a1
|
2016-08-09 13:14:50 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.models.device.hasDeviceUrl(params.uuid).then (hasDeviceUrl) ->
|
2016-08-09 13:14:50 +00:00
|
|
|
console.log(hasDeviceUrl)
|
|
|
|
.nodeify(done)
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.rename =
|
2015-07-22 22:06:53 +00:00
|
|
|
signature: 'device rename <uuid> [newName]'
|
2018-10-19 14:38:50 +00:00
|
|
|
description: 'rename a balena device'
|
2015-01-15 17:10:14 +00:00
|
|
|
help: '''
|
|
|
|
Use this command to rename a device.
|
|
|
|
|
|
|
|
If you omit the name, you'll get asked for it interactively.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device rename 7cf02a6
|
|
|
|
$ balena device rename 7cf02a6 MyPi
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
form = require('resin-cli-form')
|
|
|
|
|
2015-08-17 13:49:59 +00:00
|
|
|
Promise.try ->
|
|
|
|
return params.newName if not _.isEmpty(params.newName)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-17 13:49:59 +00:00
|
|
|
form.ask
|
|
|
|
message: 'How do you want to name this device?'
|
|
|
|
type: 'input'
|
2015-06-11 16:46:56 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
.then(_.partial(balena.models.device.rename, params.uuid))
|
2015-08-17 13:49:59 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-11-11 19:00:02 +00:00
|
|
|
exports.move =
|
|
|
|
signature: 'device move <uuid>'
|
|
|
|
description: 'move a device to another application'
|
|
|
|
help: '''
|
|
|
|
Use this command to move a device to another application you own.
|
|
|
|
|
|
|
|
If you omit the application, you'll get asked for it interactively.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device move 7cf02a6
|
|
|
|
$ balena device move 7cf02a6 --application MyNewApp
|
2015-11-11 19:00:02 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
|
|
|
options: [ commandOptions.optionalApplication ]
|
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
patterns = require('../utils/patterns')
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.device.get(params.uuid, expandForAppName).then (device) ->
|
2019-12-11 12:18:58 +00:00
|
|
|
device.application_name =
|
|
|
|
if device.belongs_to__application?[0] then device.belongs_to__application[0].app_name else 'N/a'
|
2019-09-16 12:59:21 +00:00
|
|
|
return options.application if options.application
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
balena.models.device.getManifestBySlug(device.device_type)
|
|
|
|
balena.models.config.getDeviceTypes()
|
|
|
|
]).then ([deviceDeviceType, deviceTypes]) ->
|
|
|
|
compatibleDeviceTypes = deviceTypes.filter (dt) ->
|
|
|
|
balena.models.os.isArchitectureCompatibleWith(deviceDeviceType.arch, dt.arch) &&
|
|
|
|
!!dt.isDependent == !!deviceDeviceType.isDependent &&
|
|
|
|
dt.state != 'DISCONTINUED'
|
|
|
|
|
|
|
|
return patterns.selectApplication (application) ->
|
|
|
|
return _.every [
|
|
|
|
_.some(compatibleDeviceTypes, (dt) -> dt.slug == application.device_type)
|
2019-12-11 12:18:58 +00:00
|
|
|
device.application_name isnt application.app_name
|
2019-09-16 12:59:21 +00:00
|
|
|
]
|
2015-11-11 19:00:02 +00:00
|
|
|
.tap (application) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
return balena.models.device.move(params.uuid, application)
|
2015-11-11 19:00:02 +00:00
|
|
|
.then (application) ->
|
|
|
|
console.info("#{params.uuid} was moved to #{application}")
|
|
|
|
.nodeify(done)
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
exports.init =
|
|
|
|
signature: 'device init'
|
2018-10-19 14:38:50 +00:00
|
|
|
description: 'initialise a device with balenaOS'
|
2015-08-20 19:54:42 +00:00
|
|
|
help: '''
|
|
|
|
Use this command to download the OS image of a certain application and write it to an SD Card.
|
2015-02-05 13:56:22 +00:00
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
Notice this command may ask for confirmation interactively.
|
|
|
|
You can avoid this by passing the `--yes` boolean option.
|
2015-03-11 13:05:20 +00:00
|
|
|
|
2015-02-05 13:56:22 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena device init
|
|
|
|
$ balena device init --application MyApp
|
2015-02-04 18:13:28 +00:00
|
|
|
'''
|
|
|
|
options: [
|
2015-03-12 16:03:59 +00:00
|
|
|
commandOptions.optionalApplication
|
2015-08-20 19:54:42 +00:00
|
|
|
commandOptions.yes
|
2017-06-14 21:51:56 +00:00
|
|
|
commandOptions.advancedConfig
|
2018-10-15 17:03:21 +00:00
|
|
|
_.assign({}, commandOptions.osVersionOrSemver, { signature: 'os-version', parameter: 'os-version' })
|
2017-06-14 21:51:56 +00:00
|
|
|
commandOptions.drive
|
2017-06-12 08:42:08 +00:00
|
|
|
{
|
|
|
|
signature: 'config'
|
2018-10-19 14:38:50 +00:00
|
|
|
description: 'path to the config JSON file, see `balena os build-config`'
|
2017-06-12 08:42:08 +00:00
|
|
|
parameter: 'config'
|
|
|
|
}
|
2015-02-04 18:13:28 +00:00
|
|
|
]
|
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
rimraf = Promise.promisify(require('rimraf'))
|
2017-03-27 09:14:55 +00:00
|
|
|
tmp = require('tmp')
|
|
|
|
tmpNameAsync = Promise.promisify(tmp.tmpName)
|
2015-12-07 14:32:24 +00:00
|
|
|
tmp.setGracefulCleanup()
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
patterns = require('../utils/patterns')
|
2018-05-22 15:12:51 +00:00
|
|
|
{ runCommand } = require('../utils/helpers')
|
2015-12-07 14:32:24 +00:00
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
Promise.try ->
|
|
|
|
return options.application if options.application?
|
2015-09-29 15:10:33 +00:00
|
|
|
return patterns.selectApplication()
|
2018-10-19 14:38:50 +00:00
|
|
|
.then(balena.models.application.get)
|
2015-08-20 19:54:42 +00:00
|
|
|
.then (application) ->
|
2015-09-21 11:43:17 +00:00
|
|
|
|
|
|
|
download = ->
|
2017-03-27 09:14:55 +00:00
|
|
|
tmpNameAsync().then (tempPath) ->
|
2017-06-08 19:58:37 +00:00
|
|
|
osVersion = options['os-version'] or 'default'
|
2018-05-22 15:12:51 +00:00
|
|
|
runCommand("os download #{application.device_type} --output '#{tempPath}' --version #{osVersion}")
|
2017-03-24 09:48:14 +00:00
|
|
|
.disposer (tempPath) ->
|
|
|
|
return rimraf(tempPath)
|
2015-09-21 11:43:17 +00:00
|
|
|
|
2017-03-24 09:48:14 +00:00
|
|
|
Promise.using download(), (tempPath) ->
|
2018-05-22 15:12:51 +00:00
|
|
|
runCommand("device register #{application.app_name}")
|
2018-10-19 14:38:50 +00:00
|
|
|
.then(balena.models.device.get)
|
2015-09-29 18:33:31 +00:00
|
|
|
.tap (device) ->
|
2018-01-16 16:54:46 +00:00
|
|
|
configureCommand = "os configure '#{tempPath}' --device #{device.uuid}"
|
2017-06-12 08:42:08 +00:00
|
|
|
if options.config
|
|
|
|
configureCommand += " --config '#{options.config}'"
|
|
|
|
else if options.advanced
|
2017-03-24 09:48:14 +00:00
|
|
|
configureCommand += ' --advanced'
|
2018-05-22 15:12:51 +00:00
|
|
|
runCommand(configureCommand)
|
2017-03-24 09:48:14 +00:00
|
|
|
.then ->
|
|
|
|
osInitCommand = "os initialize '#{tempPath}' --type #{application.device_type}"
|
2017-06-08 20:55:56 +00:00
|
|
|
if options.yes
|
|
|
|
osInitCommand += ' --yes'
|
2017-06-09 09:32:28 +00:00
|
|
|
if options.drive
|
|
|
|
osInitCommand += " --drive #{options.drive}"
|
2018-05-22 15:12:51 +00:00
|
|
|
runCommand(osInitCommand)
|
2016-01-14 13:14:45 +00:00
|
|
|
# Make sure the device resource is removed if there is an
|
|
|
|
# error when configuring or initializing a device image
|
|
|
|
.catch (error) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.device.remove(device.uuid).finally ->
|
2016-01-14 13:14:45 +00:00
|
|
|
throw error
|
2015-09-30 15:37:27 +00:00
|
|
|
.then (device) ->
|
|
|
|
console.log('Done')
|
|
|
|
return device.uuid
|
2015-09-29 18:33:31 +00:00
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
.nodeify(done)
|
2019-06-11 12:08:15 +00:00
|
|
|
|
2019-11-07 10:02:44 +00:00
|
|
|
tsActions = require('./device_ts')
|
|
|
|
exports.osUpdate = tsActions.osUpdate
|