mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-30 10:38:50 +00:00
44 lines
1.1 KiB
CoffeeScript
44 lines
1.1 KiB
CoffeeScript
|
_ = require('lodash')
|
||
|
async = require('async')
|
||
|
path = require('path')
|
||
|
mkdirp = require('mkdirp')
|
||
|
url = require('url')
|
||
|
resin = require('../resin')
|
||
|
connection = require('../connection/connection')
|
||
|
|
||
|
exports.download = (id) ->
|
||
|
|
||
|
fileName = "#{id}-#{Date.now()}"
|
||
|
outputFile = path.join(resin.config.osDirectory, fileName)
|
||
|
|
||
|
async.waterfall [
|
||
|
|
||
|
(callback) ->
|
||
|
|
||
|
# We need to ensure this directory exists
|
||
|
mkdirp resin.config.osDirectory, (error) ->
|
||
|
return callback(error)
|
||
|
|
||
|
(callback) ->
|
||
|
params =
|
||
|
network: resin.cli.getArgument('network')
|
||
|
wifiSsid: resin.cli.getArgument('wifiSsid')
|
||
|
wifiKey: resin.cli.getArgument('wifiKey')
|
||
|
|
||
|
connection.parseConnectionParameters(params, callback)
|
||
|
|
||
|
(parameters, callback) ->
|
||
|
parameters.appId = id
|
||
|
|
||
|
query = url.format(query: parameters)
|
||
|
downloadUrl = url.resolve(resin.config.urls.download, query)
|
||
|
|
||
|
return callback(null, downloadUrl)
|
||
|
|
||
|
(downloadUrl, callback) ->
|
||
|
resin.ui.patterns.downloadFile(downloadUrl, outputFile, callback)
|
||
|
|
||
|
], (error) ->
|
||
|
resin.errors.handle(error) if error?
|
||
|
console.log "\n\nFinished downloading #{outputFile}"
|