/
ssh_import.rb
131 lines (110 loc) · 3.66 KB
/
ssh_import.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
# Copyright (c) 2016 SUSE LLC.
# All Rights Reserved.
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 or 3 of the GNU General
# Public License as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com
require "yast"
require "ui/installation_dialog"
require "installation/ssh_importer"
module Yast
class SshImportDialog < ::UI::InstallationDialog
def initialize
super
Yast.import "UI"
Yast.import "Label"
textdomain "installation"
end
# Event callback for the 'ok' button
def next_handler
partition = UI.QueryWidget(Id(:device), :Value)
partition = nil unless UI.QueryWidget(Id(:import_ssh_key), :Value)
copy_config = UI.QueryWidget(Id(:copy_config), :Value)
log.info "SshImportDialog partition => #{partition} copy_config => #{copy_config}"
importer.device = partition
importer.copy_config = copy_config
super
end
private
def importer
@importer ||= ::Installation::SshImporter.instance
end
def partitions
@partitions ||= importer.configurations
end
def device
@device ||= importer.device
end
def copy_config
@copy_config ||= importer.copy_config
end
def dialog_content
HSquash(
VBox(
CheckBoxFrame(
Id(:import_ssh_key),
_("I would like to import SSH keys from a previous installation"),
true,
VBox(
HStretch(),
VSpacing(1),
HBox(
HSpacing(2),
partitions_list_widget
),
VSpacing(3),
HBox(
HSpacing(2),
Left(copy_config_widget)
)
)
),
HStretch()
)
)
end
def dialog_title
_("Import SSH Host Keys and Configuration")
end
def help_text
_(
"<p>Every SSH server is identified by one or several public host keys. " \
"Choose an existing Linux installation to reuse the host keys -and " \
"thus the identity- of its SSH server. The key files found in /etc/ssh " \
"(one pair of files per host key) will be copied to the new system " \
"being installed.</p>" \
"<p>Check <b>Import SSH Configuration</b> to also copy other files " \
"found in /etc/ssh, in addition to the keys.</p>"
)
end
def partitions_list_widget
sorted_partitions = partitions.to_a.sort_by(&:first)
part_widgets = sorted_partitions.map do |device, partition|
Left(partition_widget(device, partition))
end
RadioButtonGroup(
Id(:device),
VBox(
*part_widgets
)
)
end
def partition_widget(dev, partition)
strings = { system_name: partition.system_name, device: dev }
# TRANSLATORS: %{system_name} is a string like "openSUSE 13.2", %{device}
# is a string like /dev/sda1
name = _("%{system_name} at %{device}") % strings
RadioButton(Id(dev), name, device == dev)
end
def copy_config_widget
CheckBox(Id(:copy_config), _("Import SSH Configuration"), copy_config)
end
end
end