s3share 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.markdown +68 -0
- data/Rakefile +1 -0
- data/bin/s3.rb +4 -0
- data/lib/s3share/args.rb +8 -0
- data/lib/s3share/runner.rb +102 -0
- data/lib/s3share/version.rb +3 -0
- data/lib/s3share.rb +3 -0
- metadata +80 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Federico Builes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
S3Share
|
2
|
+
=======
|
3
|
+
|
4
|
+
S3Share is a simple script to upload your files to S3 and share them with your friends.
|
5
|
+
|
6
|
+
Requirements
|
7
|
+
------------
|
8
|
+
* Ruby
|
9
|
+
* aws-s3 gem
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
You can install from Rubygems
|
15
|
+
|
16
|
+
$ gem install s3share
|
17
|
+
|
18
|
+
Or you can download the source and build it manually:
|
19
|
+
|
20
|
+
$ git clone https://febuiles@github.com/febuiles/s3share.git
|
21
|
+
$ rake install
|
22
|
+
|
23
|
+
|
24
|
+
Setting ENV variables
|
25
|
+
----------------
|
26
|
+
You'll need to set the three following ENV variables:
|
27
|
+
|
28
|
+
* `AMAZON_ACCESS_KEY_ID`: AWS access key.
|
29
|
+
* `AMAZON_SECRET_ACCESS_KEY`: AWS secret access key.
|
30
|
+
* `AMAZON_S3_DEFAULT_BUCKET`: Name of the bucket where the uploads will be held.
|
31
|
+
|
32
|
+
The last variable is visible in the URL returned to the user: `http://s3.amazonaws.com/{AMAZON_S3_DEFAULT_BUCKET}/some_photo.png`, so make sure you choose something pretty. This value is global for all the S3 namespace, meaning you need to find something unique between all the S3 users ("some-user-name_uploads" should do the trick).
|
33
|
+
|
34
|
+
You can set these variables in a `~/.amazon_keys` file:
|
35
|
+
|
36
|
+
export AMAZON_ACCESS_KEY_ID='someaccesskey'
|
37
|
+
export AMAZON_SECRET_ACCESS_KEY='fortyweirdcharacters'
|
38
|
+
export AMAZON_S3_DEFAULT_BUCKET='joesuploads'
|
39
|
+
|
40
|
+
And then include it in your `~/.bash_profile`:
|
41
|
+
|
42
|
+
# place at the bottom of your .bash_profile
|
43
|
+
if [[ -f "$HOME/.amazon_keys" ]]; then
|
44
|
+
source "$HOME/.amazon_keys";
|
45
|
+
fi
|
46
|
+
|
47
|
+
Usage
|
48
|
+
------
|
49
|
+
|
50
|
+
$ s3.rb [file]
|
51
|
+
|
52
|
+
An example:
|
53
|
+
|
54
|
+
$ s3.rb kezia.png
|
55
|
+
|
56
|
+
kezia.png uploaded to: http://s3.amazonaws.com/heroin-uploads/kezia.png
|
57
|
+
|
58
|
+
By default all the uploaded files will be publicly readable. Once the upload is complete the URL will be copied to your clipboard for easy access.
|
59
|
+
|
60
|
+
Bugs/Contact
|
61
|
+
------------
|
62
|
+
|
63
|
+
Got a problem? Create an issue in the [Github Tracker](https://github.com/febuiles/s3share/issues).
|
64
|
+
|
65
|
+
Author
|
66
|
+
------
|
67
|
+
|
68
|
+
Federico Builes - federico@mheroin.com - @febuiles
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Empty Rakefile...
|
data/bin/s3.rb
ADDED
data/lib/s3share/args.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
module S3Share
|
2
|
+
class Runner
|
3
|
+
def initialize(*args)
|
4
|
+
@args = Args.new(args)
|
5
|
+
@filename = args.first
|
6
|
+
|
7
|
+
# Print usage instructions if the filename is empty.
|
8
|
+
if @filename.nil?
|
9
|
+
puts "usage: s3.rb [filename]"
|
10
|
+
exit(-1)
|
11
|
+
end
|
12
|
+
|
13
|
+
@path = get_directory
|
14
|
+
@filename = clean_filename
|
15
|
+
|
16
|
+
# Upload the file and save the URL in the clipboard
|
17
|
+
exit_code = set_clipboard_url(upload_file)
|
18
|
+
exit(exit_code)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The user can specify absolute paths, relative paths and individual
|
22
|
+
# filenames so we need to make sure we return the proper path to the
|
23
|
+
# directory.
|
24
|
+
def get_directory
|
25
|
+
if !@filename.include?("/") # single file name
|
26
|
+
"#{Dir.pwd}"
|
27
|
+
elsif @filename[0,1] == "/" # absolute path
|
28
|
+
"#{@filename.split("/")[0..-2].join("/")}"
|
29
|
+
else # relative path
|
30
|
+
"#{Dir.pwd}/#{@filename.split("/")[0..-2].join("/")}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns only the filename, discarding any directory info.
|
35
|
+
def clean_filename
|
36
|
+
@filename.split("/").last
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Uploads the file to Amazon S3 and returns the URL for the
|
41
|
+
# object. Uploaded files are publicly readable.
|
42
|
+
def upload_file
|
43
|
+
bucket_name = ENV["AMAZON_S3_DEFAULT_BUCKET"] || ""
|
44
|
+
access_key = ENV["AMAZON_ACCESS_KEY_ID"] || ""
|
45
|
+
secret_key = ENV["AMAZON_SECRET_ACCESS_KEY"] || ""
|
46
|
+
|
47
|
+
if bucket_name.empty?
|
48
|
+
print_error(:no_default_bucket)
|
49
|
+
exit(-2)
|
50
|
+
end
|
51
|
+
|
52
|
+
if access_key.empty? || secret_key.empty?
|
53
|
+
print_error(:wrong_aws_credentials)
|
54
|
+
exit(-3)
|
55
|
+
end
|
56
|
+
|
57
|
+
AWS::S3::Base.establish_connection!(
|
58
|
+
:access_key_id => access_key,
|
59
|
+
:secret_access_key => secret_key
|
60
|
+
)
|
61
|
+
|
62
|
+
AWS::S3::S3Object.store(@filename, open("#{@path}/#{@filename}"),
|
63
|
+
bucket_name,
|
64
|
+
:access => :public_read)
|
65
|
+
|
66
|
+
url = "http://s3.amazonaws.com/#{bucket_name}/#{@filename}"
|
67
|
+
puts "\n #{@filename} uploaded to: #{url}\n\n"
|
68
|
+
url
|
69
|
+
end
|
70
|
+
|
71
|
+
# Saves `url` in the clipboard for easy access. `#clipboard_cmd`
|
72
|
+
# should be extended for other platforms (right now only OS X is
|
73
|
+
# supported).
|
74
|
+
def set_clipboard_url(url)
|
75
|
+
system "echo #{url} | #{clipboard_cmd}"
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the name of the command that allows you to pipe stuff
|
79
|
+
# into the clipboard. `pbcopy` for OS X, no idea what it is in
|
80
|
+
# other systems.
|
81
|
+
def clipboard_cmd
|
82
|
+
"pbcopy"
|
83
|
+
end
|
84
|
+
|
85
|
+
# Finds an error by name and prints the associated error string.
|
86
|
+
def print_error(err)
|
87
|
+
errors = {
|
88
|
+
:no_default_bucket =>
|
89
|
+
["\nENV variable AMAZON_S3_DEFAULT_BUCKET has not been set.",
|
90
|
+
"Please run:",
|
91
|
+
" export AMAZON_S3_DEFAULT_BUCKET=\"bucket-name\"",
|
92
|
+
"\nRead the documentation for more information.\n\n"],
|
93
|
+
:wrong_aws_credentials =>
|
94
|
+
["\nAWS credentials are invalid. Make sure that you have set the ENV:",
|
95
|
+
"\n export AMAZON_ACCESS_KEY_ID=\"your-access-key\"",
|
96
|
+
" export AMAZON_SECRET_ACCESS_KEY=\"your-secret-key\"",
|
97
|
+
"\nRead the documentation for more information.\n\n"]
|
98
|
+
}
|
99
|
+
errors[err].each { |msg| puts msg }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/s3share.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3share
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Federico Builes
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-14 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |+
|
22
|
+
S3Share allows simple uploads to Amazon S3 from your command line. Set
|
23
|
+
your access ENV variables (see website) and upload the file:
|
24
|
+
|
25
|
+
$ s3.rb kezia.png
|
26
|
+
|
27
|
+
kezia.png uploaded to: http://s3.amazonaws.com/heroin-uploads/kezia.png
|
28
|
+
|
29
|
+
email: federico.builes@gmail.com
|
30
|
+
executables:
|
31
|
+
- s3.rb
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- README.markdown
|
38
|
+
- Rakefile
|
39
|
+
- LICENSE
|
40
|
+
- lib/s3share/args.rb
|
41
|
+
- lib/s3share/runner.rb
|
42
|
+
- lib/s3share/version.rb
|
43
|
+
- lib/s3share.rb
|
44
|
+
- bin/s3.rb
|
45
|
+
has_rdoc: false
|
46
|
+
homepage: http://github.com/febuiles/s3share
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Upload your files to S3 and share them with your friends.
|
79
|
+
test_files: []
|
80
|
+
|