Module: Helpers
- Defined in:
- lib/spior/helpers.rb
Overview
Various function for Spior
Defined Under Namespace
Classes: Exec, NewFile, NewSystemd
Class Method Summary
collapse
Class Method Details
.auth? ⇒ Boolean
9
10
11
12
13
|
# File 'lib/spior/helpers.rb', line 9
def self.auth?
return :root if Process.uid == '0'
return :doas if File.exist?('/bin/doas') || File.exist?('/sbin/doas')
return :sudo if File.exist?('/bin/sudo') || File.exist?('/sbin/sudo')
end
|
.cmd(command) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/spior/helpers.rb', line 15
def self.cmd(command)
case auth?
when :root
syscmd(command)
when :doas
syscmd("doas #{command}")
when :sudo
syscmd("sudo #{command}")
end
end
|
.mv(src, dest) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/spior/helpers.rb', line 34
def self.mv(src, dest)
if Process::Sys.getuid == '0'
FileUtils.mv(src, dest)
FileUtils.chmod 0644, dest
else
cmd("mv #{src} #{dest}")
cmd("chmod 644 #{dest}")
end
end
|
.syscmd(cmd) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/spior/helpers.rb', line 26
def self.syscmd(cmd)
Open3.popen2e(cmd) do |_, stdout_and_stderr, wait_thr|
puts stdout_and_stderr.gets while stdout_and_stderr.gets
exit_status = wait_thr.value
raise "Error, Running #{cmd}" unless exit_status.success?
end
end
|