Class: DnsOne::Setup

Inherits:
Object show all
Defined in:
lib/dns_one/setup.rb

Constant Summary collapse

SYSTEMD_SERVICES_DIR =
"/lib/systemd/system/"
SERVICE_NAME =
'dnsone'
SYSTEMD_SERVICE_FILE =
"#{SYSTEMD_SERVICES_DIR}/#{SERVICE_NAME}.service"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSetup

Returns a new instance of Setup.



8
9
10
11
12
13
# File 'lib/dns_one/setup.rb', line 8

def initialize
    @thisdir = File.join File.dirname(__FILE__)
    DnsOne.new # just to load the configuration 
               # TODO: move conf to own class
    @conf = Global.conf
end

Instance Attribute Details

#confObject

Returns the value of attribute conf.



6
7
8
# File 'lib/dns_one/setup.rb', line 6

def conf
  @conf
end

Instance Method Details

#removeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dns_one/setup.rb', line 24

def remove
    unless is_setup?
        die "Nothing to remove. Exiting."
    end

    # SYSTEMD_SERVICE_FILE
    if Util.has_systemd? and File.exist? SYSTEMD_SERVICE_FILE 
        Util.run "systemctl stop #{SERVICE_NAME}" 
        Util.run "systemctl disable #{SERVICE_NAME}" 
        File.delete SYSTEMD_SERVICE_FILE
    end
    
    # conf_file
    if File.exists? conf.conf_file
        if confirm? "Delete #{conf.conf_file}?"
            FileUtils.rm conf.conf_file
        end
    end
    
    # work_dir
    if conf.work_dir == '/var/local/dnsone' # Only deletes if path matches the hardcoded one
        if Dir.exists? conf.work_dir
            if confirm? "Delete #{conf.work_dir}?"
                FileUtils.rm_rf conf.work_dir
            end
        end
    end

    puts "Removed."
end

#setupObject



15
16
17
18
19
20
21
22
# File 'lib/dns_one/setup.rb', line 15

def setup
    check_reqs
    add_user
    mkdirs
    copy_sample_conf
    install_systemd_service
    setup_finished_msg
end