mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
Implement remove and dependencies setting in Ruby
This commit is contained in:
55
cbrew
55
cbrew
@@ -4,6 +4,7 @@ require 'net/http'
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
@command = ARGV[0]
|
@command = ARGV[0]
|
||||||
@pkgName = ARGV[1]
|
@pkgName = ARGV[1]
|
||||||
@@ -30,25 +31,69 @@ def download
|
|||||||
if @pkg.binary_url && @pkg.binary_url.has_key?(@device[:architecture])
|
if @pkg.binary_url && @pkg.binary_url.has_key?(@device[:architecture])
|
||||||
url = @pkg.binary_url[@device[:architecture]]
|
url = @pkg.binary_url[@device[:architecture]]
|
||||||
source = false
|
source = false
|
||||||
|
puts "Precompiled binary available, downloading..."
|
||||||
else
|
else
|
||||||
url = @pkg.source_url
|
url = @pkg.source_url
|
||||||
source = true
|
source = true
|
||||||
|
puts "No precompiled binary available for your platform, downloading source..."
|
||||||
end
|
end
|
||||||
uri = URI.parse url
|
uri = URI.parse url
|
||||||
filename = File.basename(uri.path)
|
filename = File.basename(uri.path)
|
||||||
system('wget', '--content-disposition', url)
|
system('wget', '--content-disposition', url)
|
||||||
abort 'Checksum mismatch, try again' unless Digest::SHA1.hexdigest( File.read("./#{filename}") ) == @pkg.binary_sha1[@device[:architecture]]
|
abort 'Checksum mismatch, try again' unless Digest::SHA1.hexdigest( File.read("./#{filename}") ) == @pkg.binary_sha1[@device[:architecture]]
|
||||||
|
puts "Archive downloaded"
|
||||||
return {source: source, filename: filename}
|
return {source: source, filename: filename}
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
meta = download
|
meta = download
|
||||||
if meta[:source] == true
|
if meta[:source] == true
|
||||||
|
puts "Building from source, this may take a while..."
|
||||||
@pkg.build
|
@pkg.build
|
||||||
|
puts "Installing..."
|
||||||
@pkg.install
|
@pkg.install
|
||||||
else#if meta[:source] == false
|
else
|
||||||
|
puts "Unpacking archive, this may take a while..."
|
||||||
system "tar", "zxf", meta[:filename]
|
system "tar", "zxf", meta[:filename]
|
||||||
|
puts "Installing..."
|
||||||
|
FileUtils.mv './usr', './xd'
|
||||||
|
FileUtils.mv './dlist', "./meta/#{@pkgName}.directorylist"
|
||||||
|
FileUtils.mv './filelist', "./meta/#{@pkgName}.filelist"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#add to installed packages
|
||||||
|
@device[:installed_packages].push(name: @pkgName, version: @pkg.version)
|
||||||
|
File.open('./device.json', 'w') do |file|
|
||||||
|
output = JSON.parse @device.to_json
|
||||||
|
file.write JSON.pretty_generate(output)
|
||||||
|
end
|
||||||
|
puts "#{@pkgName.capitalize} installed!"
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove
|
||||||
|
File.open("./meta/#{@pkgName}.filelist").each_line do |line|
|
||||||
|
File.unlink '.' + line.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
File.readlines("./meta/#{@pkgName}.directorylist").reverse.each do |line|
|
||||||
|
begin
|
||||||
|
Dir.rmdir '.' + line.chomp
|
||||||
|
rescue => exception #swallow exception
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
File.unlink "./meta/#{@pkgName}.filelist"
|
||||||
|
File.unlink "./meta/#{@pkgName}.directorylist"
|
||||||
|
|
||||||
|
#remove from installed packages
|
||||||
|
@device[:installed_packages].each do |elem|
|
||||||
|
@device[:installed_packages].delete elem if elem[:name] == @pkgName
|
||||||
|
end
|
||||||
|
File.open('./device.json', 'w') do |file|
|
||||||
|
out = JSON.parse @device.to_json
|
||||||
|
file.write JSON.pretty_generate(out)
|
||||||
|
end
|
||||||
|
puts "#{@pkgName.capitalize} removed!"
|
||||||
end
|
end
|
||||||
|
|
||||||
case @command
|
case @command
|
||||||
@@ -60,6 +105,14 @@ when "download"
|
|||||||
when "install"
|
when "install"
|
||||||
search @pkgName
|
search @pkgName
|
||||||
install
|
install
|
||||||
|
when "remove"
|
||||||
|
search @pkgName
|
||||||
|
remove
|
||||||
|
when nil
|
||||||
|
puts "Chromebrew, version 0.1"
|
||||||
|
puts "Usage: cbrew [command] [package]"
|
||||||
|
puts "Available commands: search, download, install, remove"
|
||||||
else
|
else
|
||||||
puts "I have no idea how to do #{@command} :("
|
puts "I have no idea how to do #{@command} :("
|
||||||
|
puts "Available commands: search, download, install, remove"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"architecture": "i686",
|
"architecture": "i686",
|
||||||
"installed_packages": [
|
"installed_packages": [
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -2,4 +2,15 @@ require './lib/package_helpers'
|
|||||||
|
|
||||||
class Package
|
class Package
|
||||||
property :version, :binary_url, :binary_sha1, :source_url
|
property :version, :binary_url, :binary_sha1, :source_url
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_reader :dependencies
|
||||||
|
end
|
||||||
|
def self.depends_on (dependency = nil)
|
||||||
|
@dependencies = [] unless @dependencies
|
||||||
|
if dependency
|
||||||
|
@dependencies << dependency
|
||||||
|
end
|
||||||
|
@dependencies
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,5 +8,4 @@ class Binutils < Package
|
|||||||
binary_sha1 ({
|
binary_sha1 ({
|
||||||
i686: 'a7edc9bdaf9fc72112fe6b370f158a9a1aee87ac'
|
i686: 'a7edc9bdaf9fc72112fe6b370f158a9a1aee87ac'
|
||||||
})
|
})
|
||||||
source_url "http://xd.xd/"
|
|
||||||
end
|
end
|
||||||
|
|||||||
5
test.rb
5
test.rb
@@ -1,11 +1,10 @@
|
|||||||
require './packages/binutils'
|
require './packages/binutils'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'pathname'
|
||||||
|
|
||||||
@device = JSON.parse(File.read('./device.json'), symbolize_names: true)
|
@device = JSON.parse(File.read('./device.json'), symbolize_names: true)
|
||||||
@device.each do |key, elem|
|
@device.each do |key, elem|
|
||||||
@device[key] = @device[key].to_sym rescue @device[key]
|
@device[key] = @device[key].to_sym rescue @device[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
Binutils.version
|
Binutils.dependencies
|
||||||
Binutils.binary_url[@device[:architecture]]
|
|
||||||
Binutils.binary_sha1[:i686]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user