Commit e77b6798 authored by Michał Siwek's avatar Michał Siwek

Implement downloading and searching with sha1sum verification

parent ad4b94b4
#!/usr/local/bin/coffee
program = require 'commander'
fs = require 'fs'
events = require 'events'
global.eventDispatch = new events.EventEmitter
crypto = require 'crypto'
program.version '0.0.1'
program.parse process.argv
......@@ -9,20 +12,47 @@ program.parse process.argv
action = process.argv[2]
pkgName = process.argv[3]
search = (pkgName, callback) ->
fs.readdir '.', (err, files) =>
callback file for file in files when file.indexOf(pkgName) isnt -1
@pkg = (pkgName) ->
eventDispatch.on 'packageFound', ->
@pkg = require './formulas/' + pkgName + '.coffee'
eventDispatch.on 'packageNotFound', ->
console.log 'package ' + pkgName + ' not found :('
process.exit 1
look_for pkgName
look_for = (pkgName) ->
fs.readdir 'formulas', (err, files) ->
return eventDispatch.emit 'packageFound' for file in files when file.indexOf(pkgName) isnt -1
return eventDispatch.emit 'packageNotFound'
download = (pkgName) ->
pkg = require './' + pkgName + '.coffee'
pkg.getBinary()
search = (pkgName) =>
@pkg pkgName
eventDispatch.on 'packageFound', ->
console.log pkgName + ' found!'
install = (pkgName) ->
download = (pkgName) =>
@pkg pkgName
eventDispatch.on 'packageFound', ->
@pkg.getSource() unless @pkg.getBinary()
eventDispatch.on 'filename', (filename) ->
@pkg.filename = filename
eventDispatch.on 'gotPackage', ->
sha1sum = crypto.createHash 'sha1'
stream = fs.ReadStream @pkg.filename
stream.on 'data', (data) ->
sha1sum.update data
stream.on 'end', ->
digest = sha1sum.digest 'hex'
console.log digest
install = (pkgName) =>
download pkgName
eventDispatch.on 'gotFile', ->
console.log "installing..."
eventDispatch.on 'gotPackage', ->
@pkg.build() unless @pkg.installBinary()
switch action
when "search" then search pkgName, console.log
when "search" then search pkgName
when "download" then download pkgName
when "install" then install pkgName
network = require './network.coffee'
network = require '../network.coffee'
module.exports =
binary_url: "https://dl.dropboxusercontent.com/s/u3cp7mpdyfx99ij/binutils-2.23.2-chromeos-i686.tar.gz?token_hash=AAGsFB9HXNb5tSAm_Wd2GyIUL59BkZYgMTHkj4CkHLxggg&dl=1"
......
network = require './network.coffee'
network = require '../network.coffee'
module.exports =
binary_url: "https://dl.dropboxusercontent.com/s/lo9ks3g7ar3zpfu/mpfr-3.1.2-chromeos-i686.tar.gz?token_hash=AAH1GlLfYtUs4uxl1ayeGTBe8RJ5uTXzOAsXgSlv8G5rrA&dl=1"
binary_sha1: ""
binary_sha1: "763c0228359f99c8a6af5c8b8da628b089eb5451"
getBinary: (callback) ->
network.getFile @binary_url
......@@ -7,6 +7,7 @@ module.exports.getFile = (url) ->
len = parseInt res.headers['content-length'], 10
content_disposition = res.headers['content-disposition']
filename = content_disposition.substring content_disposition.indexOf('"')+1, content_disposition.length-1
eventDispatch.emit 'filename', filename
console.log();
bar = new progressbar ' downloading [:bar] :percent :etas', {
......@@ -21,4 +22,4 @@ module.exports.getFile = (url) ->
bar.tick chunk.length
res.on 'end', ->
eventDispatch.emit 'gotFile'
eventDispatch.emit 'gotPackage'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment