2014-12-02 15:08:22 +00:00
|
|
|
_ = require('lodash')
|
|
|
|
async = require('async')
|
|
|
|
path = require('path')
|
|
|
|
mkdirp = require('mkdirp')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2015-01-20 19:10:18 +00:00
|
|
|
ui = require('../ui')
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.download =
|
|
|
|
signature: 'os download <id>'
|
|
|
|
description: 'download device OS'
|
|
|
|
help: '''
|
|
|
|
Use this command to download the device OS configured to a specific network.
|
2015-01-08 13:55:01 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Ethernet:
|
|
|
|
You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".
|
2015-01-08 13:55:01 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Wifi:
|
|
|
|
You can setup the device OS to use wifi by setting the `--network` option to "wifi".
|
|
|
|
If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
By default, this command saved the downloaded image into a resin specific directory.
|
|
|
|
You can save it to a custom location by specifying the `--output` option.
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
|
|
|
$ resin os download 91 --network ethernet
|
|
|
|
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123
|
|
|
|
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
|
|
|
|
'''
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
signature: 'network'
|
|
|
|
parameter: 'network'
|
|
|
|
description: 'network type'
|
|
|
|
alias: 'n'
|
|
|
|
}
|
|
|
|
{
|
|
|
|
signature: 'ssid'
|
|
|
|
parameter: 'ssid'
|
|
|
|
description: 'wifi ssid, if network is wifi'
|
|
|
|
alias: 's'
|
|
|
|
}
|
|
|
|
{
|
|
|
|
signature: 'key'
|
|
|
|
parameter: 'key'
|
|
|
|
description: 'wifi key, if network is wifi'
|
|
|
|
alias: 'k'
|
|
|
|
}
|
|
|
|
{
|
|
|
|
signature: 'output'
|
|
|
|
parameter: 'output'
|
|
|
|
description: 'output file'
|
|
|
|
alias: 'o'
|
|
|
|
}
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-01-15 17:10:14 +00:00
|
|
|
action: (params, options, done) ->
|
|
|
|
osParams =
|
|
|
|
network: options.network
|
|
|
|
wifiSsid: options.ssid
|
|
|
|
wifiKey: options.key
|
|
|
|
appId: params.id
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
fileName = resin.models.os.generateCacheName(osParams)
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
outputFile = options.output or path.join(resin.settings.get('directories.os'), fileName)
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
async.waterfall [
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
(callback) ->
|
2014-12-22 19:40:57 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
# We need to ensure this directory exists
|
|
|
|
mkdirp path.dirname(outputFile), (error) ->
|
|
|
|
return callback(error)
|
2014-12-22 19:40:57 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
(callback) ->
|
|
|
|
console.info("Destination file: #{outputFile}")
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
bar = null
|
|
|
|
received = 0
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
resin.models.os.download osParams, outputFile, callback, (state) ->
|
2015-01-20 19:41:14 +00:00
|
|
|
return if options.quiet
|
2014-12-02 15:08:22 +00:00
|
|
|
|
2015-01-20 19:10:18 +00:00
|
|
|
bar ?= new ui.widgets.Progress('Downloading device OS', state.total)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
return if bar.complete or not state?
|
|
|
|
|
|
|
|
bar.tick(state.received - received)
|
|
|
|
received = state.received
|
|
|
|
|
|
|
|
], (error) ->
|
|
|
|
return done(error) if error?
|
|
|
|
console.info("\nFinished downloading #{outputFile}")
|
|
|
|
return done()
|