-
Notifications
You must be signed in to change notification settings - Fork 6
/
OneClickInstallCLI.rb
212 lines (188 loc) · 6.29 KB
/
OneClickInstallCLI.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# encoding: utf-8
# Command line interface for One Click Install
module Yast
class OneClickInstallCLIClient < Client
def main
textdomain "oneclickinstall"
Yast.import "OneClickInstall"
Yast.import "OneClickInstallWorkerFunctions"
Yast.import "CommandLine"
Yast.import "HTTP"
Yast.import "FTP"
@cmdline = {
"help" => _("One Click Install Command Line Installer"),
"id" => "OneClickInstall",
"actions" => {
"prepareinstall" => {
"help" => _("Processes a YMP file, ready for installation"),
"handler" => fun_ref(
method(:PrepareInstallHandler),
"boolean (map <string, string>)"
)
},
"doinstall" => {
"help" => _("Processes a YMP file, ready for installation"),
"handler" => fun_ref(
method(:DoInstallHandler),
"boolean (map <string, string>)"
)
}
},
"options" => {
"url" => {
"help" => _("URL of .ymp file"),
"type" => "string"
},
"targetfile" => {
"help" => _("File to put internal representation of YMP into"),
"type" => "string"
},
"instructionsfile" => {
"help" => _(
"File containing internal representation of <b>One Click Install</b> instructions"
),
"type" => "string"
}
},
"mappings" => {
"prepareinstall" => ["url", "targetfile"],
"doinstall" => ["instructionsfile"]
}
}
@ret = CommandLine.Run(@cmdline)
deep_copy(@ret)
end
def PrepareInstall(ympFile, tempFile)
OneClickInstall.Load(ympFile)
if !OneClickInstall.HaveAnythingToDo
Builtins.y2error("Nothing to do specified in the YMP file")
CommandLine.Print(_("Error: Nothing to do specified in the YMP file."))
return false
end
if OneClickInstall.HaveRepositories
CommandLine.Print(
_("If you continue, the following repositories will be subscribed:")
)
Builtins.foreach(OneClickInstall.GetRequiredRepositories) do |repository|
CommandLine.Print(Ops.add("\t* ", repository))
end
end
if OneClickInstall.HaveSoftware
CommandLine.Print(
_(
"If you continue, the following software packages will be installed:"
)
)
Builtins.foreach(OneClickInstall.GetRequiredSoftware) do |software|
CommandLine.Print(Ops.add("\t* ", software))
end
end
OneClickInstall.ToXML(tempFile)
true
end
def PrepareInstallHandler(options)
options = deep_copy(options)
#trick ncurses
url = Ops.get(options, "url", "")
tempFile = Ops.get(options, "targetfile", "")
if Builtins.substring(url, 0, 1) != "/"
url = OneClickInstallWorkerFunctions.GrabFile(url)
end
if url == nil
Builtins.y2error(
"Unable to retrieve YMP at %1",
Ops.get(options, "url", "")
)
CommandLine.Print(
Builtins.sformat(
_("Unable to retrieve YMP at %1"),
Ops.get(options, "url", "")
)
)
return false
end
PrepareInstall(url, tempFile)
end
def DoInstall(xmlfile)
OneClickInstall.FromXML(xmlfile)
if OneClickInstall.HaveRepositoriesToInstall
CommandLine.Print(_("Adding Repositories..."))
end
success = OneClickInstallWorkerFunctions.AddRepositories(
OneClickInstall.GetRequiredRepositories
)
if !success
Builtins.y2error("Unable to add repositories")
CommandLine.Print(_("Error: Unable to add repositories"))
return false
end
#Remove any removals
if OneClickInstall.HaveRemovalsToInstall
CommandLine.Print(_("Removing Packages..."))
success = OneClickInstallWorkerFunctions.RemovePackages(
OneClickInstall.GetRequiredRemoveSoftware
)
end
if !success
Builtins.y2error("Unable to remove packages")
CommandLine.Print(_("Error: Unable to remove packages"))
return false
end
#if that was successful now try and install the patterns
if OneClickInstall.HavePatternsToInstall
CommandLine.Print(_("Installing Patterns..."))
success = OneClickInstallWorkerFunctions.InstallPatterns(
OneClickInstall.GetRequiredPatterns
)
end
if !success
Builtins.y2error("Unable to install patterns")
CommandLine.Print(_("Error: Unable to install patterns"))
return false
end
#if that was successful now try and install the packages
if OneClickInstall.HavePackagesToInstall
CommandLine.Print(_("Installing Packages..."))
success = OneClickInstallWorkerFunctions.InstallPackages(
OneClickInstall.GetRequiredPackages
)
end
if !success
Builtins.y2error("Unable to install packages")
CommandLine.Print(_("Error: Unable to install packages"))
return false
end
#If we don't want to remain subscribed, remove the repositories that were added for installation.
if OneClickInstall.HaveRepositoriesToInstall &&
!OneClickInstall.GetRemainSubscribed
success = OneClickInstallWorkerFunctions.RemoveAddedRepositories
end
if !success
Builtins.y2error("Unable to remove temporarily added repositories")
CommandLine.Print(
_("Warning: Unable to remove temporarily added repositories.")
)
return false
end
CommandLine.Print(_("Finished"))
true
end
def AmRoot
out = Convert.to_map(
SCR.Execute(path(".target.bash_output"), "/usr/bin/id --user")
)
Ops.get_string(out, "stdout", "") == "0\n"
end
def DoInstallHandler(options)
options = deep_copy(options)
if AmRoot()
return DoInstall(Ops.get(options, "instructionsfile", ""))
else
Builtins.y2error("Cannot install software as limited user")
CommandLine.Print(_("Error: Must be root"))
return false
end
end
end
end
Yast::OneClickInstallCLIClient.new.main