smc-get 0.2.0.beta1 → 0.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +674 -674
- data/HISTORY.rdoc +53 -31
- data/README.rdoc +162 -162
- data/VERSION.txt +1 -1
- data/bin/smc-checksum +44 -44
- data/bin/smc-checksum~ +2 -0
- data/bin/smc-get +31 -31
- data/bin/smc-repo-conv +205 -0
- data/bin/smc-repo-conv~ +155 -0
- data/config/smc-get.yml +32 -32
- data/config/smc-get.yml~ +32 -0
- data/lib/smc_get.rb +22 -22
- data/lib/smc_get/cui.rb +325 -325
- data/lib/smc_get/cui_commands/build.rb +297 -329
- data/lib/smc_get/cui_commands/command.rb +181 -117
- data/lib/smc_get/cui_commands/getinfo.rb +91 -91
- data/lib/smc_get/cui_commands/help.rb +64 -64
- data/lib/smc_get/cui_commands/install.rb +101 -101
- data/lib/smc_get/cui_commands/list.rb +101 -101
- data/lib/smc_get/cui_commands/search.rb +106 -106
- data/lib/smc_get/cui_commands/server.rb +76 -0
- data/lib/smc_get/cui_commands/uninstall.rb +77 -80
- data/lib/smc_get/cui_commands/update.rb +107 -119
- data/lib/smc_get/cui_commands/version.rb +57 -57
- data/lib/smc_get/errors.rb +166 -140
- data/lib/smc_get/gui.rb +19 -19
- data/lib/smc_get/local_repository.rb +290 -277
- data/lib/smc_get/package.rb +240 -260
- data/lib/smc_get/package_archive.rb +186 -80
- data/lib/smc_get/package_specification.rb +257 -253
- data/lib/smc_get/remote_repository.rb +272 -272
- data/lib/smc_get/repository.rb +9 -9
- data/lib/smc_get/smc_get.rb +118 -117
- data/smcpak.rdoc +331 -331
- data/test/test_smc-get-cui.rb +122 -122
- data/test/test_smc-get-lib.rb +171 -171
- metadata +25 -22
data/HISTORY.rdoc
CHANGED
@@ -1,31 +1,53 @@
|
|
1
|
-
This file documents the the changes that have been made
|
2
|
-
to smc-get between versions. It's *not* intended to serve
|
3
|
-
as a full-blown changelog, for this you have to install git
|
4
|
-
and issue a <tt>git log</tt> command in the project directory.
|
5
|
-
|
6
|
-
Bugfixes are written in <i>italic</i>, mayor changes in <b>bold</b> font.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
*
|
14
|
-
|
15
|
-
*
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
* <b>Added <tt>smc-get
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
This file documents the the changes that have been made
|
2
|
+
to smc-get between versions. It's *not* intended to serve
|
3
|
+
as a full-blown changelog, for this you have to install git
|
4
|
+
and issue a <tt>git log</tt> command in the project directory.
|
5
|
+
|
6
|
+
Bugfixes are written in <i>italic</i>, mayor changes in <b>bold</b> font.
|
7
|
+
If a change is related to a ticket
|
8
|
+
{on our issue tracker}[https://github.com/Luiji/smc-get/issues],
|
9
|
+
the corresponding ticket is given in square brackets [ and ].
|
10
|
+
|
11
|
+
== 0.3.0-beta1
|
12
|
+
|
13
|
+
* Lots of smaller fixes and internal code improvements
|
14
|
+
* We have a working default repository now!
|
15
|
+
* Check specs for validness before they're installed
|
16
|
+
* <i>Fixed a problem with <tt>smc-get uninstall</tt> not removing
|
17
|
+
directories.</i>
|
18
|
+
* <b>Added the <tt>server</tt> command to <tt>smc-get</tt>.
|
19
|
+
* Experimental script for converting Luiji's GitHub repo to the new
|
20
|
+
SMCPAK format.
|
21
|
+
* <b>Added --local option to <tt>smc-get install</tt> for installing local
|
22
|
+
package files.</b>
|
23
|
+
|
24
|
+
== 0.2.0-beta2
|
25
|
+
|
26
|
+
* <i>Fixed world handling in packages [#4]</i>
|
27
|
+
* <i>Added missing dependency tracking [#3]</i>
|
28
|
+
* <i>Fixed startup crash on permission error.</i>
|
29
|
+
|
30
|
+
== 0.2.0-beta1
|
31
|
+
|
32
|
+
* <b>Added a completely new SMC package format: smcpak. These are XZ-compressed
|
33
|
+
tarballs allowing for easy deployment of packages. See the smcpak.rdoc file
|
34
|
+
for further information.</b>
|
35
|
+
* <b>Rewrote nearly the full API. This release is 100%
|
36
|
+
incompatible with anything released so far.</b>
|
37
|
+
* <b>New classes LocalRepository and RemoteRepository for
|
38
|
+
managing downloads and installations.</b>
|
39
|
+
* <b><tt>smc-get list</tt> without arguments works a little different now.
|
40
|
+
Instead of showing the installation time of a package it now shows the
|
41
|
+
time of the last update, which allows you to better keep track of
|
42
|
+
what is out of date.</b>
|
43
|
+
* <b>Added <tt>smc-get update</tt> for a fully automated update of all (or
|
44
|
+
selected) installed packages.</b>
|
45
|
+
* <b>Added <tt>smc-get build</tt> to automatically build SMC packages either
|
46
|
+
interactively or as an automated process.</b>
|
47
|
+
* Added modification detection via SHA1 checksums.
|
48
|
+
* New dependency on the {ruby-xz gem}[http://rubygems.org/gems/ruby-xz].
|
49
|
+
* New dependency on the {minitar gem}[http://rubygems.org/gems/minitar].
|
50
|
+
* New dependency on liblzma[http://tukaani.org/xz/].
|
51
|
+
* Official bugtracker is now at GitHub: https://github.com/Luiji/smc-get/issues.
|
52
|
+
* Added this file (HISTORY.rdoc) for collecting change information.
|
53
|
+
|
data/README.rdoc
CHANGED
@@ -1,163 +1,163 @@
|
|
1
|
-
= SMC-GET -- level repository manager for Secret Maryo Chronicles
|
2
|
-
smc-get - Library and command-line for managing SMC level packages.
|
3
|
-
|
4
|
-
Author:: Luiji Maryo (mailto:luiji@users.sourceforge.net)
|
5
|
-
Contributor:: Marvin Gülker (mailto:sutniuq@gmx.net)
|
6
|
-
Copyright:: Copyright (C) 2010-2011 Entertaining Software, Inc.
|
7
|
-
Copyright:: Copyright (C) 2011 Marvin Gülker
|
8
|
-
License:: GNU General Public License (see COPYING)
|
9
|
-
|
10
|
-
= Synopsis for use as a command-line tool
|
11
|
-
smc-get install mypackage
|
12
|
-
smc-get uninstall mypackage
|
13
|
-
smc-get help
|
14
|
-
|
15
|
-
= Synopsis for use as a library
|
16
|
-
require 'smc_get'
|
17
|
-
# Initialize the library
|
18
|
-
SmcGet.setup
|
19
|
-
|
20
|
-
# Bind to local and remote repositories
|
21
|
-
rr = SmcGet::RemoteRepository.new("http://example.org/smc-repo")
|
22
|
-
lr = SmcGet::LocalRepository.new("/usr/share/smc")
|
23
|
-
|
24
|
-
# Get a package
|
25
|
-
path = rr.fetch_package("mypackage")
|
26
|
-
pkg = SmcGet::Package.from_file(pkg)
|
27
|
-
|
28
|
-
# Install it!
|
29
|
-
lr.install(pkg)
|
30
|
-
|
31
|
-
#...or remove it.
|
32
|
-
lr.uninstall("mypackage")
|
33
|
-
|
34
|
-
= Description
|
35
|
-
smc-get is a library and command-line tool for installing, uninstalling, etc.
|
36
|
-
level packages from the Secret Maryo Chronicles Contributed Levels Repository.
|
37
|
-
|
38
|
-
== Prototype Notice
|
39
|
-
|
40
|
-
This program is a prototype for functionality that will eventually be merged
|
41
|
-
with Secret Maryo Chronicles. It is subject to change and should not be used
|
42
|
-
for anything other then testing.
|
43
|
-
|
44
|
-
= Usage
|
45
|
-
|
46
|
-
== Using it as a command-line
|
47
|
-
smc-get's main purpose is to be used as a command-line utility. It should be
|
48
|
-
executed in the syntax:
|
49
|
-
smc-get COMMAND [PARAMETERS...]
|
50
|
-
Where <tt>COMMAND</tt> is the command and <tt>PARAMATERS...</tt> are the
|
51
|
-
parameters for that command.
|
52
|
-
|
53
|
-
To get help on the various commands, use the help command.
|
54
|
-
smc-get help [COMMAND]
|
55
|
-
Ommit the +COMMAND+ if you want general usage information.
|
56
|
-
|
57
|
-
=== Configuration file
|
58
|
-
smc-get requires a configuration file when used as a commandline tool.
|
59
|
-
By default it searches for <tt>smc-get.yml</tt> in the <b>config/</b>
|
60
|
-
subdirectory of your smc-get installation, then for <tt>smc-get-conf.yml</tt>
|
61
|
-
in the user's home directory and then for the file specified via the <tt>-c</tt>
|
62
|
-
commandline switch, if existant. Values set in later evaluated configuration
|
63
|
-
files override those in prevously evaluated ones; see
|
64
|
-
smc-get help
|
65
|
-
for more explanation. If you want to use the CUI from your scripts, you
|
66
|
-
can specify a config file via <tt>-c</tt>, but make sure it contains all
|
67
|
-
possible options, otherwise those in the global or user-level config files
|
68
|
-
may affect your program. See below for an example.
|
69
|
-
|
70
|
-
Be careful when using +sudo+, because it changes the environment variables.
|
71
|
-
smc-get may not find your user-level configuration file when using sudo,
|
72
|
-
because it derives the path from the +USER+ environment variable which may
|
73
|
-
get set to +root+ when using +sudo+.
|
74
|
-
|
75
|
-
In the configuration file you can set some general options, look into
|
76
|
-
the file which is quite self-explanatory. A sample configuration may
|
77
|
-
look like this:
|
78
|
-
data_directory: "/usr/local/share/smc"
|
79
|
-
repo_url: "ftp://ftp.example.org/smc
|
80
|
-
|
81
|
-
== Using it as a library
|
82
|
-
smc-get, although mainly targetted at being a command-line utility, may also be
|
83
|
-
used as a library. This is useful when, for instance, creating a GUI front-end.
|
84
|
-
|
85
|
-
To initialize the library, call SmcGet.setup which will do some basic initialization
|
86
|
-
needed for use of the library.
|
87
|
-
SmcGet.setup
|
88
|
-
For interacting with the SMC repository, smc-get exposes an object-oriented API
|
89
|
-
centered around the Package and repository classes. Before you can do anything,
|
90
|
-
you have to "establish" connections to a remote and a local repository, where
|
91
|
-
remote repositories are repositories where <tt>smc-get</tt> downloads from,
|
92
|
-
and local repositories are repositories where <tt>smc-get</tt> installs
|
93
|
-
into, i.e. usually your SMC installation. You can use multiple repositories
|
94
|
-
if you know how to manage it.
|
95
|
-
|
96
|
-
rr = SmcGet::RemoteRepository.new("http://example.org/smc-repo")
|
97
|
-
lr = SmcGet::LocalRepository.new("/usr/local/share/smc")
|
98
|
-
|
99
|
-
After you initialized the library
|
100
|
-
as explained above, you can query, install and uninstall packages.
|
101
|
-
|
102
|
-
path = rr.fetch_package("mypackage")
|
103
|
-
pkg = SmcGet::Package.from_file(path)
|
104
|
-
lr.install(pkg)
|
105
|
-
|
106
|
-
If any of the methods fails, it will raise various exceptions. When creating a GUI,
|
107
|
-
you should catch these exceptions and present them as message boxes.
|
108
|
-
|
109
|
-
begin
|
110
|
-
rr.fetch_package("mypackage")
|
111
|
-
rescue SmcGet::Errors::NoSuchPackageError => e
|
112
|
-
alert "No such package: #{e.package_name}!"
|
113
|
-
end
|
114
|
-
|
115
|
-
All errors smc-get raises are subclasses of SmcGet::Errors::SmcGetError. That
|
116
|
-
means, if you rescue from this exception, you can handle all package-related
|
117
|
-
errors at once:
|
118
|
-
|
119
|
-
begin
|
120
|
-
lr.install(pkg)
|
121
|
-
rescue SmcGet::Errors::SmcGetError => e
|
122
|
-
alert e.message
|
123
|
-
end
|
124
|
-
|
125
|
-
Furthermore, these error messages should have a pretty informative message set,
|
126
|
-
so unless you want to localize the error messages you can just reach them
|
127
|
-
through (the messages, not the whole exceptions, of course).
|
128
|
-
|
129
|
-
The configuration file only contains settings for the commandline user
|
130
|
-
interface, so you don't need it here. If you want to use the CUI from
|
131
|
-
your scripts, do
|
132
|
-
require "smc_get"
|
133
|
-
require "smc_get/cui"
|
134
|
-
|
135
|
-
cui = SmcGet::CUI.new(ARGV)
|
136
|
-
cui.start
|
137
|
-
The configuration file from the <b>config/</b> directory will automatically
|
138
|
-
be loaded as well as the user-level configuration file; you may specify another
|
139
|
-
configuration file by placing the appropriate option in ARGV:
|
140
|
-
ARGV.unshift("-c")
|
141
|
-
ARGV.unshift("YOURCONFIGFILE.yml")
|
142
|
-
|
143
|
-
cui = SmcGet::CUI.new(ARGV)
|
144
|
-
cui.start
|
145
|
-
|
146
|
-
= License
|
147
|
-
|
148
|
-
smc-get is licensed under the GNU General Public License version 3 or later. For
|
149
|
-
more information, see COPYING.
|
150
|
-
|
151
|
-
= Website
|
152
|
-
|
153
|
-
This software was written by Entertaining Software, Inc. Visit us at
|
154
|
-
http://www.entertainingsoftware.com.
|
155
|
-
|
156
|
-
This software is hosted at GitHub. The project page can be found at
|
157
|
-
https://github.com/Luiji/smc-get.
|
158
|
-
|
159
|
-
This software was written for Secret Maryo Chronicles. Visit them at
|
160
|
-
http://www.secretmaryo.org.
|
161
|
-
|
162
|
-
Bugs related to this software may be reported at
|
1
|
+
= SMC-GET -- level repository manager for Secret Maryo Chronicles
|
2
|
+
smc-get - Library and command-line for managing SMC level packages.
|
3
|
+
|
4
|
+
Author:: Luiji Maryo (mailto:luiji@users.sourceforge.net)
|
5
|
+
Contributor:: Marvin Gülker (mailto:sutniuq@gmx.net)
|
6
|
+
Copyright:: Copyright (C) 2010-2011 Entertaining Software, Inc.
|
7
|
+
Copyright:: Copyright (C) 2011 Marvin Gülker
|
8
|
+
License:: GNU General Public License (see COPYING)
|
9
|
+
|
10
|
+
= Synopsis for use as a command-line tool
|
11
|
+
smc-get install mypackage
|
12
|
+
smc-get uninstall mypackage
|
13
|
+
smc-get help
|
14
|
+
|
15
|
+
= Synopsis for use as a library
|
16
|
+
require 'smc_get'
|
17
|
+
# Initialize the library
|
18
|
+
SmcGet.setup
|
19
|
+
|
20
|
+
# Bind to local and remote repositories
|
21
|
+
rr = SmcGet::RemoteRepository.new("http://example.org/smc-repo")
|
22
|
+
lr = SmcGet::LocalRepository.new("/usr/share/smc")
|
23
|
+
|
24
|
+
# Get a package
|
25
|
+
path = rr.fetch_package("mypackage")
|
26
|
+
pkg = SmcGet::Package.from_file(pkg)
|
27
|
+
|
28
|
+
# Install it!
|
29
|
+
lr.install(pkg)
|
30
|
+
|
31
|
+
#...or remove it.
|
32
|
+
lr.uninstall("mypackage")
|
33
|
+
|
34
|
+
= Description
|
35
|
+
smc-get is a library and command-line tool for installing, uninstalling, etc.
|
36
|
+
level packages from the Secret Maryo Chronicles Contributed Levels Repository.
|
37
|
+
|
38
|
+
== Prototype Notice
|
39
|
+
|
40
|
+
This program is a prototype for functionality that will eventually be merged
|
41
|
+
with Secret Maryo Chronicles. It is subject to change and should not be used
|
42
|
+
for anything other then testing.
|
43
|
+
|
44
|
+
= Usage
|
45
|
+
|
46
|
+
== Using it as a command-line
|
47
|
+
smc-get's main purpose is to be used as a command-line utility. It should be
|
48
|
+
executed in the syntax:
|
49
|
+
smc-get COMMAND [PARAMETERS...]
|
50
|
+
Where <tt>COMMAND</tt> is the command and <tt>PARAMATERS...</tt> are the
|
51
|
+
parameters for that command.
|
52
|
+
|
53
|
+
To get help on the various commands, use the help command.
|
54
|
+
smc-get help [COMMAND]
|
55
|
+
Ommit the +COMMAND+ if you want general usage information.
|
56
|
+
|
57
|
+
=== Configuration file
|
58
|
+
smc-get requires a configuration file when used as a commandline tool.
|
59
|
+
By default it searches for <tt>smc-get.yml</tt> in the <b>config/</b>
|
60
|
+
subdirectory of your smc-get installation, then for <tt>smc-get-conf.yml</tt>
|
61
|
+
in the user's home directory and then for the file specified via the <tt>-c</tt>
|
62
|
+
commandline switch, if existant. Values set in later evaluated configuration
|
63
|
+
files override those in prevously evaluated ones; see
|
64
|
+
smc-get help
|
65
|
+
for more explanation. If you want to use the CUI from your scripts, you
|
66
|
+
can specify a config file via <tt>-c</tt>, but make sure it contains all
|
67
|
+
possible options, otherwise those in the global or user-level config files
|
68
|
+
may affect your program. See below for an example.
|
69
|
+
|
70
|
+
Be careful when using +sudo+, because it changes the environment variables.
|
71
|
+
smc-get may not find your user-level configuration file when using sudo,
|
72
|
+
because it derives the path from the +USER+ environment variable which may
|
73
|
+
get set to +root+ when using +sudo+.
|
74
|
+
|
75
|
+
In the configuration file you can set some general options, look into
|
76
|
+
the file which is quite self-explanatory. A sample configuration may
|
77
|
+
look like this:
|
78
|
+
data_directory: "/usr/local/share/smc"
|
79
|
+
repo_url: "ftp://ftp.example.org/smc
|
80
|
+
|
81
|
+
== Using it as a library
|
82
|
+
smc-get, although mainly targetted at being a command-line utility, may also be
|
83
|
+
used as a library. This is useful when, for instance, creating a GUI front-end.
|
84
|
+
|
85
|
+
To initialize the library, call SmcGet.setup which will do some basic initialization
|
86
|
+
needed for use of the library.
|
87
|
+
SmcGet.setup
|
88
|
+
For interacting with the SMC repository, smc-get exposes an object-oriented API
|
89
|
+
centered around the Package and repository classes. Before you can do anything,
|
90
|
+
you have to "establish" connections to a remote and a local repository, where
|
91
|
+
remote repositories are repositories where <tt>smc-get</tt> downloads from,
|
92
|
+
and local repositories are repositories where <tt>smc-get</tt> installs
|
93
|
+
into, i.e. usually your SMC installation. You can use multiple repositories
|
94
|
+
if you know how to manage it.
|
95
|
+
|
96
|
+
rr = SmcGet::RemoteRepository.new("http://example.org/smc-repo")
|
97
|
+
lr = SmcGet::LocalRepository.new("/usr/local/share/smc")
|
98
|
+
|
99
|
+
After you initialized the library
|
100
|
+
as explained above, you can query, install and uninstall packages.
|
101
|
+
|
102
|
+
path = rr.fetch_package("mypackage")
|
103
|
+
pkg = SmcGet::Package.from_file(path)
|
104
|
+
lr.install(pkg)
|
105
|
+
|
106
|
+
If any of the methods fails, it will raise various exceptions. When creating a GUI,
|
107
|
+
you should catch these exceptions and present them as message boxes.
|
108
|
+
|
109
|
+
begin
|
110
|
+
rr.fetch_package("mypackage")
|
111
|
+
rescue SmcGet::Errors::NoSuchPackageError => e
|
112
|
+
alert "No such package: #{e.package_name}!"
|
113
|
+
end
|
114
|
+
|
115
|
+
All errors smc-get raises are subclasses of SmcGet::Errors::SmcGetError. That
|
116
|
+
means, if you rescue from this exception, you can handle all package-related
|
117
|
+
errors at once:
|
118
|
+
|
119
|
+
begin
|
120
|
+
lr.install(pkg)
|
121
|
+
rescue SmcGet::Errors::SmcGetError => e
|
122
|
+
alert e.message
|
123
|
+
end
|
124
|
+
|
125
|
+
Furthermore, these error messages should have a pretty informative message set,
|
126
|
+
so unless you want to localize the error messages you can just reach them
|
127
|
+
through (the messages, not the whole exceptions, of course).
|
128
|
+
|
129
|
+
The configuration file only contains settings for the commandline user
|
130
|
+
interface, so you don't need it here. If you want to use the CUI from
|
131
|
+
your scripts, do
|
132
|
+
require "smc_get"
|
133
|
+
require "smc_get/cui"
|
134
|
+
|
135
|
+
cui = SmcGet::CUI.new(ARGV)
|
136
|
+
cui.start
|
137
|
+
The configuration file from the <b>config/</b> directory will automatically
|
138
|
+
be loaded as well as the user-level configuration file; you may specify another
|
139
|
+
configuration file by placing the appropriate option in ARGV:
|
140
|
+
ARGV.unshift("-c")
|
141
|
+
ARGV.unshift("YOURCONFIGFILE.yml")
|
142
|
+
|
143
|
+
cui = SmcGet::CUI.new(ARGV)
|
144
|
+
cui.start
|
145
|
+
|
146
|
+
= License
|
147
|
+
|
148
|
+
smc-get is licensed under the GNU General Public License version 3 or later. For
|
149
|
+
more information, see COPYING.
|
150
|
+
|
151
|
+
= Website
|
152
|
+
|
153
|
+
This software was written by Entertaining Software, Inc. Visit us at
|
154
|
+
http://www.entertainingsoftware.com.
|
155
|
+
|
156
|
+
This software is hosted at GitHub. The project page can be found at
|
157
|
+
https://github.com/Luiji/smc-get.
|
158
|
+
|
159
|
+
This software was written for Secret Maryo Chronicles. Visit them at
|
160
|
+
http://www.secretmaryo.org.
|
161
|
+
|
162
|
+
Bugs related to this software may be reported at
|
163
163
|
https://github.com/Luiji/smc-get/issues.
|
data/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0-beta1
|
data/bin/smc-checksum
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#Encoding: UTF-8
|
3
|
-
|
4
|
-
require "pathname"
|
5
|
-
require "digest/sha1"
|
6
|
-
|
7
|
-
PROG = File.basename($0)
|
8
|
-
|
9
|
-
if ARGV.include?("-h") or ARGV.include?("--help")
|
10
|
-
puts(<<HELP)
|
11
|
-
USAGE:
|
12
|
-
#{PROG} [FILES...]
|
13
|
-
|
14
|
-
Prints out all SHA1 checksums of the FILES given at the commandline.
|
15
|
-
FILES that are directories are listed recursively. If no FILES
|
16
|
-
are given, recursively lists the current directory.
|
17
|
-
HELP
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
Signal.trap("SIGINT"){exit}
|
22
|
-
Signal.trap("SIGTERM"){exit}
|
23
|
-
|
24
|
-
ARGV.unshift(".") if ARGV.empty?
|
25
|
-
|
26
|
-
ARGV.each do |arg|
|
27
|
-
begin
|
28
|
-
path = Pathname.new(arg)
|
29
|
-
|
30
|
-
if path.file?
|
31
|
-
puts "#{path}: #{Digest::SHA1.hexdigest(File.read(path))}"
|
32
|
-
else
|
33
|
-
path.find do |sub_path|
|
34
|
-
puts "#{sub_path}: #{Digest::SHA1.hexdigest(File.read(sub_path))}" if sub_path.file?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
rescue Errno::ENOENT => e
|
38
|
-
$stderr.puts("WARNING: Not found: #{arg}.")
|
39
|
-
$stderr.puts("Skipping.")
|
40
|
-
rescue Errno::EACCES => e
|
41
|
-
$stderr.puts("WARNING: Permission denied: #{arg}.")
|
42
|
-
$stderr.puts("Skipping.")
|
43
|
-
end
|
44
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#Encoding: UTF-8
|
3
|
+
|
4
|
+
require "pathname"
|
5
|
+
require "digest/sha1"
|
6
|
+
|
7
|
+
PROG = File.basename($0)
|
8
|
+
|
9
|
+
if ARGV.include?("-h") or ARGV.include?("--help")
|
10
|
+
puts(<<HELP)
|
11
|
+
USAGE:
|
12
|
+
#{PROG} [FILES...]
|
13
|
+
|
14
|
+
Prints out all SHA1 checksums of the FILES given at the commandline.
|
15
|
+
FILES that are directories are listed recursively. If no FILES
|
16
|
+
are given, recursively lists the current directory.
|
17
|
+
HELP
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
Signal.trap("SIGINT"){exit}
|
22
|
+
Signal.trap("SIGTERM"){exit}
|
23
|
+
|
24
|
+
ARGV.unshift(".") if ARGV.empty?
|
25
|
+
|
26
|
+
ARGV.each do |arg|
|
27
|
+
begin
|
28
|
+
path = Pathname.new(arg)
|
29
|
+
|
30
|
+
if path.file?
|
31
|
+
puts "#{path}: #{Digest::SHA1.hexdigest(File.read(path))}"
|
32
|
+
else
|
33
|
+
path.find do |sub_path|
|
34
|
+
puts "#{sub_path}: #{Digest::SHA1.hexdigest(File.read(sub_path))}" if sub_path.file?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
rescue Errno::ENOENT => e
|
38
|
+
$stderr.puts("WARNING: Not found: #{arg}.")
|
39
|
+
$stderr.puts("Skipping.")
|
40
|
+
rescue Errno::EACCES => e
|
41
|
+
$stderr.puts("WARNING: Permission denied: #{arg}.")
|
42
|
+
$stderr.puts("Skipping.")
|
43
|
+
end
|
44
|
+
end
|