class Spior::Copy
Public Class Methods
new()
click to toggle source
# File lib/spior/copy.rb, line 5 def initialize @cp = Helpers::Exec.new("cp -a") @files = [] search_conf_dir config_files list end
Public Instance Methods
restore()
click to toggle source
# File lib/spior/copy.rb, line 23 def restore @files.each { |f| backup = "#{f}_backup" if File.exist? backup Msg.p "#{f} restored" @cp.run("#{backup} #{f}") end } end
save()
click to toggle source
# File lib/spior/copy.rb, line 13 def save @files.each { |f| backup = "#{f}_backup" if ! File.exist? backup Msg.p "#{f} saved" @cp.run("#{f} #{backup}") end } end
Private Instance Methods
add(file)
click to toggle source
# File lib/spior/copy.rb, line 48 def add(file) @files << file if File.exist? file end
add_file(target)
click to toggle source
# File lib/spior/copy.rb, line 66 def add_file(target) @cp.run("#{@config_file} #{target}") Msg.p "File #{@config_file} has been successfully copied at #{target}" end
check_hash(src, target)
click to toggle source
# File lib/spior/copy.rb, line 78 def check_hash(src, target) return if not File.exist?(target) sha256conf = Digest::SHA256.file src sha256target = Digest::SHA256.file target sha256conf === sha256target end
config_files()
click to toggle source
# File lib/spior/copy.rb, line 35 def config_files copy_file("#{@conf_dir}/ipt_mod.conf", "/etc/modules-load.d/ipt_mod.conf") end
copy_file(conf, target)
click to toggle source
# File lib/spior/copy.rb, line 71 def copy_file(conf, target) @config_file = conf add_file target if ! File.exist? target return if check_hash(@config_file, target) add_file target end
list()
click to toggle source
# File lib/spior/copy.rb, line 39 def list add "/etc/resolv.conf" add "/etc/tor/torrc" add "/etc/systemd/resolved.conf" add "/var/lib/iptables/rules-save" # gentoo add "/etc/iptables/iptables.rules" # arch add "/etc/iptables/rules.v4" # debian end
previous_copy(target)
click to toggle source
# File lib/spior/copy.rb, line 60 def previous_copy(target) backup=`ls #{target}.backup-* | head -1`.chomp return false if ! File.exist? backup check_hash(backup, target) end
search_conf_dir()
click to toggle source
# File lib/spior/copy.rb, line 52 def search_conf_dir # ebuild on gentoo copy the ext dir at lib/ext @conf_dir = File.expand_path('../..' + '/lib/ext', __dir__) if ! Dir.exist?(@conf_dir) @conf_dir = File.expand_path('../..' + '/ext', __dir__) end end