Module: Linebook::Os::Linux::Utilities
- Included in:
- Linebook::Os::Linux
- Defined in:
- lib/linebook/os/linux/utilities.rb
Instance Method Summary collapse
-
#_group?(*args, &block) ⇒ Boolean
:nodoc:.
-
#_groupadd(*args, &block) ⇒ Object
:nodoc:.
-
#_groupdel(*args, &block) ⇒ Object
:nodoc:.
-
#_groupmod(*args, &block) ⇒ Object
:nodoc:.
-
#_groups(*args, &block) ⇒ Object
:nodoc:.
-
#_gzip(*args, &block) ⇒ Object
:nodoc:.
-
#_hostname(*args, &block) ⇒ Object
:nodoc:.
-
#_install(*args, &block) ⇒ Object
:nodoc:.
-
#_md5sum(*args, &block) ⇒ Object
:nodoc:.
-
#_mktemp(*args, &block) ⇒ Object
:nodoc:.
-
#_su(*args, &block) ⇒ Object
:nodoc:.
-
#_tar(*args, &block) ⇒ Object
:nodoc:.
-
#_user?(*args, &block) ⇒ Boolean
:nodoc:.
-
#_useradd(*args, &block) ⇒ Object
:nodoc:.
-
#_userdel(*args, &block) ⇒ Object
:nodoc:.
-
#_usermod(*args, &block) ⇒ Object
:nodoc:.
-
#group?(name) ⇒ Boolean
Returns true if the group exists as determined by checking /etc/group.
-
#groupadd(group, options = {}) ⇒ Object
Create a new group.
-
#groupdel(group) ⇒ Object
Delete a group.
-
#groupmod(group, options = {}) ⇒ Object
Modify a group.
-
#groups(user) ⇒ Object
Display a group.
-
#gzip(*files) ⇒ Object
Compress or expand files.
-
#hostname(name = nil) ⇒ Object
Show or set the system’s host name.
-
#install(source, dest, options = {}) ⇒ Object
Copy files and set attributes.
-
#md5sum(*files) ⇒ Object
Generate or check MD5 message digests.
-
#mktemp(template, options = {}) ⇒ Object
Make temporary file name (unique) [Spec].
-
#su(user = 'root', options = {}) ⇒ Object
Switches to the specified user for the duration of a block.
-
#tar(key, *files) ⇒ Object
File archiver.
-
#user?(name) ⇒ Boolean
Returns true if the user exists as determined by id.
-
#useradd(login, options = {}) ⇒ Object
Create a new user or update default new user information.
-
#userdel(login, options = {}) ⇒ Object
Delete a user account and related files.
-
#usermod(login, options = {}) ⇒ Object
Modify a user account.
Instance Method Details
#_group?(*args, &block) ⇒ Boolean
:nodoc:
14 15 16 17 18 |
# File 'lib/linebook/os/linux/utilities.rb', line 14 def _group?(*args, &block) # :nodoc: str = capture_str { group?(*args, &block) } str.strip! str end |
#_groupadd(*args, &block) ⇒ Object
:nodoc:
27 28 29 30 31 |
# File 'lib/linebook/os/linux/utilities.rb', line 27 def _groupadd(*args, &block) # :nodoc: str = capture_str { groupadd(*args, &block) } str.strip! str end |
#_groupdel(*args, &block) ⇒ Object
:nodoc:
40 41 42 43 44 |
# File 'lib/linebook/os/linux/utilities.rb', line 40 def _groupdel(*args, &block) # :nodoc: str = capture_str { groupdel(*args, &block) } str.strip! str end |
#_groupmod(*args, &block) ⇒ Object
:nodoc:
53 54 55 56 57 |
# File 'lib/linebook/os/linux/utilities.rb', line 53 def _groupmod(*args, &block) # :nodoc: str = capture_str { groupmod(*args, &block) } str.strip! str end |
#_groups(*args, &block) ⇒ Object
:nodoc:
66 67 68 69 70 |
# File 'lib/linebook/os/linux/utilities.rb', line 66 def _groups(*args, &block) # :nodoc: str = capture_str { groups(*args, &block) } str.strip! str end |
#_gzip(*args, &block) ⇒ Object
:nodoc:
79 80 81 82 83 |
# File 'lib/linebook/os/linux/utilities.rb', line 79 def _gzip(*args, &block) # :nodoc: str = capture_str { gzip(*args, &block) } str.strip! str end |
#_hostname(*args, &block) ⇒ Object
:nodoc:
92 93 94 95 96 |
# File 'lib/linebook/os/linux/utilities.rb', line 92 def _hostname(*args, &block) # :nodoc: str = capture_str { hostname(*args, &block) } str.strip! str end |
#_install(*args, &block) ⇒ Object
:nodoc:
105 106 107 108 109 |
# File 'lib/linebook/os/linux/utilities.rb', line 105 def _install(*args, &block) # :nodoc: str = capture_str { install(*args, &block) } str.strip! str end |
#_md5sum(*args, &block) ⇒ Object
:nodoc:
118 119 120 121 122 |
# File 'lib/linebook/os/linux/utilities.rb', line 118 def _md5sum(*args, &block) # :nodoc: str = capture_str { md5sum(*args, &block) } str.strip! str end |
#_mktemp(*args, &block) ⇒ Object
:nodoc:
131 132 133 134 135 |
# File 'lib/linebook/os/linux/utilities.rb', line 131 def _mktemp(*args, &block) # :nodoc: str = capture_str { mktemp(*args, &block) } str.strip! str end |
#_su(*args, &block) ⇒ Object
:nodoc:
151 152 153 154 155 |
# File 'lib/linebook/os/linux/utilities.rb', line 151 def _su(*args, &block) # :nodoc: str = capture_str { su(*args, &block) } str.strip! str end |
#_tar(*args, &block) ⇒ Object
:nodoc:
163 164 165 166 167 |
# File 'lib/linebook/os/linux/utilities.rb', line 163 def _tar(*args, &block) # :nodoc: str = capture_str { tar(*args, &block) } str.strip! str end |
#_user?(*args, &block) ⇒ Boolean
:nodoc:
176 177 178 179 180 |
# File 'lib/linebook/os/linux/utilities.rb', line 176 def _user?(*args, &block) # :nodoc: str = capture_str { user?(*args, &block) } str.strip! str end |
#_useradd(*args, &block) ⇒ Object
:nodoc:
189 190 191 192 193 |
# File 'lib/linebook/os/linux/utilities.rb', line 189 def _useradd(*args, &block) # :nodoc: str = capture_str { useradd(*args, &block) } str.strip! str end |
#_userdel(*args, &block) ⇒ Object
:nodoc:
205 206 207 208 209 |
# File 'lib/linebook/os/linux/utilities.rb', line 205 def _userdel(*args, &block) # :nodoc: str = capture_str { userdel(*args, &block) } str.strip! str end |
#_usermod(*args, &block) ⇒ Object
:nodoc:
218 219 220 221 222 |
# File 'lib/linebook/os/linux/utilities.rb', line 218 def _usermod(*args, &block) # :nodoc: str = capture_str { usermod(*args, &block) } str.strip! str end |
#group?(name) ⇒ Boolean
Returns true if the group exists as determined by checking /etc/group.
8 9 10 11 12 |
# File 'lib/linebook/os/linux/utilities.rb', line 8 def group?(name) # grep "^<%= name %>:" /etc/group >/dev/null 2>&1 write "grep \"^"; write(( name ).to_s); write ":\" /etc/group >/dev/null 2>&1" chain_proxy end |
#groupadd(group, options = {}) ⇒ Object
Create a new group. [Spec]
22 23 24 25 |
# File 'lib/linebook/os/linux/utilities.rb', line 22 def groupadd(group, ={}) execute 'groupadd', group, chain_proxy end |
#groupdel(group) ⇒ Object
Delete a group. [Spec]
35 36 37 38 |
# File 'lib/linebook/os/linux/utilities.rb', line 35 def groupdel(group) execute 'groupdel', group chain_proxy end |
#groupmod(group, options = {}) ⇒ Object
Modify a group. [Spec]
48 49 50 51 |
# File 'lib/linebook/os/linux/utilities.rb', line 48 def groupmod(group, ={}) execute 'groupmod', group, chain_proxy end |
#groups(user) ⇒ Object
Display a group. [Spec]
61 62 63 64 |
# File 'lib/linebook/os/linux/utilities.rb', line 61 def groups(user) execute 'groups', user chain_proxy end |
#gzip(*files) ⇒ Object
Compress or expand files. [Spec]
74 75 76 77 |
# File 'lib/linebook/os/linux/utilities.rb', line 74 def gzip(*files) execute 'gzip', *files chain_proxy end |
#hostname(name = nil) ⇒ Object
Show or set the system’s host name. [Spec]
87 88 89 90 |
# File 'lib/linebook/os/linux/utilities.rb', line 87 def hostname(name=nil) execute 'hostname', name chain_proxy end |
#install(source, dest, options = {}) ⇒ Object
Copy files and set attributes. [Spec]
100 101 102 103 |
# File 'lib/linebook/os/linux/utilities.rb', line 100 def install(source, dest, ={}) execute 'install', source, dest, chain_proxy end |
#md5sum(*files) ⇒ Object
Generate or check MD5 message digests. [Spec]
113 114 115 116 |
# File 'lib/linebook/os/linux/utilities.rb', line 113 def md5sum(*files) execute 'md5sum', *files chain_proxy end |
#mktemp(template, options = {}) ⇒ Object
Make temporary file name (unique) [Spec]
126 127 128 129 |
# File 'lib/linebook/os/linux/utilities.rb', line 126 def mktemp(template, ={}) execute 'mktemp', template, chain_proxy end |
#su(user = 'root', options = {}) ⇒ Object
Switches to the specified user for the duration of a block. The current ENV and pwd are preserved. [Spec]
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/linebook/os/linux/utilities.rb', line 140 def su(user='root', ={}) path = capture_script() do functions.each_value do |function| writeln function end yield end execute 'su', user, path, :m => true chain_proxy end |
#tar(key, *files) ⇒ Object
File archiver. [Spec]
158 159 160 161 |
# File 'lib/linebook/os/linux/utilities.rb', line 158 def tar(key, *files) execute 'tar', key, files chain_proxy end |
#user?(name) ⇒ Boolean
Returns true if the user exists as determined by id.
170 171 172 173 174 |
# File 'lib/linebook/os/linux/utilities.rb', line 170 def user?(name) # id <%= quote(name) %> >/dev/null 2>&1 write "id "; write(( quote(name) ).to_s); write " >/dev/null 2>&1" chain_proxy end |
#useradd(login, options = {}) ⇒ Object
Create a new user or update default new user information. [Spec]
184 185 186 187 |
# File 'lib/linebook/os/linux/utilities.rb', line 184 def useradd(login, ={}) execute 'useradd', login, chain_proxy end |
#userdel(login, options = {}) ⇒ Object
Delete a user account and related files. [Spec]
197 198 199 200 201 202 203 |
# File 'lib/linebook/os/linux/utilities.rb', line 197 def userdel(login, ={}) # TODO - look into other things that might need to happen before: # * kill processes belonging to user # * remove at/cron/print jobs etc. execute 'userdel', login, chain_proxy end |
#usermod(login, options = {}) ⇒ Object
Modify a user account. [Spec]
213 214 215 216 |
# File 'lib/linebook/os/linux/utilities.rb', line 213 def usermod(login, ={}) execute 'usermod', login, chain_proxy end |