Module: Linebook::Shell

Defined in:
lib/linebook/shell.rb,
lib/linebook/shell/bash.rb

Defined Under Namespace

Modules: Bash

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/linebook/shell.rb', line 5

def self.extended(base)
  base.attributes 'linebook/shell'
  
  if os = base.attrs['linebook']['os']
    base.helpers os
  end
  
  if shell = base.attrs['linebook']['shell']
    base.helpers shell
  end
  
  super
end

Instance Method Details

#_directory(*args, &block) ⇒ Object

:nodoc:



28
29
30
31
32
# File 'lib/linebook/shell.rb', line 28

def _directory(*args, &block) # :nodoc:
  str = capture_str { directory(*args, &block) }
  str.strip!
  str
end

#_file(*args, &block) ⇒ Object

:nodoc:



42
43
44
45
46
# File 'lib/linebook/shell.rb', line 42

def _file(*args, &block) # :nodoc:
  str = capture_str { file(*args, &block) }
  str.strip!
  str
end

#_group(*args, &block) ⇒ Object

:nodoc:



55
56
57
58
59
# File 'lib/linebook/shell.rb', line 55

def _group(*args, &block) # :nodoc:
  str = capture_str { group(*args, &block) }
  str.strip!
  str
end

#_package(*args, &block) ⇒ Object

:nodoc:



66
67
68
69
70
# File 'lib/linebook/shell.rb', line 66

def _package(*args, &block) # :nodoc:
  str = capture_str { package(*args, &block) }
  str.strip!
  str
end

#_recipe(*args, &block) ⇒ Object

:nodoc:



91
92
93
94
95
# File 'lib/linebook/shell.rb', line 91

def _recipe(*args, &block) # :nodoc:
  str = capture_str { recipe(*args, &block) }
  str.strip!
  str
end

#_template(*args, &block) ⇒ Object

:nodoc:



106
107
108
109
110
# File 'lib/linebook/shell.rb', line 106

def _template(*args, &block) # :nodoc:
  str = capture_str { template(*args, &block) }
  str.strip!
  str
end

#_user(*args, &block) ⇒ Object

:nodoc:



119
120
121
122
123
# File 'lib/linebook/shell.rb', line 119

def _user(*args, &block) # :nodoc:
  str = capture_str { user(*args, &block) }
  str.strip!
  str
end

#_userdel(*args, &block) ⇒ Object

:nodoc:



130
131
132
133
134
# File 'lib/linebook/shell.rb', line 130

def _userdel(*args, &block) # :nodoc:
  str = capture_str { userdel(*args, &block) }
  str.strip!
  str
end

#_usermod(*args, &block) ⇒ Object

:nodoc:



141
142
143
144
145
# File 'lib/linebook/shell.rb', line 141

def _usermod(*args, &block) # :nodoc:
  str = capture_str { usermod(*args, &block) }
  str.strip!
  str
end

#directory(target, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/linebook/shell.rb', line 19

def directory(target, options={})
  unless_ _directory?(target) do 
    mkdir '-p', target
  end 
  chmod options[:mode] || 0755, target
  chown options[:owner], options[:group], target
  chain_proxy
end

#file(file_name, target, options = {}) ⇒ Object

Installs a file from the package.



35
36
37
38
39
40
# File 'lib/linebook/shell.rb', line 35

def file(file_name, target, options={})
  source = file_path(file_name, guess_target_name(target))
  options = {:D => true}.merge(options)
  install(source, target, options)
  chain_proxy
end

#group(name, options = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/linebook/shell.rb', line 48

def group(name, options={})
  unless_ _group?(name) do
    groupadd name
  end
  chain_proxy
end

#package(name, version = nil) ⇒ Object

Raises:

  • (NotImplementedError)


61
62
63
64
# File 'lib/linebook/shell.rb', line 61

def package(name, version=nil)
  raise NotImplementedError
  chain_proxy
end

#recipe(recipe_name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/linebook/shell.rb', line 72

def recipe(recipe_name)
  target_name = File.join('recipes', recipe_name)
  recipe_path = _package_.registry.has_key?(target_name) ? 
    target_path(target_name) : 
    self.recipe_path(recipe_name, target_name, 0777)

  dir = target_path File.join('tmp', recipe_name)
  unless_ _directory?(dir) do
    current = target_path('tmp')
    recipe_name.split('/').each do |segment|
      current = File.join(current, segment)
      directory current, :mode => 0770
    end
    writeln "#{quote(recipe_path)} $*"
    check_status
  end
  chain_proxy
end

#template(template_name, target, options = {}) ⇒ Object

Installs a template from the package.



98
99
100
101
102
103
104
# File 'lib/linebook/shell.rb', line 98

def template(template_name, target, options={})
  locals = options.delete(:locals) || {'attrs' => attrs}
  source = template_path(template_name, guess_target_name(target), 0600, locals)
  options = {:D => true}.merge(options)
  install(source, target, options)
  chain_proxy
end

#user(name, options = {}) ⇒ Object



112
113
114
115
116
117
# File 'lib/linebook/shell.rb', line 112

def user(name, options={})
  unless_ _user?(name) do
    useradd name, options
  end
  chain_proxy
end

#userdel(name, options = {}) ⇒ Object



125
126
127
128
# File 'lib/linebook/shell.rb', line 125

def userdel(name, options={})
  execute 'userdel', name, options
  chain_proxy
end

#usermod(name, options = {}) ⇒ Object



136
137
138
139
# File 'lib/linebook/shell.rb', line 136

def usermod(name, options={})
  execute 'usermod', name, options
  chain_proxy
end