From 2d09c18d6b1949764a23a654398ca3539424bbd8 Mon Sep 17 00:00:00 2001 From: Kostas Lekkas Date: Wed, 8 Mar 2017 23:30:24 +0000 Subject: [PATCH] Build JS --- build/actions/app.js | 3 +- build/actions/auth.js | 2 +- build/actions/command-options.js | 2 +- build/actions/config.js | 2 +- build/actions/device.js | 2 +- build/actions/environment-variables.js | 2 +- build/actions/help.js | 2 +- build/actions/index.js | 3 +- build/actions/info.js | 2 +- build/actions/keys.js | 2 +- build/actions/local/common.js | 89 +++++++++++++++++ build/actions/local/configure.js | 133 +++++++++++++++++++++++++ build/actions/local/flash.js | 129 ++++++++++++++++++++++++ build/actions/local/index.js | 34 +++++++ build/actions/local/logs.js | 68 +++++++++++++ build/actions/local/promote.js | 64 ++++++++++++ build/actions/local/push.js | 34 +++++++ build/actions/local/scan.js | 101 +++++++++++++++++++ build/actions/local/ssh.js | 93 +++++++++++++++++ build/actions/logs.js | 2 +- build/actions/notes.js | 2 +- build/actions/os.js | 2 +- build/actions/settings.js | 2 +- build/actions/sync.js | 2 +- build/actions/wizard.js | 2 +- build/app.js | 16 ++- build/errors.js | 2 +- build/events.js | 2 +- build/utils/helpers.js | 2 +- build/utils/messages.js | 2 +- build/utils/patterns.js | 2 +- build/utils/plugins.js | 2 +- build/utils/update.js | 2 +- build/utils/validation.js | 2 +- 34 files changed, 785 insertions(+), 26 deletions(-) create mode 100644 build/actions/local/common.js create mode 100644 build/actions/local/configure.js create mode 100644 build/actions/local/flash.js create mode 100644 build/actions/local/index.js create mode 100644 build/actions/local/logs.js create mode 100644 build/actions/local/promote.js create mode 100644 build/actions/local/push.js create mode 100644 build/actions/local/scan.js create mode 100644 build/actions/local/ssh.js diff --git a/build/actions/app.js b/build/actions/app.js index 9f53017d..143091bc 100644 --- a/build/actions/app.js +++ b/build/actions/app.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io @@ -34,7 +34,6 @@ limitations under the License. } ], permission: 'user', - primary: true, action: function(params, options, done) { var patterns, resin; resin = require('resin-sdk-preconfigured'); diff --git a/build/actions/auth.js b/build/actions/auth.js index 6b16c86f..051d1205 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/command-options.js b/build/actions/command-options.js index e26ac0c9..4c175364 100644 --- a/build/actions/command-options.js +++ b/build/actions/command-options.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/config.js b/build/actions/config.js index b3a47141..4bd4e329 100644 --- a/build/actions/config.js +++ b/build/actions/config.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/device.js b/build/actions/device.js index 5d502189..39eea974 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/environment-variables.js b/build/actions/environment-variables.js index e3e304ac..e9f807ca 100644 --- a/build/actions/environment-variables.js +++ b/build/actions/environment-variables.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/help.js b/build/actions/help.js index 5a8c8833..5e9745a0 100644 --- a/build/actions/help.js +++ b/build/actions/help.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/index.js b/build/actions/index.js index e4570848..bdf1d20f 100644 --- a/build/actions/index.js +++ b/build/actions/index.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io @@ -26,6 +26,7 @@ limitations under the License. env: require('./environment-variables'), keys: require('./keys'), logs: require('./logs'), + local: require('./local'), notes: require('./notes'), help: require('./help'), os: require('./os'), diff --git a/build/actions/info.js b/build/actions/info.js index ab0256ca..49b8eafc 100644 --- a/build/actions/info.js +++ b/build/actions/info.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/keys.js b/build/actions/keys.js index 591fbc15..aa11737a 100644 --- a/build/actions/keys.js +++ b/build/actions/keys.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/local/common.js b/build/actions/local/common.js new file mode 100644 index 00000000..a6801592 --- /dev/null +++ b/build/actions/local/common.js @@ -0,0 +1,89 @@ +// Generated by CoffeeScript 1.12.4 +(function() { + var Docker, Promise, _, chalk, form; + + Promise = require('bluebird'); + + _ = require('lodash'); + + Docker = require('docker-toolbelt'); + + form = require('resin-cli-form'); + + chalk = require('chalk'); + + module.exports = { + selectContainerFromDevice: Promise.method(function(deviceIp) { + var docker; + docker = new Docker({ + host: deviceIp, + port: 2375 + }); + return docker.listContainersAsync({ + all: true + }).then(function(containers) { + if (_.isEmpty(containers)) { + throw new Error("No containers found in " + deviceIp); + } + return form.ask({ + message: 'Select a container', + type: 'list', + choices: _.map(containers, function(container) { + var containerName, containerStatus, shortContainerId; + containerName = container.Names[0] || 'Untitled'; + shortContainerId = ('' + container.Id).substr(0, 11); + containerStatus = container.Status; + return { + name: containerName + " (" + shortContainerId + ") - " + containerStatus, + value: container.Id + }; + }) + }); + }); + }), + pipeContainerStream: Promise.method(function(arg) { + var container, deviceIp, docker, follow, name, outStream, ref; + deviceIp = arg.deviceIp, name = arg.name, outStream = arg.outStream, follow = (ref = arg.follow) != null ? ref : false; + docker = new Docker({ + host: deviceIp, + port: 2375 + }); + container = docker.getContainer(name); + return container.inspectAsync().then(function(containerInfo) { + var ref1; + return containerInfo != null ? (ref1 = containerInfo.State) != null ? ref1.Running : void 0 : void 0; + }).then(function(isRunning) { + return container.attachAsync({ + logs: !follow || !isRunning, + stream: follow && isRunning, + stdout: true, + stderr: true + }); + }).then(function(containerStream) { + return containerStream.pipe(outStream); + })["catch"](function(err) { + err = '' + err.statusCode; + if (err === '404') { + return console.log(chalk.red.bold("Container '" + name + "' not found.")); + } + throw err; + }); + }), + getSubShellCommand: function(command) { + var os; + os = require('os'); + if (os.platform() === 'win32') { + return { + program: 'cmd.exe', + args: ['/s', '/c', command] + }; + } else { + return { + program: '/bin/sh', + args: ['-c', command] + }; + } + } + }; + +}).call(this); diff --git a/build/actions/local/configure.js b/build/actions/local/configure.js new file mode 100644 index 00000000..af928706 --- /dev/null +++ b/build/actions/local/configure.js @@ -0,0 +1,133 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + var CONFIGURATION_SCHEMA; + + 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 ', + description: '(Re)configure a resinOS drive or image', + help: 'Use this command to configure or reconfigure a resinOS drive or image.\n\nExamples:\n\n $ resin local configure /dev/sdc\n $ resin local configure path/to/image.img', + root: true, + action: function(params, options, done) { + var Promise, _, denymount, inquirer, reconfix, umount; + _ = require('lodash'); + Promise = require('bluebird'); + umount = Promise.promisifyAll(require('umount')); + inquirer = require('inquirer'); + reconfix = require('reconfix'); + denymount = Promise.promisify(require('denymount')); + return umount.isMountedAsync(params.target).then(function(isMounted) { + if (!isMounted) { + return; + } + return umount.umountAsync(params.target); + }).then(function() { + return denymount(params.target, function(cb) { + return reconfix.readConfiguration(CONFIGURATION_SCHEMA, params.target).then(function(data) { + data.persistentLogging = data.persistentLogging || false; + return 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: function(answers) { + return answers.advancedSettings; + } + }, { + message: 'Do you want to enable persistent logging?', + type: 'confirm', + name: 'persistentLogging', + "default": data.persistentLogging, + when: function(answers) { + return answers.advancedSettings; + } + } + ]).then(function(answers) { + return _.merge(data, answers); + }); + }).then(function(answers) { + return reconfix.writeConfiguration(CONFIGURATION_SCHEMA, answers, params.target); + }).asCallback(cb); + }); + }).then(function() { + return console.log('Done!'); + }).asCallback(done); + } + }; + +}).call(this); diff --git a/build/actions/local/flash.js b/build/actions/local/flash.js new file mode 100644 index 00000000..e05ea86a --- /dev/null +++ b/build/actions/local/flash.js @@ -0,0 +1,129 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + module.exports = { + signature: 'local flash ', + description: 'Flash an image to a drive', + help: 'Use this command to flash a resinOS image to a drive.\n\nExamples:\n\n $ resin local flash path/to/resinos.img\n $ resin local flash path/to/resinos.img --drive /dev/disk2\n $ resin local flash path/to/resinos.img --drive /dev/disk2 --yes', + options: [ + { + signature: 'yes', + boolean: true, + description: 'confirm non-interactively', + alias: 'y' + }, { + signature: 'drive', + parameter: 'drive', + description: 'drive', + alias: 'd' + } + ], + root: true, + action: function(params, options, done) { + var Promise, _, chalk, drivelist, form, fs, imageWrite, os, umount, visuals; + _ = require('lodash'); + os = require('os'); + Promise = require('bluebird'); + umount = Promise.promisifyAll(require('umount')); + fs = Promise.promisifyAll(require('fs')); + drivelist = Promise.promisifyAll(require('drivelist')); + chalk = require('chalk'); + visuals = require('resin-cli-visuals'); + form = require('resin-cli-form'); + require('babel-register')({ + only: /etcher-image-write|bmapflash/, + presets: ['es2015'], + compact: true + }); + imageWrite = require('etcher-image-write'); + return form.run([ + { + message: 'Select drive', + type: 'drive', + name: 'drive' + }, { + message: 'This will erase the selected drive. Are you sure?', + type: 'confirm', + name: 'yes', + "default": false + } + ], { + override: { + drive: options.drive, + yes: options.yes || void 0 + } + }).then(function(answers) { + if (answers.yes !== true) { + console.log(chalk.red.bold('Aborted image flash')); + process.exit(0); + } + return drivelist.listAsync().then(function(drives) { + var selectedDrive; + selectedDrive = _.find(drives, { + device: answers.drive + }); + if (selectedDrive == null) { + throw new Error("Drive not found: " + answers.drive); + } + return selectedDrive; + }); + }).then(function(selectedDrive) { + var progressBars; + progressBars = { + write: new visuals.Progress('Flashing'), + check: new visuals.Progress('Validating') + }; + return umount.umountAsync(selectedDrive.device).then(function() { + return Promise.props({ + imageSize: fs.statAsync(params.image).get('size'), + imageStream: Promise.resolve(fs.createReadStream(params.image)), + driveFileDescriptor: fs.openAsync(selectedDrive.raw, 'rs+') + }); + }).then(function(results) { + return imageWrite.write({ + fd: results.driveFileDescriptor, + device: selectedDrive.raw, + size: selectedDrive.size + }, { + stream: results.imageStream, + size: results.imageSize + }, { + check: true + }); + }).then(function(writer) { + return new Promise(function(resolve, reject) { + writer.on('progress', function(state) { + return progressBars[state.type].update(state); + }); + writer.on('error', reject); + return writer.on('done', resolve); + }); + }).then(function() { + var removedrive; + if ((os.platform() === 'win32') && (selectedDrive.mountpoint != null)) { + removedrive = Promise.promisifyAll(require('removedrive')); + return removedrive.ejectAsync(selectedDrive.mountpoint); + } + return umount.umountAsync(selectedDrive.device); + }); + }).asCallback(done); + } + }; + +}).call(this); diff --git a/build/actions/local/index.js b/build/actions/local/index.js new file mode 100644 index 00000000..e40643cd --- /dev/null +++ b/build/actions/local/index.js @@ -0,0 +1,34 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + exports.configure = require('./configure'); + + exports.flash = require('./flash'); + + exports.logs = require('./logs'); + + exports.promote = require('./promote'); + + exports.scan = require('./scan'); + + exports.ssh = require('./ssh'); + + exports.push = require('./push'); + +}).call(this); diff --git a/build/actions/local/logs.js b/build/actions/local/logs.js new file mode 100644 index 00000000..2f0c688c --- /dev/null +++ b/build/actions/local/logs.js @@ -0,0 +1,68 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + module.exports = { + signature: 'local logs [deviceIp]', + description: 'Get or attach to logs of a running container on a resinOS device', + help: '\nExamples:\n\n $ resin local logs\n $ resin local logs -f\n $ resin local logs 192.168.1.10\n $ resin local logs 192.168.1.10 -f\n $ resin local logs 192.168.1.10 -f --app-name myapp', + options: [ + { + signature: 'follow', + boolean: true, + description: 'follow log', + alias: 'f' + }, { + signature: 'app-name', + parameter: 'name', + description: 'name of container to get logs from', + alias: 'a' + } + ], + action: function(params, options, done) { + var Promise, forms, pipeContainerStream, ref, selectContainerFromDevice; + Promise = require('bluebird'); + forms = require('resin-sync').forms; + ref = require('./common'), selectContainerFromDevice = ref.selectContainerFromDevice, pipeContainerStream = ref.pipeContainerStream; + return Promise["try"](function() { + if (params.deviceIp == null) { + return forms.selectLocalResinOsDevice(); + } + return params.deviceIp; + }).then((function(_this) { + return function(deviceIp) { + _this.deviceIp = deviceIp; + if (options['app-name'] == null) { + return selectContainerFromDevice(_this.deviceIp); + } + return options['app-name']; + }; + })(this)).then((function(_this) { + return function(appName) { + return pipeContainerStream({ + deviceIp: _this.deviceIp, + name: appName, + outStream: process.stdout, + follow: options['follow'] + }); + }; + })(this)); + } + }; + +}).call(this); diff --git a/build/actions/local/promote.js b/build/actions/local/promote.js new file mode 100644 index 00000000..3c79c7a0 --- /dev/null +++ b/build/actions/local/promote.js @@ -0,0 +1,64 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + module.exports = { + signature: 'local promote [deviceIp]', + description: 'Promote a resinOS device', + help: 'Warning: \'resin promote\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to promote your device.\n\nPromoting a device will provision it onto the Resin platform,\nconverting it from an unmanaged device to a managed device.\n\nExamples:\n\n $ resin local promote\n $ resin local promote --port 22222\n $ resin local promote --verbose', + options: [ + { + signature: 'verbose', + boolean: true, + description: 'increase verbosity', + alias: 'v' + }, { + signature: 'port', + parameter: 'port', + description: 'ssh port number (default: 22222)', + alias: 'p' + } + ], + action: function(params, options, done) { + var Promise, _, child_process, forms, getSubShellCommand, verbose; + child_process = require('child_process'); + Promise = require('bluebird'); + _ = require('lodash'); + forms = require('resin-sync').forms; + getSubShellCommand = require('./common').getSubShellCommand; + if (options.port == null) { + options.port = 22222; + } + verbose = options.verbose ? '-vvv' : ''; + return Promise["try"](function() { + return params.deviceIp != null ? params.deviceIp : params.deviceIp = forms.selectLocalResinOsDevice(); + }).then(function(deviceIp) { + var command, subShellCommand; + _.assign(options, { + deviceIp: deviceIp + }); + command = "ssh " + verbose + " -t -p " + options.port + " -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no root@" + options.deviceIp + " -- \"resin-provision interactive\""; + subShellCommand = getSubShellCommand(command); + return child_process.spawn(subShellCommand.program, subShellCommand.args, { + stdio: 'inherit' + }); + }).nodeify(done); + } + }; + +}).call(this); diff --git a/build/actions/local/push.js b/build/actions/local/push.js new file mode 100644 index 00000000..44f0c869 --- /dev/null +++ b/build/actions/local/push.js @@ -0,0 +1,34 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + var resinPush; + + resinPush = require('resin-sync').capitano('resin-toolbox'); + + resinPush.signature = 'local push [deviceIp]'; + + resinPush.help = { + help: 'Warning: \'resin local push\' requires an openssh-compatible client and \'rsync\' to\nbe correctly installed in your shell environment. For more information (including\nWindows support) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to push your local changes to a container on a LAN-accessible resinOS device on the fly.\n\nIf `Dockerfile` or any file in the \'build-triggers\' list is changed, a new container will be built and run on your device.\nIf not, changes will simply be synced with `rsync` into the application container.\n\nAfter every \'resin local push\' the updated settings will be saved in\n\'/.resin-sync.yml\' and will be used in later invocations. You can\nalso change any option by editing \'.resin-sync.yml\' directly.\n\nHere is an example \'.resin-sync.yml\' :\n\n $ cat $PWD/.resin-sync.yml\n destination: \'/usr/src/app\'\n before: \'echo Hello\'\n after: \'echo Done\'\n ignore:\n - .git\n - node_modules/\n\nCommand line options have precedence over the ones saved in \'.resin-sync.yml\'.\n\nIf \'.gitignore\' is found in the source directory then all explicitly listed files will be\nexcluded when using rsync to update the container. You can choose to change this default behavior with the\n\'--skip-gitignore\' option.\n\nExamples:\n\n $ resin local push\n $ resin local push --app-name test-server --build-triggers package.json,requirements.txt\n $ resin local push --force-build\n $ resin local push --force-build --skip-logs\n $ resin local push --ignore lib/\n $ resin local push --verbose false\n $ resin local push 192.168.2.10 --source . --destination /usr/src/app\n $ resin local push 192.168.2.10 -s /home/user/myResinProject -d /usr/src/app --before \'echo Hello\' --after \'echo Done\'' + }; + + resinPush.primary = true; + + module.exports = resinPush; + +}).call(this); diff --git a/build/actions/local/scan.js b/build/actions/local/scan.js new file mode 100644 index 00000000..141057b4 --- /dev/null +++ b/build/actions/local/scan.js @@ -0,0 +1,101 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + var dockerInfoProperties, dockerVersionProperties; + + dockerInfoProperties = ['Containers', 'ContainersRunning', 'ContainersPaused', 'ContainersStopped', 'Images', 'Driver', 'SystemTime', 'KernelVersion', 'OperatingSystem', 'Architecture']; + + dockerVersionProperties = ['Version', 'ApiVersion']; + + module.exports = { + signature: 'local scan', + description: 'Scan for resinOS devices in your local network', + help: '\nExamples:\n\n $ resin local scan\n $ resin local scan --timeout 120\n $ resin local scan --verbose', + options: [ + { + signature: 'verbose', + boolean: true, + description: 'Display full info', + alias: 'v' + }, { + signature: 'timeout', + parameter: 'timeout', + description: 'Scan timeout in seconds', + alias: 't' + } + ], + primary: true, + action: function(params, options, done) { + var Docker, Promise, SpinnerPromise, _, discover, prettyjson; + Promise = require('bluebird'); + _ = require('lodash'); + prettyjson = require('prettyjson'); + Docker = require('docker-toolbelt'); + discover = require('resin-sync').discover; + SpinnerPromise = require('resin-cli-visuals').SpinnerPromise; + if (options.timeout != null) { + options.timeout *= 1000; + } + return Promise["try"](function() { + return new SpinnerPromise({ + promise: discover.discoverLocalResinOsDevices(options.timeout), + startMessage: 'Scanning for local resinOS devices..', + stopMessage: 'Reporting scan results' + }); + }).tap(function(devices) { + if (_.isEmpty(devices)) { + throw new Error('Could not find any resinOS devices in the local network'); + } + }).map(function(arg) { + var address, docker, host; + host = arg.host, address = arg.address; + docker = new Docker({ + host: address, + port: 2375 + }); + return Promise.props({ + dockerInfo: docker.infoAsync().catchReturn('Could not get Docker info'), + dockerVersion: docker.versionAsync().catchReturn('Could not get Docker version') + }).then(function(arg1) { + var dockerInfo, dockerVersion; + dockerInfo = arg1.dockerInfo, dockerVersion = arg1.dockerVersion; + if (!options.verbose) { + if (_.isObject(dockerInfo)) { + dockerInfo = _.pick(dockerInfo, dockerInfoProperties); + } + if (_.isObject(dockerVersion)) { + dockerVersion = _.pick(dockerVersion, dockerVersionProperties); + } + } + return { + host: host, + address: address, + dockerInfo: dockerInfo, + dockerVersion: dockerVersion + }; + }); + }).then(function(devicesInfo) { + return console.log(prettyjson.render(devicesInfo, { + noColor: true + })); + }).nodeify(done); + } + }; + +}).call(this); diff --git a/build/actions/local/ssh.js b/build/actions/local/ssh.js new file mode 100644 index 00000000..d34d231a --- /dev/null +++ b/build/actions/local/ssh.js @@ -0,0 +1,93 @@ +// Generated by CoffeeScript 1.12.4 + +/* +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. + */ + +(function() { + module.exports = { + signature: 'local ssh [deviceIp]', + description: 'Get a shell into a resinOS device', + help: 'Warning: \'resin local ssh\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to get a shell into the running application container of\nyour device.\n\nThe \'--host\' option will get you a shell into the Host OS of the resinOS device.\nNo option will return a list of containers to enter or you can explicitly select\none by passing its name to the --container option\n\nExamples:\n\n $ resin local ssh\n $ resin local ssh --host\n $ resin local ssh --container chaotic_water\n $ resin local ssh --container chaotic_water --port 22222\n $ resin local ssh --verbose', + options: [ + { + signature: 'verbose', + boolean: true, + description: 'increase verbosity', + alias: 'v' + }, { + signature: 'host', + boolean: true, + description: 'get a shell into the host OS', + alias: 's' + }, { + signature: 'container', + parameter: 'container', + "default": null, + description: 'name of container to access', + alias: 'c' + }, { + signature: 'port', + parameter: 'port', + description: 'ssh port number (default: 22222)', + alias: 'p' + } + ], + action: function(params, options, done) { + var Promise, _, child_process, forms, getSubShellCommand, ref, selectContainerFromDevice, verbose; + child_process = require('child_process'); + Promise = require('bluebird'); + _ = require('lodash'); + forms = require('resin-sync').forms; + ref = require('./common'), selectContainerFromDevice = ref.selectContainerFromDevice, getSubShellCommand = ref.getSubShellCommand; + if (options.host === true && (options.container != null)) { + throw new Error('Please pass either --host or --container option'); + } + if (options.port == null) { + options.port = 22222; + } + verbose = options.verbose ? '-vvv' : ''; + return Promise["try"](function() { + if (params.deviceIp == null) { + return forms.selectLocalResinOsDevice(); + } + return params.deviceIp; + }).then(function(deviceIp) { + _.assign(options, { + deviceIp: deviceIp + }); + if (options.host) { + return; + } + if (options.container == null) { + return selectContainerFromDevice(deviceIp); + } + return options.container; + }).then(function(container) { + var command, shellCmd, subShellCommand; + command = "ssh " + verbose + " -t -p " + options.port + " -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no root@" + options.deviceIp; + if (!options.host) { + shellCmd = '/bin/sh -c $"\'if [ -e /bin/bash ]; then exec /bin/bash; else exec /bin/sh; fi\'"'; + command += " docker exec -ti " + container + " " + shellCmd; + } + subShellCommand = getSubShellCommand(command); + return child_process.spawn(subShellCommand.program, subShellCommand.args, { + stdio: 'inherit' + }); + }).nodeify(done); + } + }; + +}).call(this); diff --git a/build/actions/logs.js b/build/actions/logs.js index 115ad887..fde5a831 100644 --- a/build/actions/logs.js +++ b/build/actions/logs.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/notes.js b/build/actions/notes.js index f6ab34b6..b43d82e7 100644 --- a/build/actions/notes.js +++ b/build/actions/notes.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/os.js b/build/actions/os.js index dbe8633a..9b8e1d5a 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/settings.js b/build/actions/settings.js index 55225ddc..e6e0c149 100644 --- a/build/actions/settings.js +++ b/build/actions/settings.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/sync.js b/build/actions/sync.js index 2f325bbb..7cd9f3ab 100644 --- a/build/actions/sync.js +++ b/build/actions/sync.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/actions/wizard.js b/build/actions/wizard.js index 81d2a8e8..f91ed85c 100644 --- a/build/actions/wizard.js +++ b/build/actions/wizard.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/app.js b/build/app.js index 36465ad6..9032df5b 100644 --- a/build/app.js +++ b/build/app.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io @@ -156,6 +156,20 @@ limitations under the License. capitano.command(actions.ssh); + capitano.command(actions.local.configure); + + capitano.command(actions.local.flash); + + capitano.command(actions.local.logs); + + capitano.command(actions.local.promote); + + capitano.command(actions.local.push); + + capitano.command(actions.local.ssh); + + capitano.command(actions.local.scan); + update.notify(); plugins.register(/^resin-plugin-(.+)$/).then(function() { diff --git a/build/errors.js b/build/errors.js index bb06ba0f..9f27848b 100644 --- a/build/errors.js +++ b/build/errors.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/events.js b/build/events.js index 548f02d5..d0348001 100644 --- a/build/events.js +++ b/build/events.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 (function() { var Mixpanel, Promise, _, capitanoState, packageJSON, resin; diff --git a/build/utils/helpers.js b/build/utils/helpers.js index 811439e0..125deb20 100644 --- a/build/utils/helpers.js +++ b/build/utils/helpers.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/utils/messages.js b/build/utils/messages.js index 0be33432..6e5bbebd 100644 --- a/build/utils/messages.js +++ b/build/utils/messages.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 (function() { exports.gettingStarted = 'Run the following command to get a device started with Resin.io\n\n $ resin quickstart'; diff --git a/build/utils/patterns.js b/build/utils/patterns.js index e023fe3e..8ff87d5c 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/utils/plugins.js b/build/utils/plugins.js index c6bfff0f..5b6cb625 100644 --- a/build/utils/plugins.js +++ b/build/utils/plugins.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/utils/update.js b/build/utils/update.js index 54a40b44..17df8248 100644 --- a/build/utils/update.js +++ b/build/utils/update.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io diff --git a/build/utils/validation.js b/build/utils/validation.js index 486fbc58..a4ff0617 100644 --- a/build/utils/validation.js +++ b/build/utils/validation.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.2 +// Generated by CoffeeScript 1.12.4 /* Copyright 2016 Resin.io