Commit 1a2a3c4e authored by Michał Siwek's avatar Michał Siwek

Implement working install and remove commands

parent e77b6798
...@@ -5,16 +5,23 @@ fs = require 'fs' ...@@ -5,16 +5,23 @@ fs = require 'fs'
events = require 'events' events = require 'events'
global.eventDispatch = new events.EventEmitter global.eventDispatch = new events.EventEmitter
crypto = require 'crypto' crypto = require 'crypto'
tgz = require 'tar.gz'
ncp = require 'ncp'
ncp = ncp.ncp
network = require './network.coffee'
ncp.limit = 16
program.version '0.0.1' program.version '0.0.1'
program.parse process.argv program.parse process.argv
@device = require './device.json'
action = process.argv[2] action = process.argv[2]
pkgName = process.argv[3] pkgName = process.argv[3]
@pkg = (pkgName) -> @pkg = (pkgName) ->
eventDispatch.on 'packageFound', -> eventDispatch.on 'packageFound', ->
@pkg = require './formulas/' + pkgName + '.coffee' @pkg = require './formulas/' + pkgName + '.coffee'
global.pkgVersion = @pkg.version
eventDispatch.on 'packageNotFound', -> eventDispatch.on 'packageNotFound', ->
console.log 'package ' + pkgName + ' not found :(' console.log 'package ' + pkgName + ' not found :('
process.exit 1 process.exit 1
...@@ -34,7 +41,8 @@ search = (pkgName) => ...@@ -34,7 +41,8 @@ search = (pkgName) =>
download = (pkgName) => download = (pkgName) =>
@pkg pkgName @pkg pkgName
eventDispatch.on 'packageFound', -> eventDispatch.on 'packageFound', ->
@pkg.getSource() unless @pkg.getBinary() if @pkg.binary_url then network.getFile @pkg.binary_url else network.getFile @pkg.source_url
eventDispatch.on 'filename', (filename) -> eventDispatch.on 'filename', (filename) ->
@pkg.filename = filename @pkg.filename = filename
eventDispatch.on 'gotPackage', -> eventDispatch.on 'gotPackage', ->
...@@ -42,17 +50,40 @@ download = (pkgName) => ...@@ -42,17 +50,40 @@ download = (pkgName) =>
stream = fs.ReadStream @pkg.filename stream = fs.ReadStream @pkg.filename
stream.on 'data', (data) -> stream.on 'data', (data) ->
sha1sum.update data sha1sum.update data
stream.on 'end', -> stream.on 'end', =>
digest = sha1sum.digest 'hex' digest = sha1sum.digest 'hex'
console.log digest checksum = @pkg.binary_sha1 or @pkg.source_sha1
eventDispatch.emit 'packageSumOk' unless digest isnt checksum
install = (pkgName) => install = (pkgName) =>
eventDispatch.on 'extractedPackage', =>
console.log 'installing package...'
ncp './usr', './xd', (error) =>
@device.installed_packages.push { name: pkgName, version: pkgVersion }
fs.writeFile './device.json', JSON.stringify @device, null, 2
ncp './filelist', './meta/' + pkgName + '.filelist', (error) ->
console.log 'package ' + pkgName + ' installed!' unless error
eventDispatch.on 'packageSumOk', ->
console.log 'extracting archive...'
new tgz().extract './' + @pkg.filename, '.', (error) ->
eventDispatch.emit 'extractedPackage' unless error
download pkgName download pkgName
eventDispatch.on 'gotPackage', -> remove = (pkgName) =>
@pkg.build() unless @pkg.installBinary() fs.readFile './meta/' + pkgName + '.filelist', (error, data) ->
throw error if error
lines = data.toString().split '\n'
fs.unlink '.' + line for line in lines
console.log pkgName + ' removed!'
showStatus = =>
console.log pkg.name + ': ' + pkg.version for pkg in @device.installed_packages
switch action switch action
when "search" then search pkgName when "search" then search pkgName
when "download" then download pkgName when "download" then download pkgName
when "install" then install pkgName when "install" then install pkgName
when "remove" then remove pkgName
when "status" then showStatus()
{
"architecture": "i686",
"installed_packages": [
]
}
network = require '../network.coffee'
module.exports = module.exports =
version: "3.1.2"
binary_url: "https://dl.dropboxusercontent.com/s/lo9ks3g7ar3zpfu/mpfr-3.1.2-chromeos-i686.tar.gz?token_hash=AAH1GlLfYtUs4uxl1ayeGTBe8RJ5uTXzOAsXgSlv8G5rrA&dl=1" binary_url: "https://dl.dropboxusercontent.com/s/lo9ks3g7ar3zpfu/mpfr-3.1.2-chromeos-i686.tar.gz?token_hash=AAH1GlLfYtUs4uxl1ayeGTBe8RJ5uTXzOAsXgSlv8G5rrA&dl=1"
binary_sha1: "763c0228359f99c8a6af5c8b8da628b089eb5451" binary_sha1: "ad8a29c21322f245ea0a03045aeb0b07b36cd361"
getBinary: (callback) ->
network.getFile @binary_url
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