shere 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.gitmodules +3 -0
- data/CHANGES.md +5 -0
- data/Gemfile +6 -0
- data/LICENSE +201 -0
- data/README.md +48 -0
- data/Rakefile +18 -0
- data/TODO.md +1 -0
- data/bin/shere +4 -0
- data/lib/shere.rb +217 -0
- data/lib/shere/runner.rb +62 -0
- data/lib/shere/version.rb +4 -0
- data/shere.gemspec +42 -0
- data/task/.gitignore +1 -0
- data/task/gemgem.rb +265 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Shere
|
2
|
+
|
3
|
+
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
|
+
|
5
|
+
## LINKS:
|
6
|
+
|
7
|
+
* [github](https://github.com/godfat/shere)
|
8
|
+
* [rubygems](http://rubygems.org/gems/shere)
|
9
|
+
|
10
|
+
## DESCRIPTION:
|
11
|
+
|
12
|
+
_Share_ the directory _here_ with [Nginx][]!
|
13
|
+
|
14
|
+
[Nginx]: http://nginx.org/
|
15
|
+
|
16
|
+
## REQUIREMENTS:
|
17
|
+
|
18
|
+
* Any Ruby 1.8+
|
19
|
+
* [Nginx][]
|
20
|
+
|
21
|
+
## INSTALLATION:
|
22
|
+
|
23
|
+
gem install shere
|
24
|
+
|
25
|
+
## SYNOPSIS:
|
26
|
+
|
27
|
+
shere
|
28
|
+
shere --help
|
29
|
+
shere -p 8080 ~/public
|
30
|
+
sudo shere -u nobody
|
31
|
+
|
32
|
+
## LICENSE:
|
33
|
+
|
34
|
+
Apache License 2.0
|
35
|
+
|
36
|
+
Copyright (c) 2011, Lin Jen-Shin (godfat)
|
37
|
+
|
38
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
39
|
+
you may not use this file except in compliance with the License.
|
40
|
+
You may obtain a copy of the License at
|
41
|
+
|
42
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
43
|
+
|
44
|
+
Unless required by applicable law or agreed to in writing, software
|
45
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
46
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
47
|
+
See the License for the specific language governing permissions and
|
48
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
3
|
+
Gemgem.dir = dir
|
4
|
+
|
5
|
+
($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib")).uniq!
|
6
|
+
|
7
|
+
desc 'Generate gemspec'
|
8
|
+
task 'gem:spec' do
|
9
|
+
Gemgem.spec = Gemgem.create do |s|
|
10
|
+
require 'shere/version'
|
11
|
+
s.name = 'shere'
|
12
|
+
s.version = Shere::VERSION
|
13
|
+
|
14
|
+
%w[].each{ |g| s.add_runtime_dependency(g) }
|
15
|
+
end
|
16
|
+
|
17
|
+
Gemgem.write
|
18
|
+
end
|
data/TODO.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# TODO
|
data/bin/shere
ADDED
data/lib/shere.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
|
2
|
+
module Shere
|
3
|
+
module_function
|
4
|
+
def run opts={}
|
5
|
+
root = File.expand_path(opts[:root] || '.')
|
6
|
+
port = opts[:port] || 4331
|
7
|
+
host = opts[:host] || '_'
|
8
|
+
user = opts[:user]
|
9
|
+
|
10
|
+
require 'tmpdir'
|
11
|
+
tmpdir = Dir.mktmpdir
|
12
|
+
File.open("#{tmpdir}/nginx.conf", 'w'){ |conf|
|
13
|
+
conf.puts(nginx_config(root, port, host, user, tmpdir))
|
14
|
+
}
|
15
|
+
sh('nginx', '-c', "#{tmpdir}/nginx.conf")
|
16
|
+
puts("PID: #{File.read("#{tmpdir}/nginx.pid")}")
|
17
|
+
puts("http://#{local_ip}:#{port}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def local_ip
|
21
|
+
require 'socket'
|
22
|
+
Socket.getaddrinfo(Socket.gethostname, 'echo', Socket::AF_INET)[0][3]
|
23
|
+
end
|
24
|
+
|
25
|
+
def root_privilege?
|
26
|
+
require 'etc'
|
27
|
+
Etc.getpwuid(Process.uid).name == 'root'
|
28
|
+
end
|
29
|
+
|
30
|
+
def sh *commands
|
31
|
+
puts commands.join(' ')
|
32
|
+
system(*commands)
|
33
|
+
end
|
34
|
+
|
35
|
+
def nginx_config root, port, host, user, tmpdir=Dir.mktmpdir
|
36
|
+
if user
|
37
|
+
if root_privilege?
|
38
|
+
"user #{user};\n"
|
39
|
+
else
|
40
|
+
puts "\e[31m[WARN] Since you don't have root privilege,"
|
41
|
+
puts " switching user to `#{user}' is not possible.\e[0m"
|
42
|
+
''
|
43
|
+
end
|
44
|
+
else
|
45
|
+
''
|
46
|
+
end +
|
47
|
+
<<-NGINX
|
48
|
+
worker_processes 2;
|
49
|
+
|
50
|
+
error_log #{tmpdir}/nginx_error.log;
|
51
|
+
pid #{tmpdir}/nginx.pid;
|
52
|
+
|
53
|
+
events {
|
54
|
+
worker_connections 1024;
|
55
|
+
}
|
56
|
+
|
57
|
+
http {
|
58
|
+
#{nginx_mime_types}
|
59
|
+
default_type application/octet-stream;
|
60
|
+
|
61
|
+
log_format main '$remote_addr - $remote_user [$time_local] $request '
|
62
|
+
'"$status" $body_bytes_sent "$http_referer" '
|
63
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
64
|
+
|
65
|
+
access_log #{tmpdir}/nginx_access.log main;
|
66
|
+
|
67
|
+
fastcgi_temp_path #{tmpdir}/fcgi_temp;
|
68
|
+
client_body_temp_path #{tmpdir}/client_body 1 2;
|
69
|
+
proxy_temp_path #{tmpdir}/proxy_temp;
|
70
|
+
|
71
|
+
client_header_timeout 10m;
|
72
|
+
client_body_timeout 10m;
|
73
|
+
send_timeout 10m;
|
74
|
+
|
75
|
+
connection_pool_size 256;
|
76
|
+
client_header_buffer_size 1k;
|
77
|
+
large_client_header_buffers 4 2k;
|
78
|
+
request_pool_size 4k;
|
79
|
+
|
80
|
+
output_buffers 1 32k;
|
81
|
+
postpone_output 1460;
|
82
|
+
|
83
|
+
sendfile on;
|
84
|
+
tcp_nopush on;
|
85
|
+
tcp_nodelay on;
|
86
|
+
|
87
|
+
keepalive_timeout 75 20;
|
88
|
+
ignore_invalid_headers on;
|
89
|
+
|
90
|
+
gzip on;
|
91
|
+
gzip_min_length 1100;
|
92
|
+
gzip_buffers 4 8k;
|
93
|
+
gzip_types text/plain text/css application/xhtml+xml application/javascript;
|
94
|
+
|
95
|
+
server {
|
96
|
+
listen #{port};
|
97
|
+
server_name #{host};
|
98
|
+
index index.xhtml index.html index.htm;
|
99
|
+
|
100
|
+
location / {
|
101
|
+
root #{root};
|
102
|
+
autoindex on;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
NGINX
|
107
|
+
end
|
108
|
+
|
109
|
+
def nginx_mime_types
|
110
|
+
<<-NGINX
|
111
|
+
types {
|
112
|
+
# text
|
113
|
+
text/plain txt;
|
114
|
+
text/html html htm shtml;
|
115
|
+
text/css css;
|
116
|
+
text/xml xml;
|
117
|
+
|
118
|
+
# images
|
119
|
+
image/gif gif;
|
120
|
+
image/jpeg jpeg jpg;
|
121
|
+
image/png png;
|
122
|
+
image/tiff tif tiff;
|
123
|
+
image/vnd.microsoft.icon ico;
|
124
|
+
|
125
|
+
# common application
|
126
|
+
application/atom+xml atom;
|
127
|
+
application/rss+xml rss;
|
128
|
+
application/xhtml+xml xhtml;
|
129
|
+
|
130
|
+
application/javascript js;
|
131
|
+
application/postscript ps eps ai;
|
132
|
+
application/rtf rtf;
|
133
|
+
|
134
|
+
application/x-shockwave-flash swf;
|
135
|
+
application/pdf pdf;
|
136
|
+
application/java-archive jar war ear;
|
137
|
+
|
138
|
+
application/zip zip;
|
139
|
+
application/x-gzip gz;
|
140
|
+
application/x-tar tar;
|
141
|
+
application/x-rar-compressed rar;
|
142
|
+
|
143
|
+
application/vnd.mozilla.xul+xml xul;
|
144
|
+
application/msword doc;
|
145
|
+
application/vnd.ms-excel xls;
|
146
|
+
application/vnd.ms-powerpoint ppt;
|
147
|
+
|
148
|
+
# audio
|
149
|
+
audio/midi mid midi kar;
|
150
|
+
audio/mpeg mp3;
|
151
|
+
audio/ogg ogg;
|
152
|
+
audio/aac m4a;
|
153
|
+
|
154
|
+
audio/vnd.rn-realaudio ra;
|
155
|
+
|
156
|
+
audio/x-wav wav;
|
157
|
+
audio/x-ms-wma wma;
|
158
|
+
|
159
|
+
# video
|
160
|
+
video/mpeg mpeg mpg;
|
161
|
+
video/quicktime mov;
|
162
|
+
video/mp4 mp4;
|
163
|
+
|
164
|
+
video/x-ms-wmv wmv;
|
165
|
+
video/x-ms-asf asx asf;
|
166
|
+
video/x-aif aif aiff aifc;
|
167
|
+
video/x-msvideo avi;
|
168
|
+
|
169
|
+
# others
|
170
|
+
text/mathml mml;
|
171
|
+
text/vnd.sun.j2me.app-descriptor jad;
|
172
|
+
text/vnd.wap.wml wml;
|
173
|
+
text/x-component htc;
|
174
|
+
|
175
|
+
image/x-portable-pixmap ppm;
|
176
|
+
image/x-portable-graymap pgm;
|
177
|
+
image/x-portable-bitmap pbm;
|
178
|
+
image/x-portable-anymap pnm;
|
179
|
+
image/x-xwindowdump xwd;
|
180
|
+
image/x-xpixmap xpm;
|
181
|
+
image/x-xbitmap xbm;
|
182
|
+
|
183
|
+
image/vnd.wap.wbmp wbmp;
|
184
|
+
image/x-jng jng;
|
185
|
+
image/x-ms-bmp bmp;
|
186
|
+
|
187
|
+
video/3gpp 3gpp 3gp;
|
188
|
+
video/x-flv flv;
|
189
|
+
video/x-mng mng;
|
190
|
+
|
191
|
+
application/mac-binhex40 hqx;
|
192
|
+
application/vnd.wap.wmlc wmlc;
|
193
|
+
|
194
|
+
application/x-cocoa cco;
|
195
|
+
application/x-java-archive-diff jardiff;
|
196
|
+
application/x-java-jnlp-file jnlp;
|
197
|
+
application/x-makeself run;
|
198
|
+
application/x-perl pl pm;
|
199
|
+
application/x-pilot prc pdb;
|
200
|
+
|
201
|
+
application/x-redhat-package-manager rpm;
|
202
|
+
application/x-sea sea;
|
203
|
+
application/x-stuffit sit;
|
204
|
+
application/x-tcl tcl tk;
|
205
|
+
application/x-x509-ca-cert der pem crt;
|
206
|
+
application/x-xpinstall xpi;
|
207
|
+
|
208
|
+
application/octet-stream bin exe dll;
|
209
|
+
application/octet-stream deb;
|
210
|
+
application/octet-stream dmg;
|
211
|
+
application/octet-stream eot;
|
212
|
+
application/octet-stream iso img;
|
213
|
+
application/octet-stream msi msp msm;
|
214
|
+
}
|
215
|
+
NGINX
|
216
|
+
end
|
217
|
+
end
|
data/lib/shere/runner.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
module Shere; end
|
3
|
+
module Shere::Runner
|
4
|
+
module_function
|
5
|
+
def options
|
6
|
+
@options ||=
|
7
|
+
[['-p, --port PORT', 'Which port Nginx should listen on (default 4331)'],
|
8
|
+
['-h, --host HOST', 'Which host Nginx should use (default _)' ],
|
9
|
+
['-u, --user USER', 'Which user Nginx should use' \
|
10
|
+
' (if having root privilege)'],
|
11
|
+
[' --help' , 'Print this message' ],
|
12
|
+
['-v, --version' , 'Print the version' ]]
|
13
|
+
end
|
14
|
+
|
15
|
+
def run argv=ARGV.dup
|
16
|
+
opts = parse(argv)
|
17
|
+
require 'shere'
|
18
|
+
Shere.run(opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse argv
|
22
|
+
opts = {}
|
23
|
+
until argv.empty?
|
24
|
+
case arg = argv.shift
|
25
|
+
when /^-p=?(.+)?/, /^--port=?(.+)?/
|
26
|
+
opts[:port] = $1 || argv.shift
|
27
|
+
|
28
|
+
when /^-h=?(.+)?/, /^--host=?(.+)?/
|
29
|
+
opts[:host] = $1 || argv.shift
|
30
|
+
|
31
|
+
when /^-u=?(.+)?/, /^--user=?(.+)?/
|
32
|
+
opts[:user] = $1 || argv.shift
|
33
|
+
|
34
|
+
when '--help'
|
35
|
+
puts(help)
|
36
|
+
exit
|
37
|
+
|
38
|
+
when '-v', '--version'
|
39
|
+
require 'shere/version'
|
40
|
+
puts(Shere::VERSION)
|
41
|
+
exit
|
42
|
+
|
43
|
+
else
|
44
|
+
opts[:root] = arg
|
45
|
+
end
|
46
|
+
end
|
47
|
+
opts
|
48
|
+
end
|
49
|
+
|
50
|
+
def help
|
51
|
+
maxn = options.transpose.first.map(&:size).max
|
52
|
+
maxd = options.transpose.last .map(&:size).max
|
53
|
+
"Usage: shere ROOT\n" +
|
54
|
+
options.map{ |(name, desc)|
|
55
|
+
if desc.empty?
|
56
|
+
name
|
57
|
+
else
|
58
|
+
sprintf(" %-*s %-*s", maxn, name, maxd, desc)
|
59
|
+
end
|
60
|
+
}.join("\n")
|
61
|
+
end
|
62
|
+
end
|
data/shere.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "shere"
|
5
|
+
s.version = "0.9.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Lin Jen-Shin (godfat)"]
|
9
|
+
s.date = "2011-11-04"
|
10
|
+
s.description = "_Share_ the directory _here_ with [Nginx][]!\n\n[Nginx]: http://nginx.org/"
|
11
|
+
s.email = ["godfat (XD) godfat.org"]
|
12
|
+
s.executables = ["shere"]
|
13
|
+
s.files = [
|
14
|
+
".gitignore",
|
15
|
+
".gitmodules",
|
16
|
+
"CHANGES.md",
|
17
|
+
"Gemfile",
|
18
|
+
"LICENSE",
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"TODO.md",
|
22
|
+
"bin/shere",
|
23
|
+
"lib/shere.rb",
|
24
|
+
"lib/shere/runner.rb",
|
25
|
+
"lib/shere/version.rb",
|
26
|
+
"shere.gemspec",
|
27
|
+
"task/.gitignore",
|
28
|
+
"task/gemgem.rb"]
|
29
|
+
s.homepage = "https://github.com/godfat/shere"
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = "1.8.11"
|
32
|
+
s.summary = "_Share_ the directory _here_ with [Nginx][]!"
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
s.specification_version = 3
|
36
|
+
|
37
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
38
|
+
else
|
39
|
+
end
|
40
|
+
else
|
41
|
+
end
|
42
|
+
end
|
data/task/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.rbc
|
data/task/gemgem.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Gemgem
|
5
|
+
class << self
|
6
|
+
attr_accessor :dir, :spec
|
7
|
+
end
|
8
|
+
|
9
|
+
module_function
|
10
|
+
def create
|
11
|
+
yield(spec = Gem::Specification.new{ |s|
|
12
|
+
s.authors = ['Lin Jen-Shin (godfat)']
|
13
|
+
s.email = ['godfat (XD) godfat.org']
|
14
|
+
|
15
|
+
s.description = description.join
|
16
|
+
s.summary = description.first
|
17
|
+
|
18
|
+
s.rubygems_version = Gem::VERSION
|
19
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
20
|
+
s.files = gem_files
|
21
|
+
s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
22
|
+
s.executables = Dir['bin/*'].map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = %w[lib]
|
24
|
+
})
|
25
|
+
spec.homepage ||= "https://github.com/godfat/#{spec.name}"
|
26
|
+
spec
|
27
|
+
end
|
28
|
+
|
29
|
+
def readme
|
30
|
+
path = %w[README.md README].find{ |name|
|
31
|
+
File.exist?("#{Gemgem.dir}/#{name}")
|
32
|
+
}
|
33
|
+
@readme ||=
|
34
|
+
if path
|
35
|
+
ps = File.read(path).scan(/#+[^\n]+\n\n.+?(?=\n\n#+[^\n]+\n)/m)
|
36
|
+
ps.inject({'HEADER' => ps.first}){ |r, s, i|
|
37
|
+
r[s[/\w+/]] = s
|
38
|
+
r
|
39
|
+
}
|
40
|
+
else
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def description
|
46
|
+
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
def changes
|
50
|
+
path = %w[CHANGES.md CHANGES].find{ |name|
|
51
|
+
File.exist?("#{Gemgem.dir}/#{name}")
|
52
|
+
}
|
53
|
+
@changes ||=
|
54
|
+
if path
|
55
|
+
date = '\d+{4}\-\d+{2}\-\d{2}'
|
56
|
+
File.read(path).match(
|
57
|
+
/([^\n]+#{date}\n\n(.+?))(?=\n\n[^\n]+#{date}\n|\Z)/m)[1]
|
58
|
+
else
|
59
|
+
''
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def ann_md
|
64
|
+
"##{readme['HEADER'].sub(/([\w\-]+)/, "[\\1](#{spec.homepage})")}\n\n" \
|
65
|
+
"##{readme['DESCRIPTION'][/[^\n]+\n\n[^\n]+/]}\n\n" \
|
66
|
+
"### CHANGES:\n\n" \
|
67
|
+
"###{changes}\n\n" \
|
68
|
+
"##{readme['INSTALLATION']}\n\n" +
|
69
|
+
if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}" else '' end
|
70
|
+
end
|
71
|
+
|
72
|
+
def ann_html
|
73
|
+
gem 'nokogiri'
|
74
|
+
gem 'kramdown'
|
75
|
+
|
76
|
+
IO.popen('kramdown', 'r+') do |md|
|
77
|
+
md.puts Gemgem.ann_md
|
78
|
+
md.close_write
|
79
|
+
require 'nokogiri'
|
80
|
+
html = Nokogiri::XML.parse("<gemgem>#{md.read}</gemgem>")
|
81
|
+
html.css('*').each{ |n| n.delete('id') }
|
82
|
+
html.root.children.to_html
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def ann_email
|
87
|
+
"#{readme['HEADER'].sub(/([\w\-]+)/, "\\1 <#{spec.homepage}>")}\n\n" \
|
88
|
+
"#{readme['DESCRIPTION']}\n\n" \
|
89
|
+
"#{readme['INSTALLATION']}\n\n" +
|
90
|
+
if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}\n\n" else '' end +
|
91
|
+
"## CHANGES:\n\n" \
|
92
|
+
"##{changes}\n\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
def gem_tag
|
96
|
+
"#{spec.name}-#{spec.version}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def write
|
100
|
+
File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
|
101
|
+
f << split_lines(spec.to_ruby) }
|
102
|
+
end
|
103
|
+
|
104
|
+
def split_lines ruby
|
105
|
+
ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
|
106
|
+
if $2.index(',')
|
107
|
+
"#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
108
|
+
else
|
109
|
+
s
|
110
|
+
end
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def all_files
|
115
|
+
@all_files ||= find_files(Pathname.new(dir)).map{ |file|
|
116
|
+
if file.to_s =~ %r{\.git/}
|
117
|
+
nil
|
118
|
+
else
|
119
|
+
file.to_s
|
120
|
+
end
|
121
|
+
}.compact.sort
|
122
|
+
end
|
123
|
+
|
124
|
+
def gem_files
|
125
|
+
@gem_files ||= all_files - ignored_files
|
126
|
+
end
|
127
|
+
|
128
|
+
def ignored_files
|
129
|
+
@ignored_file ||= all_files.select{ |path| ignore_patterns.find{ |ignore|
|
130
|
+
path =~ ignore && !git_files.include?(path)}}
|
131
|
+
end
|
132
|
+
|
133
|
+
def git_files
|
134
|
+
@git_files ||= if File.exist?("#{dir}/.git")
|
135
|
+
`git ls-files`.split("\n")
|
136
|
+
else
|
137
|
+
[]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# protected
|
142
|
+
def find_files path
|
143
|
+
path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
|
144
|
+
path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
|
145
|
+
end
|
146
|
+
|
147
|
+
def ignore_patterns
|
148
|
+
@ignore_files ||= expand_patterns(
|
149
|
+
gitignore.split("\n").reject{ |pattern|
|
150
|
+
pattern.strip == ''
|
151
|
+
}).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
|
152
|
+
end
|
153
|
+
|
154
|
+
def expand_patterns pathes
|
155
|
+
pathes.map{ |path|
|
156
|
+
if path !~ /\*/
|
157
|
+
path
|
158
|
+
else
|
159
|
+
expand_patterns(
|
160
|
+
Dir[path] +
|
161
|
+
Pathname.new(File.dirname(path)).children.select(&:directory?).
|
162
|
+
map{ |prefix| "#{prefix}/#{File.basename(path)}" })
|
163
|
+
end
|
164
|
+
}.flatten
|
165
|
+
end
|
166
|
+
|
167
|
+
def gitignore
|
168
|
+
if File.exist?(path = "#{dir}/.gitignore")
|
169
|
+
File.read(path)
|
170
|
+
else
|
171
|
+
''
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
namespace :gem do
|
177
|
+
|
178
|
+
desc 'Install gem'
|
179
|
+
task :install => [:build] do
|
180
|
+
sh("#{Gem.ruby} -S gem install pkg/#{Gemgem.gem_tag}")
|
181
|
+
end
|
182
|
+
|
183
|
+
desc 'Build gem'
|
184
|
+
task :build => [:spec] do
|
185
|
+
sh("#{Gem.ruby} -S gem build #{Gemgem.spec.name}.gemspec")
|
186
|
+
sh("mkdir -p pkg")
|
187
|
+
sh("mv #{Gemgem.gem_tag}.gem pkg/")
|
188
|
+
end
|
189
|
+
|
190
|
+
desc 'Release gem'
|
191
|
+
task :release => [:spec, :check, :build] do
|
192
|
+
sh("git tag #{Gemgem.gem_tag}")
|
193
|
+
sh("git push")
|
194
|
+
sh("git push --tags")
|
195
|
+
sh("#{Gem.ruby} -S gem push pkg/#{Gemgem.gem_tag}.gem")
|
196
|
+
end
|
197
|
+
|
198
|
+
task :check do
|
199
|
+
ver = Gemgem.spec.version.to_s
|
200
|
+
|
201
|
+
if ENV['VERSION'].nil?
|
202
|
+
puts("\e[35mExpected " \
|
203
|
+
"\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
|
204
|
+
exit(1)
|
205
|
+
|
206
|
+
elsif ENV['VERSION'] != ver
|
207
|
+
puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
|
208
|
+
"\e[35mbut got\n " \
|
209
|
+
"\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
|
210
|
+
exit(2)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
end # of gem namespace
|
215
|
+
|
216
|
+
desc 'Run tests in memory'
|
217
|
+
task :test do
|
218
|
+
require 'bacon'
|
219
|
+
Bacon.extend(Bacon::TestUnitOutput)
|
220
|
+
Bacon.summary_on_exit
|
221
|
+
$LOAD_PATH.unshift('lib')
|
222
|
+
Dir['./test/**/test_*.rb'].each{ |file| require file[0..-4] }
|
223
|
+
end
|
224
|
+
|
225
|
+
desc 'Run tests with shell'
|
226
|
+
task 'test:shell', :RUBY_OPTS do |t, args|
|
227
|
+
files = Dir['test/**/test_*.rb'].join(' ')
|
228
|
+
|
229
|
+
cmd = [Gem.ruby, args[:RUBY_OPTS],
|
230
|
+
'-I', 'lib', '-S', 'bacon', '--quiet', files]
|
231
|
+
|
232
|
+
sh(cmd.compact.join(' '))
|
233
|
+
end
|
234
|
+
|
235
|
+
desc 'Generate ann markdown'
|
236
|
+
task 'ann:md' => ['gem:spec'] do
|
237
|
+
puts Gemgem.ann_md
|
238
|
+
end
|
239
|
+
|
240
|
+
desc 'Generate ann html'
|
241
|
+
task 'ann:html' => ['gem:spec'] do
|
242
|
+
puts Gemgem.ann_html
|
243
|
+
end
|
244
|
+
|
245
|
+
desc 'Generate ann email'
|
246
|
+
task 'ann:email' => ['gem:spec'] do
|
247
|
+
puts Gemgem.ann_email
|
248
|
+
end
|
249
|
+
|
250
|
+
desc 'Generate rdoc'
|
251
|
+
task :doc => ['gem:spec'] do
|
252
|
+
sh("yardoc -o rdoc --main README.md" \
|
253
|
+
" --files #{Gemgem.spec.extra_rdoc_files.join(',')}")
|
254
|
+
end
|
255
|
+
|
256
|
+
desc 'Remove ignored files'
|
257
|
+
task :clean => ['gem:spec'] do
|
258
|
+
trash = "~/.Trash/#{Gemgem.spec.name}/"
|
259
|
+
sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash))
|
260
|
+
Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
|
261
|
+
end
|
262
|
+
|
263
|
+
task :default do
|
264
|
+
puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
|
265
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shere
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lin Jen-Shin (godfat)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! '_Share_ the directory _here_ with [Nginx][]!
|
15
|
+
|
16
|
+
|
17
|
+
[Nginx]: http://nginx.org/'
|
18
|
+
email:
|
19
|
+
- godfat (XD) godfat.org
|
20
|
+
executables:
|
21
|
+
- shere
|
22
|
+
extensions: []
|
23
|
+
extra_rdoc_files: []
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- .gitmodules
|
27
|
+
- CHANGES.md
|
28
|
+
- Gemfile
|
29
|
+
- LICENSE
|
30
|
+
- README.md
|
31
|
+
- Rakefile
|
32
|
+
- TODO.md
|
33
|
+
- bin/shere
|
34
|
+
- lib/shere.rb
|
35
|
+
- lib/shere/runner.rb
|
36
|
+
- lib/shere/version.rb
|
37
|
+
- shere.gemspec
|
38
|
+
- task/.gitignore
|
39
|
+
- task/gemgem.rb
|
40
|
+
homepage: https://github.com/godfat/shere
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.11
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: _Share_ the directory _here_ with [Nginx][]!
|
64
|
+
test_files: []
|