/
inst_install_inf.rb
86 lines (69 loc) · 2.14 KB
/
inst_install_inf.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require "yast"
require "network/install_inf_convertor"
require "installation/dialogs/registration_url_dialog"
module Yast
class InstInstallInfClient < Client
VALID_URL_SCHEMES = ["http", "https"].freeze
include Yast::Logger
include Yast::I18n
Yast.import "Linuxrc"
Yast.import "Wizard"
Yast.import "WFM"
def main
textdomain "installation"
InstallInfConvertor.instance.write_netconfig
return :next if Mode.auto
Yast::Wizard.CreateDialog if separate_wizard_needed?
regurl = Linuxrc.InstallInf("regurl")
fix_regurl!(regurl) if need_fix?(regurl)
Yast::Wizard.CloseDialog if separate_wizard_needed?
:next
end
private
# Checks if the given url is invalid and needs to be fixed.
#
# @param url [String]
# @return [Boolean] return true if not nil and invalid.
def need_fix?(url)
url && !valid_url?(url)
end
# Shows a dialog allowing the user to modify the invalid URL, modifying the
# /etc/install.inf file with the new value. In case of cancelled or empty,
# the URL will be completely removed.
#
# @param regurl [String]
def fix_regurl!(regurl)
while need_fix?(regurl)
new_url = ::Installation::RegistrationURLDialog.new(regurl).run
case new_url
when :cancel
if Popup.YesNo(_("If you decide to cancel, the custom URL\n" \
"will be completely ignored.\n\n" \
"Really cancel URL modification?"))
regurl = nil
end
when "",
regurl = nil
else
regurl = new_url
end
end
SCR.Write(path(".etc.install_inf.regurl"), regurl)
SCR.Write(path(".etc.install_inf"), nil) # Flush the cache
Linuxrc.ResetInstallInf
end
# Check if the given URI is valid or not
#
# @param url [String]
# @return [Boolean]
def valid_url?(url)
VALID_URL_SCHEMES.include?(URI(url).scheme)
rescue URI::InvalidURIError
false
end
# Returns whether we need/ed to create new UI Wizard
def separate_wizard_needed?
Yast::Mode.normal
end
end
end