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'
events = require 'events'
global.eventDispatch = new events.EventEmitter
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.parse process.argv
@device = require './device.json'
action = process.argv[2]
pkgName = process.argv[3]
@pkg = (pkgName) ->
eventDispatch.on 'packageFound', ->
@pkg = require './formulas/' + pkgName + '.coffee'
global.pkgVersion = @pkg.version
eventDispatch.on 'packageNotFound', ->
console.log 'package ' + pkgName + ' not found :('
process.exit 1
......@@ -34,7 +41,8 @@ search = (pkgName) =>
download = (pkgName) =>
@pkg pkgName
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) ->
@pkg.filename = filename
eventDispatch.on 'gotPackage', ->
......@@ -42,17 +50,40 @@ download = (pkgName) =>
stream = fs.ReadStream @pkg.filename
stream.on 'data', (data) ->
sha1sum.update data
stream.on 'end', ->
stream.on 'end', =>
digest = sha1sum.digest 'hex'
console.log digest
checksum = @pkg.binary_sha1 or @pkg.source_sha1
eventDispatch.emit 'packageSumOk' unless digest isnt checksum
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
eventDispatch.on 'gotPackage', ->
@pkg.build() unless @pkg.installBinary()
remove = (pkgName) =>
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
when "search" then search pkgName
when "download" then download 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 =
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_sha1: "763c0228359f99c8a6af5c8b8da628b089eb5451"
getBinary: (callback) ->
network.getFile @binary_url
binary_sha1: "ad8a29c21322f245ea0a03045aeb0b07b36cd361"
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