Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
chromebrew
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
chromebrew
Commits
65e80514
Commit
65e80514
authored
Sep 01, 2013
by
Michał Siwek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement remove and dependencies setting in Ruby
parent
3661071c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
7 deletions
+69
-7
cbrew
cbrew
+54
-1
device.json
device.json
+2
-2
lib/package.rb
lib/package.rb
+11
-0
packages/binutils.rb
packages/binutils.rb
+0
-1
test.rb
test.rb
+2
-3
No files found.
cbrew
View file @
65e80514
...
...
@@ -4,6 +4,7 @@ require 'net/http'
require
'uri'
require
'digest/sha1'
require
'json'
require
'fileutils'
@command
=
ARGV
[
0
]
@pkgName
=
ARGV
[
1
]
...
...
@@ -30,25 +31,69 @@ def download
if
@pkg
.
binary_url
&&
@pkg
.
binary_url
.
has_key?
(
@device
[
:architecture
])
url
=
@pkg
.
binary_url
[
@device
[
:architecture
]]
source
=
false
puts
"Precompiled binary available, downloading..."
else
url
=
@pkg
.
source_url
source
=
true
puts
"No precompiled binary available for your platform, downloading source..."
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
]]
puts
"Archive downloaded"
return
{
source:
source
,
filename:
filename
}
end
def
install
meta
=
download
if
meta
[
:source
]
==
true
puts
"Building from source, this may take a while..."
@pkg
.
build
puts
"Installing..."
@pkg
.
install
else
#if meta[:source] == false
else
puts
"Unpacking archive, this may take a while..."
system
"tar"
,
"zxf"
,
meta
[
:filename
]
puts
"Installing..."
FileUtils
.
mv
'./usr'
,
'./xd'
FileUtils
.
mv
'./dlist'
,
"./meta/
#{
@pkgName
}
.directorylist"
FileUtils
.
mv
'./filelist'
,
"./meta/
#{
@pkgName
}
.filelist"
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
case
@command
...
...
@@ -60,6 +105,14 @@ when "download"
when
"install"
search
@pkgName
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
puts
"I have no idea how to do
#{
@command
}
:("
puts
"Available commands: search, download, install, remove"
end
device.json
View file @
65e80514
{
"architecture"
:
"i686"
,
"installed_packages"
:
[
]
}
}
\ No newline at end of file
lib/package.rb
View file @
65e80514
...
...
@@ -2,4 +2,15 @@ require './lib/package_helpers'
class
Package
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
packages/binutils.rb
View file @
65e80514
...
...
@@ -8,5 +8,4 @@ class Binutils < Package
binary_sha1
({
i686:
'a7edc9bdaf9fc72112fe6b370f158a9a1aee87ac'
})
source_url
"http://xd.xd/"
end
test.rb
View file @
65e80514
require
'./packages/binutils'
require
'json'
require
'pathname'
@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
]
Binutils
.
dependencies
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment