linebook 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ module Linebook
2
+ module Os
3
+ module Posix
4
+ class Variable
5
+ attr_accessor :varname
6
+ attr_accessor :default
7
+
8
+ def initialize(varname, default=nil)
9
+ @varname = varname.to_s
10
+ @default = default
11
+ end
12
+
13
+ def lstrip(pattern)
14
+ "${#{varname}##{pattern}}"
15
+ end
16
+
17
+ def llstrip(pattern)
18
+ "${#{varname}###{pattern}}"
19
+ end
20
+
21
+ def rstrip(pattern)
22
+ "${#{varname}%#{pattern}}"
23
+ end
24
+
25
+ def rrstrip(pattern)
26
+ "${#{varname}%%#{pattern}}"
27
+ end
28
+
29
+ def sub(pattern, replacement)
30
+ "${#{varname}/#{pattern}/#{replacement}}"
31
+ end
32
+
33
+ def gsub(pattern, replacement)
34
+ "${#{varname}//#{pattern}/#{replacement}}"
35
+ end
36
+
37
+ def length
38
+ "${##{varname}}"
39
+ end
40
+
41
+ def substring(offset, length=nil)
42
+ length ? "${#{varname}:#{offset}:#{length}}": "${#{varname}:#{offset}}"
43
+ end
44
+
45
+ def eq(another)
46
+ "[ #{self} -eq #{another} ]"
47
+ end
48
+
49
+ def ne(another)
50
+ "[ #{self} -ne #{another} ]"
51
+ end
52
+
53
+ def gt(another)
54
+ "[ #{self} -gt #{another} ]"
55
+ end
56
+
57
+ def lt(another)
58
+ "[ #{self} -lt #{another} ]"
59
+ end
60
+
61
+ def ==(another)
62
+ "[ #{self} = #{another} ]"
63
+ end
64
+
65
+ # def !=(another)
66
+ # "[ #{self} != #{another} ]"
67
+ # end
68
+
69
+ def >(another)
70
+ "[ #{self} > #{another} ]"
71
+ end
72
+
73
+ def <(another)
74
+ "[ #{self} < #{another} ]"
75
+ end
76
+
77
+ def null?
78
+ "[ -z #{self} ]"
79
+ end
80
+
81
+ def not_null?
82
+ "[ -n #{self} ]"
83
+ end
84
+
85
+ def to_s
86
+ default.nil? ? "$#{varname}" : "${#{varname}:-#{default}}"
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -8,7 +8,7 @@ module Linebook
8
8
 
9
9
  # Installs a package using apt-get.
10
10
  def package(name, version=nil, options={:q => true, :y => true})
11
- name = "#{name}=#{version}" unless blank?(version)
11
+ name = "#{name}=#{version}" unless version.to_s.strip.empty?
12
12
  execute "apt-get install", name, options
13
13
  chain_proxy
14
14
  end
@@ -18,9 +18,9 @@ module Linebook
18
18
 
19
19
  def directory(target, options={})
20
20
  unless_ _directory?(target) do
21
- mkdir_p target
21
+ mkdir '-p', target
22
22
  end
23
- chmod options[:mode] || 755, target
23
+ chmod options[:mode] || 0755, target
24
24
  chown options[:owner], options[:group], target
25
25
  chain_proxy
26
26
  end
@@ -80,7 +80,7 @@ module Linebook
80
80
  current = target_path('tmp')
81
81
  recipe_name.split('/').each do |segment|
82
82
  current = File.join(current, segment)
83
- directory current, :mode => 770
83
+ directory current, :mode => 0770
84
84
  end
85
85
  writeln "#{quote(recipe_path)} $*"
86
86
  check_status
@@ -1,6 +1,6 @@
1
1
  module Linebook
2
2
  MAJOR = 0
3
- MINOR = 7
3
+ MINOR = 8
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: 3
5
- prerelease:
4
+ hash: 63
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
8
+ - 8
9
9
  - 0
10
- version: 0.7.0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Chiang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-26 00:00:00 -06:00
18
+ date: 2011-05-23 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,14 +26,14 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 15
29
+ hash: 11
30
30
  segments:
31
31
  - 1
32
- - 0
33
- version: "1.0"
32
+ - 2
33
+ version: "1.2"
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
- description: The standard library for Linecook, and a namespace for distributing Linecook cookbooks.
36
+ description: The standard library for Linecook, providing helpers for POSIX and Linux.
37
37
  email: simon.a.chiang@gmail.com
38
38
  executables: []
39
39
 
@@ -43,20 +43,32 @@ extra_rdoc_files:
43
43
  - History
44
44
  - README
45
45
  - License.txt
46
+ - HowTo/Switch Users
47
+ - HowTo/Setup/Debian
48
+ - HowTo/Setup/openSUSE
49
+ - HowTo/Setup/SLES
50
+ - HowTo/Setup/Ubuntu
46
51
  files:
47
52
  - attributes/linebook/shell.rb
48
53
  - cookbook
49
54
  - lib/linebook.rb
50
55
  - lib/linebook/os/linux.rb
56
+ - lib/linebook/os/linux/utilities.rb
51
57
  - lib/linebook/os/posix.rb
58
+ - lib/linebook/os/posix/utilities.rb
59
+ - lib/linebook/os/posix/variable.rb
52
60
  - lib/linebook/os/ubuntu.rb
53
- - lib/linebook/os/unix.rb
54
61
  - lib/linebook/shell.rb
55
62
  - lib/linebook/shell/bash.rb
56
63
  - lib/linebook/version.rb
57
64
  - History
58
65
  - README
59
66
  - License.txt
67
+ - HowTo/Switch Users
68
+ - HowTo/Setup/Debian
69
+ - HowTo/Setup/openSUSE
70
+ - HowTo/Setup/SLES
71
+ - HowTo/Setup/Ubuntu
60
72
  has_rdoc: true
61
73
  homepage: http://rubygems.org/gems/linebook
62
74
  licenses: []
@@ -92,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
104
  requirements: []
93
105
 
94
106
  rubyforge_project: ""
95
- rubygems_version: 1.4.2
107
+ rubygems_version: 1.3.7
96
108
  signing_key:
97
109
  specification_version: 3
98
- summary: The Linecook standard library
110
+ summary: The standard library for Linecook
99
111
  test_files: []
100
112
 
@@ -1,462 +0,0 @@
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