mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 22:23:07 +00:00
Implement os download command
This command download an unconfigured image to both the cache and to the specified location by the `--output` option.
This commit is contained in:
parent
d2b9e6fd8c
commit
f6d8f12ba2
@ -1,9 +1,9 @@
|
||||
(function() {
|
||||
var Promise, _, capitano, commandOptions, events, form, fs, helpers, init, patterns, resin, rimraf, stepHandler, umount, vcs, visuals;
|
||||
var Promise, _, capitano, commandOptions, events, form, fs, helpers, init, patterns, resin, rimraf, stepHandler, tmp, umount, vcs, visuals;
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
capitano = require('capitano');
|
||||
capitano = Promise.promisifyAll(require('capitano'));
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
@ -29,6 +29,10 @@
|
||||
|
||||
helpers = require('../utils/helpers');
|
||||
|
||||
tmp = Promise.promisifyAll(require('tmp'));
|
||||
|
||||
tmp.setGracefulCleanup();
|
||||
|
||||
commandOptions = require('./command-options');
|
||||
|
||||
exports.list = {
|
||||
@ -156,8 +160,9 @@
|
||||
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umount.umountAsync);
|
||||
}
|
||||
}).then(function(answers) {
|
||||
console.info('Getting device operating system');
|
||||
return patterns.download(application.device_type).then(function(temporalPath) {
|
||||
return tmp.tmpNameAsync().then(function(temporalPath) {
|
||||
return capitano.runAsync("os download --output " + temporalPath);
|
||||
}).then(function(temporalPath) {
|
||||
var uuid;
|
||||
uuid = resin.models.device.generateUUID();
|
||||
console.log("Registering to " + application.app_name + ": " + uuid);
|
||||
|
@ -9,7 +9,8 @@
|
||||
keys: require('./keys'),
|
||||
logs: require('./logs'),
|
||||
notes: require('./notes'),
|
||||
help: require('./help')
|
||||
help: require('./help'),
|
||||
os: require('./os')
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
50
build/actions/os.js
Normal file
50
build/actions/os.js
Normal file
@ -0,0 +1,50 @@
|
||||
(function() {
|
||||
var fs, helpers, manager, visuals;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
manager = require('resin-image-manager');
|
||||
|
||||
visuals = require('resin-cli-visuals');
|
||||
|
||||
helpers = require('../utils/helpers');
|
||||
|
||||
exports.download = {
|
||||
signature: 'os download <type>',
|
||||
description: 'download an unconfigured os image',
|
||||
help: 'Use this command to download an unconfigured os image for a certain device type.\n\nExamples:\n\n $ resin os download parallella -o ../foo/bar/parallella.img',
|
||||
permission: 'user',
|
||||
options: [
|
||||
{
|
||||
signature: 'output',
|
||||
description: 'output path',
|
||||
parameter: 'output',
|
||||
alias: 'o',
|
||||
required: 'You have to specify an output location'
|
||||
}
|
||||
],
|
||||
action: function(params, options, done) {
|
||||
console.info("Getting device operating system for " + params.type);
|
||||
return manager.get(params.type).then(function(stream) {
|
||||
var bar, output, spinner;
|
||||
bar = new visuals.Progress('Downloading Device OS');
|
||||
spinner = new visuals.Spinner('Downloading Device OS (size unknown)');
|
||||
stream.on('progress', function(state) {
|
||||
if (state != null) {
|
||||
return bar.update(state);
|
||||
} else {
|
||||
return spinner.start();
|
||||
}
|
||||
});
|
||||
stream.on('end', function() {
|
||||
return spinner.stop();
|
||||
});
|
||||
output = fs.createWriteStream(options.output);
|
||||
return helpers.waitStream(stream.pipe(output))["return"](options.output);
|
||||
}).tap(function(output) {
|
||||
return console.log("The image was downloaded to " + output);
|
||||
}).nodeify(done);
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
@ -90,6 +90,8 @@
|
||||
|
||||
capitano.command(actions.env.remove);
|
||||
|
||||
capitano.command(actions.os.download);
|
||||
|
||||
capitano.command(actions.logs);
|
||||
|
||||
update.notify();
|
||||
|
@ -1,5 +1,7 @@
|
||||
(function() {
|
||||
var _, chalk, os;
|
||||
var Promise, _, chalk, os;
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
@ -34,4 +36,11 @@
|
||||
}
|
||||
};
|
||||
|
||||
exports.waitStream = function(stream) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
stream.on('close', resolve);
|
||||
return stream.on('error', reject);
|
||||
});
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Promise, _, form, helpers, manager, resin, visuals;
|
||||
var Promise, _, form, helpers, resin, visuals;
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
@ -11,8 +11,6 @@
|
||||
|
||||
resin = require('resin-sdk');
|
||||
|
||||
manager = require('resin-image-manager');
|
||||
|
||||
helpers = require('./helpers');
|
||||
|
||||
exports.selectDeviceType = function() {
|
||||
@ -109,23 +107,4 @@
|
||||
});
|
||||
};
|
||||
|
||||
exports.download = function(deviceType) {
|
||||
return manager.get(deviceType).then(function(stream) {
|
||||
var bar, spinner;
|
||||
bar = new visuals.Progress('Downloading Device OS');
|
||||
spinner = new visuals.Spinner('Downloading Device OS (size unknown)');
|
||||
stream.on('progress', function(state) {
|
||||
if (state != null) {
|
||||
return bar.update(state);
|
||||
} else {
|
||||
return spinner.start();
|
||||
}
|
||||
});
|
||||
stream.on('end', function() {
|
||||
return spinner.stop();
|
||||
});
|
||||
return manager.pipeTemporal(stream);
|
||||
});
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
@ -56,6 +56,12 @@
|
||||
"lib/actions/notes.coffee"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "OS",
|
||||
"files": [
|
||||
"lib/actions/os.coffee"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Wizard",
|
||||
"files": [
|
||||
|
@ -69,6 +69,10 @@ Now you have access to all the commands referenced below.
|
||||
|
||||
- [note <|note>](#note-60-note-62-)
|
||||
|
||||
- OS
|
||||
|
||||
- [os download <type>](#os-download-60-type-62-)
|
||||
|
||||
- Wizard
|
||||
|
||||
- [quickstart [name]](#quickstart-name-)
|
||||
@ -540,6 +544,22 @@ Examples:
|
||||
|
||||
device uuid
|
||||
|
||||
# OS
|
||||
|
||||
## os download <type>
|
||||
|
||||
Use this command to download an unconfigured os image for a certain device type.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os download parallella -o ../foo/bar/parallella.img
|
||||
|
||||
### Options
|
||||
|
||||
#### --output, -o <output>
|
||||
|
||||
output path
|
||||
|
||||
# Wizard
|
||||
|
||||
## quickstart [name]
|
||||
|
@ -1,5 +1,5 @@
|
||||
Promise = require('bluebird')
|
||||
capitano = require('capitano')
|
||||
capitano = Promise.promisifyAll(require('capitano'))
|
||||
_ = require('lodash')
|
||||
resin = require('resin-sdk')
|
||||
visuals = require('resin-cli-visuals')
|
||||
@ -12,6 +12,8 @@ rimraf = Promise.promisify(require('rimraf'))
|
||||
umount = Promise.promisifyAll(require('umount'))
|
||||
patterns = require('../utils/patterns')
|
||||
helpers = require('../utils/helpers')
|
||||
tmp = Promise.promisifyAll(require('tmp'))
|
||||
tmp.setGracefulCleanup()
|
||||
|
||||
commandOptions = require('./command-options')
|
||||
|
||||
@ -205,8 +207,9 @@ exports.init =
|
||||
.return(answers.drive)
|
||||
.then(umount.umountAsync)
|
||||
.then (answers) ->
|
||||
console.info('Getting device operating system')
|
||||
patterns.download(application.device_type).then (temporalPath) ->
|
||||
tmp.tmpNameAsync().then (temporalPath) ->
|
||||
return capitano.runAsync("os download --output #{temporalPath}")
|
||||
.then (temporalPath) ->
|
||||
uuid = resin.models.device.generateUUID()
|
||||
console.log("Registering to #{application.app_name}: #{uuid}")
|
||||
resin.models.device.register(application.app_name, uuid).tap (device) ->
|
||||
|
@ -9,3 +9,4 @@ module.exports =
|
||||
logs: require('./logs')
|
||||
notes: require('./notes')
|
||||
help: require('./help')
|
||||
os: require('./os')
|
||||
|
45
lib/actions/os.coffee
Normal file
45
lib/actions/os.coffee
Normal file
@ -0,0 +1,45 @@
|
||||
fs = require('fs')
|
||||
manager = require('resin-image-manager')
|
||||
visuals = require('resin-cli-visuals')
|
||||
helpers = require('../utils/helpers')
|
||||
|
||||
exports.download =
|
||||
signature: 'os download <type>'
|
||||
description: 'download an unconfigured os image'
|
||||
help: '''
|
||||
Use this command to download an unconfigured os image for a certain device type.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os download parallella -o ../foo/bar/parallella.img
|
||||
'''
|
||||
permission: 'user'
|
||||
options: [
|
||||
signature: 'output'
|
||||
description: 'output path'
|
||||
parameter: 'output'
|
||||
alias: 'o'
|
||||
required: 'You have to specify an output location'
|
||||
]
|
||||
action: (params, options, done) ->
|
||||
console.info("Getting device operating system for #{params.type}")
|
||||
|
||||
manager.get(params.type).then (stream) ->
|
||||
bar = new visuals.Progress('Downloading Device OS')
|
||||
spinner = new visuals.Spinner('Downloading Device OS (size unknown)')
|
||||
|
||||
stream.on 'progress', (state) ->
|
||||
if state?
|
||||
bar.update(state)
|
||||
else
|
||||
spinner.start()
|
||||
|
||||
stream.on 'end', ->
|
||||
spinner.stop()
|
||||
|
||||
output = fs.createWriteStream(options.output)
|
||||
|
||||
return helpers.waitStream(stream.pipe(output)).return(options.output)
|
||||
.tap (output) ->
|
||||
console.log("The image was downloaded to #{output}")
|
||||
.nodeify(done)
|
@ -64,6 +64,9 @@ capitano.command(actions.env.add)
|
||||
capitano.command(actions.env.rename)
|
||||
capitano.command(actions.env.remove)
|
||||
|
||||
# ---------- OS Module ----------
|
||||
capitano.command(actions.os.download)
|
||||
|
||||
# ---------- Logs Module ----------
|
||||
capitano.command(actions.logs)
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
Promise = require('bluebird')
|
||||
_ = require('lodash')
|
||||
_.str = require('underscore.string')
|
||||
os = require('os')
|
||||
@ -21,3 +22,8 @@ exports.stateToString = (state) ->
|
||||
return "#{result} #{state.operation.script}"
|
||||
else
|
||||
throw new Error("Unsupported operation: #{state.operation.type}")
|
||||
|
||||
exports.waitStream = (stream) ->
|
||||
return new Promise (resolve, reject) ->
|
||||
stream.on('close', resolve)
|
||||
stream.on('error', reject)
|
||||
|
@ -3,7 +3,6 @@ Promise = require('bluebird')
|
||||
form = require('resin-cli-form')
|
||||
visuals = require('resin-cli-visuals')
|
||||
resin = require('resin-sdk')
|
||||
manager = require('resin-image-manager')
|
||||
helpers = require('./helpers')
|
||||
|
||||
exports.selectDeviceType = ->
|
||||
@ -76,19 +75,3 @@ exports.askDeviceOptions = (deviceType) ->
|
||||
.then (answers) ->
|
||||
answers.os ?= helpers.getOperatingSystem()
|
||||
return answers
|
||||
|
||||
exports.download = (deviceType) ->
|
||||
manager.get(deviceType).then (stream) ->
|
||||
bar = new visuals.Progress('Downloading Device OS')
|
||||
spinner = new visuals.Spinner('Downloading Device OS (size unknown)')
|
||||
|
||||
stream.on 'progress', (state) ->
|
||||
if state?
|
||||
bar.update(state)
|
||||
else
|
||||
spinner.start()
|
||||
|
||||
stream.on 'end', ->
|
||||
spinner.stop()
|
||||
|
||||
return manager.pipeTemporal(stream)
|
||||
|
@ -63,6 +63,7 @@
|
||||
"resin-settings-client": "^3.1.0",
|
||||
"resin-vcs": "^2.0.0",
|
||||
"rimraf": "^2.4.3",
|
||||
"tmp": "0.0.28",
|
||||
"umount": "^1.1.1",
|
||||
"underscore.string": "^3.1.1",
|
||||
"update-notifier": "^0.5.0",
|
||||
|
Loading…
Reference in New Issue
Block a user