mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-08 23:18:10 -05:00
Beign rewriting everything in Ruby :p
This commit is contained in:
65
cbrew
Executable file
65
cbrew
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'find'
|
||||
require 'net/http'
|
||||
require 'uri'
|
||||
require 'digest/sha1'
|
||||
require 'json'
|
||||
|
||||
@command = ARGV[0]
|
||||
@pkgName = ARGV[1]
|
||||
|
||||
@device = JSON.parse(File.read('./device.json'), symbolize_names: true)
|
||||
@device.each do |key, elem| #symbolize also values
|
||||
@device[key] = @device[key].to_sym rescue @device[key]
|
||||
end
|
||||
|
||||
def setPkg
|
||||
require './packages/' + @pkgName
|
||||
@pkg = Object.const_get(@pkgName.capitalize)
|
||||
puts "Found #{@pkgName}, version #{@pkg.version}"
|
||||
end
|
||||
|
||||
def search (pkgName)
|
||||
Find.find ('packages') do |filename|
|
||||
return setPkg if filename == 'packages/' + pkgName + '.rb'
|
||||
end
|
||||
puts "package #{pkgName} not found :("
|
||||
end
|
||||
|
||||
def download
|
||||
if @pkg.binary_url && @pkg.binary_url.has_key?(@device[:architecture])
|
||||
url = @pkg.binary_url[@device[:architecture]]
|
||||
source = false
|
||||
else
|
||||
url = @pkg.source_url
|
||||
source = true
|
||||
end
|
||||
uri = URI.parse url
|
||||
filename = File.basename(uri.path)
|
||||
system('wget', '--content-disposition', url)
|
||||
abort 'Checksum mismatch, try again' unless Digest::SHA1.hexdigest( File.read("./#{filename}") ) == @pkg.binary_sha1[@device[:architecture]]
|
||||
return {source: source, filename: filename}
|
||||
end
|
||||
|
||||
def install
|
||||
meta = download
|
||||
if meta[:source] == true
|
||||
@pkg.build
|
||||
@pkg.install
|
||||
else#if meta[:source] == false
|
||||
system "tar", "zxf", meta[:filename]
|
||||
end
|
||||
end
|
||||
|
||||
case @command
|
||||
when "search"
|
||||
search @pkgName
|
||||
when "download"
|
||||
search @pkgName
|
||||
download
|
||||
when "install"
|
||||
search @pkgName
|
||||
install
|
||||
else
|
||||
puts "I have no idea how to do #{@command} :("
|
||||
end
|
||||
105
cbrew.coffee
105
cbrew.coffee
@@ -1,105 +0,0 @@
|
||||
#!/usr/local/bin/coffee
|
||||
|
||||
program = require 'commander'
|
||||
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
|
||||
|
||||
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'
|
||||
|
||||
search = (pkgName) =>
|
||||
@pkg pkgName
|
||||
eventDispatch.on 'packageFound', ->
|
||||
console.log pkgName + ' found!'
|
||||
|
||||
download = (pkgName) =>
|
||||
@pkg pkgName
|
||||
eventDispatch.on 'packageFound', ->
|
||||
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', ->
|
||||
sha1sum = crypto.createHash 'sha1'
|
||||
stream = fs.ReadStream @pkg.filename
|
||||
stream.on 'data', (data) ->
|
||||
sha1sum.update data
|
||||
stream.on 'end', =>
|
||||
digest = sha1sum.digest 'hex'
|
||||
checksum = @pkg.binary_sha1 or @pkg.source_sha1
|
||||
eventDispatch.emit 'packageSumOk' unless digest isnt checksum
|
||||
|
||||
install = (pkgName) =>
|
||||
eventDispatch.on 'extractedPackage', =>
|
||||
console.log 'installing package...'
|
||||
fs.rename './usr', './xd', =>
|
||||
@device.installed_packages.push { name: pkgName, version: pkgVersion }
|
||||
fs.writeFile './device.json', JSON.stringify @device, null, 2
|
||||
fs.rename './dlist', './meta/' + pkgName + '.directorylist'
|
||||
fs.rename './filelist', './meta/' + pkgName + '.filelist', ->
|
||||
console.log 'package ' + pkgName + ' installed!'
|
||||
|
||||
eventDispatch.on 'packageSumOk', ->
|
||||
console.log 'extracting archive...'
|
||||
new tgz().extract './' + @pkg.filename, '.', (error) =>
|
||||
eventDispatch.emit 'extractedPackage' unless error
|
||||
fs.unlink './' + @pkg.filename, (error) ->
|
||||
throw error if error
|
||||
|
||||
download pkgName
|
||||
|
||||
remove = (pkgName) =>
|
||||
fs.readFile './meta/' + pkgName + '.filelist', (error, data) =>
|
||||
throw error if error
|
||||
filelist_lines = data.toString().split '\n'
|
||||
for line in filelist_lines
|
||||
unless not line
|
||||
fs.unlink '.' + line, (error) ->
|
||||
throw error if error
|
||||
fs.readFile './meta/' + pkgName + '.directorylist', (error, data) ->
|
||||
throw error if error
|
||||
directorylist_lines = data.toString().split '\n'
|
||||
for line in directorylist_lines.reverse()
|
||||
unless not line
|
||||
fs.rmdirSync '.' + line
|
||||
@device.installed_packages = @device.installed_packages.filter (pkg) -> pkg.name isnt pkgName
|
||||
fs.writeFileSync './device.json', JSON.stringify @device, null, 2
|
||||
fs.unlink './meta/' + pkgName + '.filelist'
|
||||
fs.unlink './meta/' + pkgName + '.directorylist'
|
||||
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()
|
||||
6
device.json
Normal file
6
device.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"architecture": "i686",
|
||||
"installed_packages": [
|
||||
|
||||
]
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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"
|
||||
binary_sha1: ""
|
||||
|
||||
binary_install: ->
|
||||
|
||||
getBinary: ->
|
||||
network.getFile @binary_url
|
||||
|
||||
build: ->
|
||||
system './configure'
|
||||
system 'make'
|
||||
|
||||
install: ->
|
||||
system 'make install'
|
||||
5
lib/package.rb
Normal file
5
lib/package.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require './lib/package_helpers'
|
||||
|
||||
class Package
|
||||
property :version, :binary_url, :binary_sha1, :source_url
|
||||
end
|
||||
5
lib/package_helpers.rb
Normal file
5
lib/package_helpers.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
def property(*properties)
|
||||
properties.each do |prop|
|
||||
self.class_eval("def self.#{prop}(#{prop} = nil); @#{prop} = #{prop} if #{prop}; @#{prop}; end")
|
||||
end
|
||||
end
|
||||
@@ -1,25 +0,0 @@
|
||||
https = require 'https'
|
||||
progressbar = require 'progress'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports.getFile = (url) ->
|
||||
https.get url, (res) ->
|
||||
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', {
|
||||
complete: '='
|
||||
incomplete: ' '
|
||||
width: 20
|
||||
total: len
|
||||
}
|
||||
|
||||
res.on 'data', (chunk) ->
|
||||
fs.appendFileSync filename, chunk
|
||||
bar.tick chunk.length
|
||||
|
||||
res.on 'end', ->
|
||||
eventDispatch.emit 'gotPackage'
|
||||
4
packages/binutils.coffee
Normal file
4
packages/binutils.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports =
|
||||
version: "2.23.2"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/u3cp7mpdyfx99ij/binutils-2.23.2-chromeos-i686.tar.gz?token_hash=AAGsFB9HXNb5tSAm_Wd2GyIUL59BkZYgMTHkj4CkHLxggg&dl=1"
|
||||
binary_sha1: "a7edc9bdaf9fc72112fe6b370f158a9a1aee87ac"
|
||||
12
packages/binutils.rb
Normal file
12
packages/binutils.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require './lib/package'
|
||||
|
||||
class Binutils < Package
|
||||
version '2.12'
|
||||
binary_url ({
|
||||
i686: 'https://dl.dropboxusercontent.com/s/u3cp7mpdyfx99ij/binutils-2.23.2-chromeos-i686.tar.gz?token_hash=AAGsFB9HXNb5tSAm_Wd2GyIUL59BkZYgMTHkj4CkHLxggg&dl=1'
|
||||
})
|
||||
binary_sha1 ({
|
||||
i686: 'a7edc9bdaf9fc72112fe6b370f158a9a1aee87ac'
|
||||
})
|
||||
source_url "http://xd.xd/"
|
||||
end
|
||||
10
packages/gcc.coffee
Normal file
10
packages/gcc.coffee
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports =
|
||||
version: "4.8.1-baseline"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/c06pcge8ogsqfcd/gcc-4.8.1-baseline-chromeos-i686.tar.gz?token_hash=AAFLnE_8iL_lAnGtAAVM5G_sYqejA44jGW8D9r0a8xCjrQ&dl=1"
|
||||
binary_sha1: "d720c9a804d26728d730b93748072ffa6df7ee3d"
|
||||
dependencies: [
|
||||
"binutils"
|
||||
"gmp"
|
||||
"mpc"
|
||||
"mpfr"
|
||||
]
|
||||
4
packages/glibc.coffee
Normal file
4
packages/glibc.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports =
|
||||
version: "2.17.90-baseline"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/dic47f8eqxhpf89/glibc-2.17.90-baseline-chromeos-i686.tar.gz?token_hash=AAHx_77YtWLLnkjCJRaCJt7RsdKrfkT6lgKS9BZc4O-0Pg&dl=1"
|
||||
binary_sha1: "defebdeeafd71c40193debf3b786938399ece844"
|
||||
4
packages/gmp.coffee
Normal file
4
packages/gmp.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports =
|
||||
version: "5.1.2"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/9cwila1kaomsyl2/gmp-5.1.2-chromeos-i686.tar.gz?token_hash=AAHO9VxBpvXU2GPWBwimsp4hL8DADIItfNnIaFbfcyynMg&dl=1"
|
||||
binary_sha1: "b03b9508463588bfe9d09303c0725068cddd8810"
|
||||
4
packages/linux-headers.coffee
Normal file
4
packages/linux-headers.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports =
|
||||
version: "3.4.0"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/mdzdoyq7dtnz682/linux-headers-3.4.0-chromeos-i686.tar.gz?token_hash=AAE4yw5oH_SfZ3lAx02mFP603rnjmoB9Gp4vqTY14NsA-A&dl=1"
|
||||
binary_sha1: "31c933f3a4e82fd9310b0f5b32d79c9a51514fee"
|
||||
4
packages/make.coffee
Normal file
4
packages/make.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports =
|
||||
version: "3.82"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/f6pg4bkg6m3vn7q/make-3.82-chromeos-i686.tar.gz?token_hash=AAHP__I3leN8BCLdP0pLbkNopoFGGhDuKX0sN-I6Zx4JYg&dl=1"
|
||||
binary_sha1: "86321098f3f31daa49abb1bb38045dffb1f168b4"
|
||||
8
packages/mpc.coffee
Normal file
8
packages/mpc.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports =
|
||||
version: "1.0.1"
|
||||
binary_url: "https://dl.dropboxusercontent.com/s/3o6uc8n4uy3oved/mpc-1.0.1-chromeos-i686.tar.gz?token_hash=AAH_OlvQWGUF7lyFhV3DXXgYRM1fupgKoHIwyiVmmVyWUQ&dl=1"
|
||||
binary_sha1: "86321098f3f31daa49abb1bb38045dffb1f168b4"
|
||||
dependencies: [
|
||||
"mpfr"
|
||||
"gmp"
|
||||
]
|
||||
11
test.rb
Normal file
11
test.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require './packages/binutils'
|
||||
require 'json'
|
||||
|
||||
@device = JSON.parse(File.read('./device.json'), symbolize_names: true)
|
||||
@device.each do |key, elem|
|
||||
@device[key] = @device[key].to_sym rescue @device[key]
|
||||
end
|
||||
|
||||
Binutils.version
|
||||
Binutils.binary_url[@device[:architecture]]
|
||||
Binutils.binary_sha1[:i686]
|
||||
Reference in New Issue
Block a user