Module: VScripts::Util::LocalSystem
- Included in:
- VScripts::Util
- Defined in:
- lib/vscripts/util/local_system.rb
Overview
Local system functions library.
Instance Method Summary collapse
-
#ensure_file_content(file, body) ⇒ Object
Ensures the specified file has the specified content.
-
#ensure_file_dir(file) ⇒ Object
Creates the directory for the specified file.
-
#external_dns ⇒ String
Tries to get the reverse dns.
-
#hostname_path ⇒ String
The hostname file path.
-
#hosts_path ⇒ String
The hosts file path.
-
#local_domain_name ⇒ String
The local domain name.
-
#local_fqdn ⇒ String
The local fully qualified domain.
-
#local_host_name ⇒ String
The local host name.
-
#write_file(file, body) ⇒ Object
Writes to a file.
Instance Method Details
#ensure_file_content(file, body) ⇒ Object
Ensures the specified file has the specified content
64 65 66 67 68 |
# File 'lib/vscripts/util/local_system.rb', line 64 def ensure_file_content(file, body) write = write_file(file, body) read = IO.read(file) read == body || write end |
#ensure_file_dir(file) ⇒ Object
Creates the directory for the specified file
44 45 46 47 |
# File 'lib/vscripts/util/local_system.rb', line 44 def ensure_file_dir(file) path = File.dirname(file) `mkdir -p #{path}` end |
#external_dns ⇒ String
Tries to get the reverse dns
34 35 36 37 38 39 40 |
# File 'lib/vscripts/util/local_system.rb', line 34 def external_dns ext_ip = `wget -q -O - checkip.dyndns.org \ | sed -e 's/[^[:digit:]|.]//g'` `dig +short -x #{ext_ip}`.strip rescue false end |
#hostname_path ⇒ String
Returns the hostname file path.
11 12 13 |
# File 'lib/vscripts/util/local_system.rb', line 11 def hostname_path '/etc/hostname' end |
#hosts_path ⇒ String
Returns the hosts file path.
6 7 8 |
# File 'lib/vscripts/util/local_system.rb', line 6 def hosts_path '/etc/hosts' end |
#local_domain_name ⇒ String
Returns the local domain name.
26 27 28 29 30 |
# File 'lib/vscripts/util/local_system.rb', line 26 def local_domain_name `dnsdomainname`.strip rescue 'local' end |
#local_fqdn ⇒ String
Returns the local fully qualified domain.
16 17 18 |
# File 'lib/vscripts/util/local_system.rb', line 16 def local_fqdn `hostname -f`.strip end |
#local_host_name ⇒ String
Returns the local host name.
21 22 23 |
# File 'lib/vscripts/util/local_system.rb', line 21 def local_host_name `hostname`.strip end |
#write_file(file, body) ⇒ Object
Writes to a file
52 53 54 55 56 57 58 59 |
# File 'lib/vscripts/util/local_system.rb', line 52 def write_file(file, body) ensure_file_dir(file) File.open(file, 'w') do |newfile| newfile.write(body) end rescue Errno::EACCES abort "FATAL: You need to be root in order to write to #{file}" end |