mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Implement 'resin local configure'
This commit is contained in:
parent
eea9a2f723
commit
00753a5776
128
lib/actions/local/configure.coffee
Normal file
128
lib/actions/local/configure.coffee
Normal file
@ -0,0 +1,128 @@
|
||||
###
|
||||
Copyright 2017 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.
|
||||
###
|
||||
|
||||
CONFIGURATION_SCHEMA =
|
||||
mapper: [
|
||||
{
|
||||
template:
|
||||
hostname: '{{hostname}}'
|
||||
persistentLogging: '{{persistentLogging}}'
|
||||
domain: [
|
||||
[ 'config_json', 'hostname' ]
|
||||
[ 'config_json', 'persistentLogging' ]
|
||||
]
|
||||
}
|
||||
{
|
||||
template:
|
||||
wifi:
|
||||
ssid: '{{networkSsid}}'
|
||||
'wifi-security':
|
||||
psk: '{{networkKey}}'
|
||||
domain: [
|
||||
[ 'system_connections', 'resin-sample', 'wifi' ]
|
||||
[ 'system_connections', 'resin-sample', 'wifi-security' ]
|
||||
]
|
||||
}
|
||||
]
|
||||
files:
|
||||
system_connections:
|
||||
fileset: true
|
||||
type: 'ini'
|
||||
location:
|
||||
path: 'system-connections'
|
||||
partition:
|
||||
primary: 1
|
||||
config_json:
|
||||
type: 'json'
|
||||
location:
|
||||
path: 'config.json'
|
||||
partition:
|
||||
primary: 1
|
||||
|
||||
module.exports =
|
||||
signature: 'local configure <target>'
|
||||
description: '(Re)configure a resinOS drive or image'
|
||||
help: '''
|
||||
Use this command to configure or reconfigure a resinOS drive or image.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin local configure /dev/sdc
|
||||
$ resin local configure path/to/image.img
|
||||
'''
|
||||
root: true
|
||||
action: (params, options, done) ->
|
||||
_ = require('lodash')
|
||||
Promise = require('bluebird')
|
||||
umount = Promise.promisifyAll(require('umount'))
|
||||
inquirer = require('inquirer')
|
||||
reconfix = require('reconfix')
|
||||
denymount = Promise.promisify(require('denymount'))
|
||||
|
||||
umount.isMountedAsync(params.target).then (isMounted) ->
|
||||
return if not isMounted
|
||||
umount.umountAsync(params.target)
|
||||
.then ->
|
||||
denymount params.target, (cb) ->
|
||||
reconfix.readConfiguration(CONFIGURATION_SCHEMA, params.target).then (data) ->
|
||||
|
||||
# `persistentLogging` can be `undefined`, so we want
|
||||
# to make sure that case defaults to `false`
|
||||
data.persistentLogging = data.persistentLogging or false
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
message: 'Network SSID'
|
||||
type: 'input'
|
||||
name: 'networkSsid'
|
||||
default: data.networkSsid
|
||||
}
|
||||
{
|
||||
message: 'Network Key'
|
||||
type: 'input'
|
||||
name: 'networkKey'
|
||||
default: data.networkKey
|
||||
}
|
||||
{
|
||||
message: 'Do you want to set advanced settings?'
|
||||
type: 'confirm'
|
||||
name: 'advancedSettings'
|
||||
default: false
|
||||
}
|
||||
{
|
||||
message: 'Device Hostname'
|
||||
type: 'input'
|
||||
name: 'hostname'
|
||||
default: data.hostname,
|
||||
when: (answers) ->
|
||||
answers.advancedSettings
|
||||
}
|
||||
{
|
||||
message: 'Do you want to enable persistent logging?'
|
||||
type: 'confirm'
|
||||
name: 'persistentLogging'
|
||||
default: data.persistentLogging
|
||||
when: (answers) ->
|
||||
answers.advancedSettings
|
||||
}
|
||||
]).then (answers) ->
|
||||
return _.merge(data, answers)
|
||||
.then (answers) ->
|
||||
reconfix.writeConfiguration(CONFIGURATION_SCHEMA, answers, params.target)
|
||||
.asCallback(cb)
|
||||
.then ->
|
||||
console.log('Done!')
|
||||
.asCallback(done)
|
17
lib/actions/local/index.coffee
Normal file
17
lib/actions/local/index.coffee
Normal file
@ -0,0 +1,17 @@
|
||||
###
|
||||
Copyright 2017 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.
|
||||
###
|
||||
|
||||
exports.configure = require('./configure')
|
@ -36,6 +36,8 @@
|
||||
"chalk": "^1.1.1",
|
||||
"coffee-script": "~1.12.2",
|
||||
"columnify": "^1.5.2",
|
||||
"denymount": "^2.2.0",
|
||||
"inquirer": "^3.0.6",
|
||||
"is-root": "^1.0.0",
|
||||
"js-yaml": "^3.7.0",
|
||||
"lodash": "^3.10.0",
|
||||
@ -44,6 +46,7 @@
|
||||
"nplugm": "^3.0.0",
|
||||
"president": "^2.0.1",
|
||||
"prettyjson": "^1.1.3",
|
||||
"reconfix": "0.0.3",
|
||||
"resin-cli-auth": "^1.0.0",
|
||||
"resin-cli-errors": "^1.2.0",
|
||||
"resin-cli-form": "^1.4.0",
|
||||
@ -59,7 +62,7 @@
|
||||
"rimraf": "^2.4.3",
|
||||
"rindle": "^1.0.0",
|
||||
"tmp": "^0.0.31",
|
||||
"umount": "^1.1.1",
|
||||
"umount": "^1.1.5",
|
||||
"underscore.string": "^3.1.1",
|
||||
"unzip2": "^0.2.5",
|
||||
"update-notifier": "^0.6.1",
|
||||
|
Loading…
Reference in New Issue
Block a user