linebook 0.2.0 → 0.7.0

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.
@@ -0,0 +1,462 @@
1
+ # Generated by Linecook
2
+
3
+ module Linebook
4
+ module Os
5
+ module Unix
6
+ require 'linebook/os/posix'
7
+ include Posix
8
+
9
+ def guess_target_name(source_name)
10
+ target_dir = File.dirname(target_name)
11
+ name = File.basename(source_name)
12
+
13
+ _package_.next_target_name(target_dir == '.' ? name : File.join(target_dir, name))
14
+ end
15
+
16
+ def close
17
+ unless closed?
18
+ if @shebang ||= false
19
+ section " (#{target_name}) "
20
+ end
21
+ end
22
+
23
+ super
24
+ end
25
+
26
+ # Executes 'cat' with the sources.
27
+ def cat(*sources)
28
+ execute 'cat', *sources
29
+ chain_proxy
30
+ end
31
+
32
+ def _cat(*args, &block) # :nodoc:
33
+ str = capture_str { cat(*args, &block) }
34
+ str.strip!
35
+ str
36
+ end
37
+
38
+ def cd(dir=nil)
39
+ if block_given?
40
+ var = _package_.next_variable_name('cd')
41
+ writeln %{#{var}=$(pwd)}
42
+ end
43
+
44
+ execute "cd", dir
45
+
46
+ if block_given?
47
+ yield
48
+ execute "cd", "$#{var}"
49
+ end
50
+ chain_proxy
51
+ end
52
+
53
+ def _cd(*args, &block) # :nodoc:
54
+ str = capture_str { cd(*args, &block) }
55
+ str.strip!
56
+ str
57
+ end
58
+
59
+ # Makes a command to chmod a file or directory. Provide the mode as the
60
+ # literal string that should go into the statement:
61
+ #
62
+ # chmod "600" target
63
+ def chmod(mode, target)
64
+ if mode
65
+ execute 'chmod', mode, target
66
+ end
67
+ chain_proxy
68
+ end
69
+
70
+ def _chmod(*args, &block) # :nodoc:
71
+ str = capture_str { chmod(*args, &block) }
72
+ str.strip!
73
+ str
74
+ end
75
+
76
+ # Makes a command to chown a file or directory.
77
+ def chown(user, group, target)
78
+ if user || group
79
+ execute 'chown', "#{user}:#{group}", target
80
+ end
81
+ chain_proxy
82
+ end
83
+
84
+ def _chown(*args, &block) # :nodoc:
85
+ str = capture_str { chown(*args, &block) }
86
+ str.strip!
87
+ str
88
+ end
89
+
90
+ # Copy source to target. Accepts a hash of command line options.
91
+ def cp(source, target, options={})
92
+ execute 'cp', source, target, options
93
+ chain_proxy
94
+ end
95
+
96
+ def _cp(*args, &block) # :nodoc:
97
+ str = capture_str { cp(*args, &block) }
98
+ str.strip!
99
+ str
100
+ end
101
+
102
+ # Copy source to target, with -f.
103
+ def cp_f(source, target)
104
+ cp source, target, '-f' => true
105
+ chain_proxy
106
+ end
107
+
108
+ def _cp_f(*args, &block) # :nodoc:
109
+ str = capture_str { cp_f(*args, &block) }
110
+ str.strip!
111
+ str
112
+ end
113
+
114
+ # Copy source to target, with -r.
115
+ def cp_r(source, target)
116
+ cp source, target, '-r'=> true
117
+ chain_proxy
118
+ end
119
+
120
+ def _cp_r(*args, &block) # :nodoc:
121
+ str = capture_str { cp_r(*args, &block) }
122
+ str.strip!
123
+ str
124
+ end
125
+
126
+ # Copy source to target, with -rf.
127
+ def cp_rf(source, target)
128
+ cp source, target, '-rf' => true
129
+ chain_proxy
130
+ end
131
+
132
+ def _cp_rf(*args, &block) # :nodoc:
133
+ str = capture_str { cp_rf(*args, &block) }
134
+ str.strip!
135
+ str
136
+ end
137
+
138
+ # Returns the current system time. A format string may be provided, as well as
139
+ # a hash of command line options.
140
+ def date(format=nil, options={})
141
+ if format
142
+ format = "+#{quote(format)}"
143
+ end
144
+
145
+ execute "date", format, options
146
+ chain_proxy
147
+ end
148
+
149
+ def _date(*args, &block) # :nodoc:
150
+ str = capture_str { date(*args, &block) }
151
+ str.strip!
152
+ str
153
+ end
154
+
155
+ def directory?(path)
156
+ # [ -d "<%= path %>" ]
157
+ write "[ -d \""; write(( path ).to_s); write "\" ]"
158
+ chain_proxy
159
+ end
160
+
161
+ def _directory?(*args, &block) # :nodoc:
162
+ str = capture_str { directory?(*args, &block) }
163
+ str.strip!
164
+ str
165
+ end
166
+
167
+ # Echo the args.
168
+ def echo(*args)
169
+ execute 'echo', *args
170
+ chain_proxy
171
+ end
172
+
173
+ def _echo(*args, &block) # :nodoc:
174
+ str = capture_str { echo(*args, &block) }
175
+ str.strip!
176
+ str
177
+ end
178
+
179
+ def exists?(path)
180
+ # [ -e "<%= path %>" ]
181
+ write "[ -e \""; write(( path ).to_s); write "\" ]"
182
+ chain_proxy
183
+ end
184
+
185
+ def _exists?(*args, &block) # :nodoc:
186
+ str = capture_str { exists?(*args, &block) }
187
+ str.strip!
188
+ str
189
+ end
190
+
191
+ def file?(path)
192
+ # [ -f "<%= path %>" ]
193
+ write "[ -f \""; write(( path ).to_s); write "\" ]"
194
+ chain_proxy
195
+ end
196
+
197
+ def _file?(*args, &block) # :nodoc:
198
+ str = capture_str { file?(*args, &block) }
199
+ str.strip!
200
+ str
201
+ end
202
+
203
+ # Sets up a gsub using sed.
204
+ def gsub(pattern, replacement, *args)
205
+ unless args.last.kind_of?(Hash)
206
+ args << {}
207
+ end
208
+ args.last[:e] = "s/#{pattern}/#{replacement}/g"
209
+ sed(*args)
210
+ chain_proxy
211
+ end
212
+
213
+ def _gsub(*args, &block) # :nodoc:
214
+ str = capture_str { gsub(*args, &block) }
215
+ str.strip!
216
+ str
217
+ end
218
+
219
+ # Link source to target. Accepts a hash of command line options.
220
+ def ln(source, target, options={})
221
+ execute 'ln', source, target, options
222
+ chain_proxy
223
+ end
224
+
225
+ def _ln(*args, &block) # :nodoc:
226
+ str = capture_str { ln(*args, &block) }
227
+ str.strip!
228
+ str
229
+ end
230
+
231
+ # Copy source to target, with -s.
232
+ def ln_s(source, target)
233
+ ln source, target, '-s' => true
234
+ chain_proxy
235
+ end
236
+
237
+ def _ln_s(*args, &block) # :nodoc:
238
+ str = capture_str { ln_s(*args, &block) }
239
+ str.strip!
240
+ str
241
+ end
242
+
243
+ # Make a directory. Accepts a hash of command line options.
244
+ def mkdir(path, options={})
245
+ execute 'mkdir', path, options
246
+ chain_proxy
247
+ end
248
+
249
+ def _mkdir(*args, &block) # :nodoc:
250
+ str = capture_str { mkdir(*args, &block) }
251
+ str.strip!
252
+ str
253
+ end
254
+
255
+ # Make a directory, and parent directories as needed.
256
+ def mkdir_p(path)
257
+ mkdir path, '-p' => true
258
+ chain_proxy
259
+ end
260
+
261
+ def _mkdir_p(*args, &block) # :nodoc:
262
+ str = capture_str { mkdir_p(*args, &block) }
263
+ str.strip!
264
+ str
265
+ end
266
+
267
+ # Move source to target. Accepts a hash of command line options.
268
+ def mv(source, target, options={})
269
+ execute 'mv', source, target, options
270
+ chain_proxy
271
+ end
272
+
273
+ def _mv(*args, &block) # :nodoc:
274
+ str = capture_str { mv(*args, &block) }
275
+ str.strip!
276
+ str
277
+ end
278
+
279
+ # Move source to target, with -f.
280
+ def mv_f(source, target)
281
+ mv source, target, '-f' => true
282
+ chain_proxy
283
+ end
284
+
285
+ def _mv_f(*args, &block) # :nodoc:
286
+ str = capture_str { mv_f(*args, &block) }
287
+ str.strip!
288
+ str
289
+ end
290
+
291
+ # Unlink a file. Accepts a hash of command line options.
292
+ def rm(path, options={})
293
+ execute 'rm', path, options
294
+ chain_proxy
295
+ end
296
+
297
+ def _rm(*args, &block) # :nodoc:
298
+ str = capture_str { rm(*args, &block) }
299
+ str.strip!
300
+ str
301
+ end
302
+
303
+ # Unlink a file or directory, with -r.
304
+ def rm_r(path)
305
+ rm path, '-r' => true
306
+ chain_proxy
307
+ end
308
+
309
+ def _rm_r(*args, &block) # :nodoc:
310
+ str = capture_str { rm_r(*args, &block) }
311
+ str.strip!
312
+ str
313
+ end
314
+
315
+ # Unlink a file or directory, with -rf.
316
+ def rm_rf(path)
317
+ rm path, '-rf' => true
318
+ chain_proxy
319
+ end
320
+
321
+ def _rm_rf(*args, &block) # :nodoc:
322
+ str = capture_str { rm_rf(*args, &block) }
323
+ str.strip!
324
+ str
325
+ end
326
+
327
+ def section(comment="")
328
+ n = (78 - comment.length)/2
329
+ str = "-" * n
330
+ # #<%= str %><%= comment %><%= str %><%= "-" if comment.length % 2 == 1 %>
331
+ #
332
+ write "#"; write(( str ).to_s); write(( comment ).to_s); write(( str ).to_s); write(( "-" if comment.length % 2 == 1 ).to_s); write "\n"
333
+
334
+ chain_proxy
335
+ end
336
+
337
+ def _section(*args, &block) # :nodoc:
338
+ str = capture_str { section(*args, &block) }
339
+ str.strip!
340
+ str
341
+ end
342
+
343
+ # Execute sed.
344
+ def sed(*args)
345
+ execute 'sed', *args
346
+ chain_proxy
347
+ end
348
+
349
+ def _sed(*args, &block) # :nodoc:
350
+ str = capture_str { sed(*args, &block) }
351
+ str.strip!
352
+ str
353
+ end
354
+
355
+ # Sets the options to on (true) or off (false) as specified. If a block is
356
+ # given then options will only be reset when the block completes.
357
+ def set(options)
358
+ if block_given?
359
+ var = _package_.next_variable_name('set')
360
+ patterns = options.keys.collect {|key| "-e #{key}" }.sort
361
+ writeln %{#{var}=$(set +o | grep #{patterns.join(' ')})}
362
+ end
363
+
364
+ super
365
+
366
+ if block_given?
367
+ yield
368
+ writeln %{eval "$#{var}"}
369
+ end
370
+ chain_proxy
371
+ end
372
+
373
+ def _set(*args, &block) # :nodoc:
374
+ str = capture_str { set(*args, &block) }
375
+ str.strip!
376
+ str
377
+ end
378
+
379
+ # Sets the system time. Must be root for this to succeed.
380
+ def set_date(time=Time.now)
381
+ # date -u <%= time.dup.utc.strftime("%m%d%H%M%Y.%S") %>
382
+ # <% check_status %>
383
+ write "date -u "; write(( time.dup.utc.strftime("%m%d%H%M%Y.%S") ).to_s); write "\n"
384
+ check_status
385
+ chain_proxy
386
+ end
387
+
388
+ def _set_date(*args, &block) # :nodoc:
389
+ str = capture_str { set_date(*args, &block) }
390
+ str.strip!
391
+ str
392
+ end
393
+
394
+ def shebang(options={})
395
+ @shebang = true
396
+ # #!<%= options[:program] || '/bin/sh' %>
397
+ # <% section %>
398
+ #
399
+ # usage="usage: %s: [-h]\n"
400
+ # while getopts "h" opt
401
+ # do
402
+ # case $opt in
403
+ # h ) printf "$usage" $0
404
+ # printf " %s %s\n" "-h" "prints this help"
405
+ # exit 0 ;;
406
+ # \? ) printf "$usage" $0
407
+ # exit 2 ;;
408
+ # esac
409
+ # done
410
+ # shift $(($OPTIND - 1))
411
+ #
412
+ # <% check_status_function %>
413
+ # <% yield if block_given? %>
414
+ #
415
+ # <% if options[:info] %>
416
+ # echo >&2
417
+ # echo "###############################################################################" >&2
418
+ # echo "# $(whoami)@$(hostname):$(pwd):$0" >&2
419
+ #
420
+ # <% end %>
421
+ # <% section " #{target_name} " %>
422
+ #
423
+ #
424
+ write "#!"; write(( options[:program] || '/bin/sh' ).to_s); write "\n"
425
+ section
426
+ write "\n"
427
+ write "usage=\"usage: %s: [-h]\\n\"\n"
428
+ write "while getopts \"h\" opt\n"
429
+ write "do\n"
430
+ write " case $opt in\n"
431
+ write " h ) printf \"$usage\" $0\n"
432
+ write " printf \" %s %s\\n\" \"-h\" \"prints this help\"\n"
433
+ write " exit 0 ;;\n"
434
+ write " \\? ) printf \"$usage\" $0\n"
435
+ write " exit 2 ;;\n"
436
+ write " esac\n"
437
+ write "done\n"
438
+ write "shift $(($OPTIND - 1))\n"
439
+ write "\n"
440
+ check_status_function
441
+ yield if block_given?
442
+ write "\n"
443
+ if options[:info]
444
+ write "echo >&2\n"
445
+ write "echo \"###############################################################################\" >&2\n"
446
+ write "echo \"# $(whoami)@$(hostname):$(pwd):$0\" >&2\n"
447
+ write "\n"
448
+ end
449
+ section " #{target_name} "
450
+ write "\n"
451
+
452
+ chain_proxy
453
+ end
454
+
455
+ def _shebang(*args, &block) # :nodoc:
456
+ str = capture_str { shebang(*args, &block) }
457
+ str.strip!
458
+ str
459
+ end
460
+ end
461
+ end
462
+ end
@@ -0,0 +1,11 @@
1
+ # Generated by Linecook
2
+
3
+ module Linebook
4
+ module Shell
5
+ module Bash
6
+ def shell_path
7
+ @shell_path ||= '/bin/bash'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,147 @@
1
+ # Generated by Linecook
2
+
3
+ module Linebook
4
+ module Shell
5
+ def self.extended(base)
6
+ base.attributes 'linebook/shell'
7
+
8
+ if os = base.attrs['linebook']['os']
9
+ base.helpers os
10
+ end
11
+
12
+ if shell = base.attrs['linebook']['shell']
13
+ base.helpers shell
14
+ end
15
+
16
+ super
17
+ end
18
+
19
+ def directory(target, options={})
20
+ unless_ _directory?(target) do
21
+ mkdir_p target
22
+ end
23
+ chmod options[:mode] || 755, target
24
+ chown options[:owner], options[:group], target
25
+ chain_proxy
26
+ end
27
+
28
+ def _directory(*args, &block) # :nodoc:
29
+ str = capture_str { directory(*args, &block) }
30
+ str.strip!
31
+ str
32
+ end
33
+
34
+ # Installs a file from the package.
35
+ def file(file_name, target, options={})
36
+ source = file_path(file_name, guess_target_name(target))
37
+ options = {:D => true}.merge(options)
38
+ install(source, target, options)
39
+ chain_proxy
40
+ end
41
+
42
+ def _file(*args, &block) # :nodoc:
43
+ str = capture_str { file(*args, &block) }
44
+ str.strip!
45
+ str
46
+ end
47
+
48
+ def group(name, options={})
49
+ unless_ _group?(name) do
50
+ groupadd name
51
+ end
52
+ chain_proxy
53
+ end
54
+
55
+ def _group(*args, &block) # :nodoc:
56
+ str = capture_str { group(*args, &block) }
57
+ str.strip!
58
+ str
59
+ end
60
+
61
+ def package(name, version=nil)
62
+ raise NotImplementedError
63
+ chain_proxy
64
+ end
65
+
66
+ def _package(*args, &block) # :nodoc:
67
+ str = capture_str { package(*args, &block) }
68
+ str.strip!
69
+ str
70
+ end
71
+
72
+ def recipe(recipe_name)
73
+ target_name = File.join('recipes', recipe_name)
74
+ recipe_path = _package_.registry.has_key?(target_name) ?
75
+ target_path(target_name) :
76
+ self.recipe_path(recipe_name, target_name, 0777)
77
+
78
+ dir = target_path File.join('tmp', recipe_name)
79
+ unless_ _directory?(dir) do
80
+ current = target_path('tmp')
81
+ recipe_name.split('/').each do |segment|
82
+ current = File.join(current, segment)
83
+ directory current, :mode => 770
84
+ end
85
+ writeln "#{quote(recipe_path)} $*"
86
+ check_status
87
+ end
88
+ chain_proxy
89
+ end
90
+
91
+ def _recipe(*args, &block) # :nodoc:
92
+ str = capture_str { recipe(*args, &block) }
93
+ str.strip!
94
+ str
95
+ end
96
+
97
+ # Installs a template from the package.
98
+ def template(template_name, target, options={})
99
+ locals = options.delete(:locals) || {'attrs' => attrs}
100
+ source = template_path(template_name, guess_target_name(target), 0600, locals)
101
+ options = {:D => true}.merge(options)
102
+ install(source, target, options)
103
+ chain_proxy
104
+ end
105
+
106
+ def _template(*args, &block) # :nodoc:
107
+ str = capture_str { template(*args, &block) }
108
+ str.strip!
109
+ str
110
+ end
111
+
112
+ def user(name, options={})
113
+ unless_ _user?(name) do
114
+ useradd name, options
115
+ end
116
+ chain_proxy
117
+ end
118
+
119
+ def _user(*args, &block) # :nodoc:
120
+ str = capture_str { user(*args, &block) }
121
+ str.strip!
122
+ str
123
+ end
124
+
125
+ def userdel(name, options={})
126
+ execute 'userdel', name, options
127
+ chain_proxy
128
+ end
129
+
130
+ def _userdel(*args, &block) # :nodoc:
131
+ str = capture_str { userdel(*args, &block) }
132
+ str.strip!
133
+ str
134
+ end
135
+
136
+ def usermod(name, options={})
137
+ execute 'usermod', name, options
138
+ chain_proxy
139
+ end
140
+
141
+ def _usermod(*args, &block) # :nodoc:
142
+ str = capture_str { usermod(*args, &block) }
143
+ str.strip!
144
+ str
145
+ end
146
+ end
147
+ end
@@ -1,6 +1,6 @@
1
1
  module Linebook
2
2
  MAJOR = 0
3
- MINOR = 2
3
+ MINOR = 7
4
4
  TINY = 0
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{TINY}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linebook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 3
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 7
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Chiang
@@ -15,11 +15,25 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-07 00:00:00 -07:00
18
+ date: 2011-04-26 00:00:00 -06:00
19
19
  default_executable:
20
- dependencies: []
21
-
22
- description: Linebook is a distribution module used by Linecook.
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: linecook
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: The standard library for Linecook, and a namespace for distributing Linecook cookbooks.
23
37
  email: simon.a.chiang@gmail.com
24
38
  executables: []
25
39
 
@@ -30,7 +44,15 @@ extra_rdoc_files:
30
44
  - README
31
45
  - License.txt
32
46
  files:
47
+ - attributes/linebook/shell.rb
48
+ - cookbook
33
49
  - lib/linebook.rb
50
+ - lib/linebook/os/linux.rb
51
+ - lib/linebook/os/posix.rb
52
+ - lib/linebook/os/ubuntu.rb
53
+ - lib/linebook/os/unix.rb
54
+ - lib/linebook/shell.rb
55
+ - lib/linebook/shell/bash.rb
34
56
  - lib/linebook/version.rb
35
57
  - History
36
58
  - README
@@ -70,9 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
92
  requirements: []
71
93
 
72
94
  rubyforge_project: ""
73
- rubygems_version: 1.3.7
95
+ rubygems_version: 1.4.2
74
96
  signing_key:
75
97
  specification_version: 3
76
- summary: Cookbooks for Linecook
98
+ summary: The Linecook standard library
77
99
  test_files: []
78
100