libisi 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +677 -0
- data/Manifest +89 -0
- data/Rakefile +34 -0
- data/lib/inifile.rb +119 -0
- data/lib/libisi.rb +948 -0
- data/lib/libisi/attribute.rb +32 -0
- data/lib/libisi/attribute/activerecord.rb +34 -0
- data/lib/libisi/attribute/base.rb +33 -0
- data/lib/libisi/base.rb +109 -0
- data/lib/libisi/bridge.rb +21 -0
- data/lib/libisi/bridge/base.rb +23 -0
- data/lib/libisi/bridge/java.rb +71 -0
- data/lib/libisi/bridge/python.rb +37 -0
- data/lib/libisi/cache.rb +21 -0
- data/lib/libisi/cache/base.rb +67 -0
- data/lib/libisi/cache/file_cache.rb +24 -0
- data/lib/libisi/chart.rb +21 -0
- data/lib/libisi/chart/base.rb +320 -0
- data/lib/libisi/chart/jfreechart.rb +682 -0
- data/lib/libisi/chart/jfreechart_generator.rb +206 -0
- data/lib/libisi/color.rb +21 -0
- data/lib/libisi/color/base.rb +66 -0
- data/lib/libisi/color/colortools.rb +92 -0
- data/lib/libisi/color/java.rb +44 -0
- data/lib/libisi/concept.rb +33 -0
- data/lib/libisi/concept/activerecord.rb +39 -0
- data/lib/libisi/concept/base.rb +58 -0
- data/lib/libisi/doc.rb +35 -0
- data/lib/libisi/doc/base.rb +414 -0
- data/lib/libisi/doc/html.rb +85 -0
- data/lib/libisi/doc/text.rb +98 -0
- data/lib/libisi/doc/wiki.rb +55 -0
- data/lib/libisi/environment.rb +21 -0
- data/lib/libisi/environment/base.rb +36 -0
- data/lib/libisi/environment/http.rb +105 -0
- data/lib/libisi/environment/rails.rb +27 -0
- data/lib/libisi/environment/root.rb +23 -0
- data/lib/libisi/fake_logger/logger.rb +61 -0
- data/lib/libisi/function/base.rb +30 -0
- data/lib/libisi/hal.rb +558 -0
- data/lib/libisi/instance.rb +27 -0
- data/lib/libisi/instance/activerecord.rb +21 -0
- data/lib/libisi/instance/base.rb +42 -0
- data/lib/libisi/log.rb +237 -0
- data/lib/libisi/mail/base.rb +32 -0
- data/lib/libisi/mail/tmail.rb +120 -0
- data/lib/libisi/parameter/base.rb +41 -0
- data/lib/libisi/property.rb +27 -0
- data/lib/libisi/property/base.rb +28 -0
- data/lib/libisi/reciever/base.rb +31 -0
- data/lib/libisi/reciever/socket.rb +31 -0
- data/lib/libisi/relation.rb +23 -0
- data/lib/libisi/request.rb +22 -0
- data/lib/libisi/request/base.rb +29 -0
- data/lib/libisi/request/http.rb +129 -0
- data/lib/libisi/response/base.rb +27 -0
- data/lib/libisi/task/base.rb +27 -0
- data/lib/libisi/task/http.rb +90 -0
- data/lib/libisi/tee.rb +296 -0
- data/lib/libisi/ui/base.rb +116 -0
- data/lib/libisi/ui/console.rb +238 -0
- data/lib/libisi/ui/kde.rb +94 -0
- data/lib/libisi/ui/nobody.rb +29 -0
- data/lib/libisi/ui/rails.rb +150 -0
- data/lib/libisi/ui/x11.rb +55 -0
- data/lib/libisi/uri.rb +42 -0
- data/lib/libisi/uri/activerecord.rb +152 -0
- data/lib/libisi/uri/base.rb +115 -0
- data/lib/libisi/uri/file.rb +43 -0
- data/lib/libisi/uri/ldap.rb +72 -0
- data/lib/libisi/uri/mysql.rb +98 -0
- data/lib/libisi/value.rb +31 -0
- data/lib/libisi/value/attribute_value.rb +19 -0
- data/lib/libisi/value/base.rb +55 -0
- data/lib/libisi/value/property_value.rb +19 -0
- data/lib/libisi/value/relation_value.rb +19 -0
- data/lib/ordered_hash.rb +228 -0
- data/libisi.gemspec +31 -0
- data/test/bridge_test.rb +77 -0
- data/test/cache_test.rb +65 -0
- data/test/chart_test.rb +179 -0
- data/test/color_test.rb +64 -0
- data/test/concept_test.rb +56 -0
- data/test/doc_test.rb +172 -0
- data/test/fixtures/test.db +0 -0
- data/test/ordered_hash_test.rb +39 -0
- data/test/profile_test.rb +36 -0
- data/test/request_test.rb +121 -0
- data/test/test +0 -0
- data/test/ui_test.rb +62 -0
- metadata +244 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
# fake logger class, do not load
|
|
19
|
+
# logger.rb in ruby api. Include
|
|
20
|
+
# functions that are needed for
|
|
21
|
+
# rails
|
|
22
|
+
module Log4r
|
|
23
|
+
class Logger
|
|
24
|
+
# Logging date-time format (string passed to +strftime+).
|
|
25
|
+
def datetime_format=(datetime_format)
|
|
26
|
+
@default_formatter.datetime_format = datetime_format
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def datetime_format
|
|
30
|
+
@default_formatter.datetime_format
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def format_message(severity, datetime, progname, msg)
|
|
34
|
+
(@formatter || @default_formatter).call(severity, datetime, progname, msg)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def format_datetime(time)
|
|
41
|
+
if @datetime_format.nil?
|
|
42
|
+
time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec
|
|
43
|
+
else
|
|
44
|
+
time.strftime(@datetime_format)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def msg2str(msg)
|
|
49
|
+
case msg
|
|
50
|
+
when ::String
|
|
51
|
+
msg
|
|
52
|
+
when ::Exception
|
|
53
|
+
"#{ msg.message } (#{ msg.class })\n" <<
|
|
54
|
+
(msg.backtrace || []).join("\n")
|
|
55
|
+
else
|
|
56
|
+
msg.inspect
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
# context: Context name in a environment
|
|
19
|
+
# name: The name of the function
|
|
20
|
+
class BaseFunction
|
|
21
|
+
|
|
22
|
+
attr_reader :context, :name
|
|
23
|
+
|
|
24
|
+
def initialize(cont, name, optinos = {})
|
|
25
|
+
@context = cont
|
|
26
|
+
@name = name
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
end
|
data/lib/libisi/hal.rb
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
class Hal
|
|
19
|
+
HAL_PREFIX = "/org/freedesktop/Hal/devices"
|
|
20
|
+
|
|
21
|
+
def self.parse_hal
|
|
22
|
+
debughal = false
|
|
23
|
+
udis = {}
|
|
24
|
+
open("|lshal") {|f|
|
|
25
|
+
current_item = nil
|
|
26
|
+
current_udi = nil
|
|
27
|
+
while true
|
|
28
|
+
current = f.readline
|
|
29
|
+
|
|
30
|
+
$log.debug("Current line is: #{current.inspect}") if debughal
|
|
31
|
+
case current
|
|
32
|
+
when /^udi = \'(.*)\'\s*$/
|
|
33
|
+
$log.debug("UDI: #{$1}") if debughal
|
|
34
|
+
current_udi = $1
|
|
35
|
+
current_item ={}
|
|
36
|
+
when /^\s+(\S+) = \{(.*)\} \(string list\)\s*$/
|
|
37
|
+
# list
|
|
38
|
+
name = $1
|
|
39
|
+
$log.debug("Array is: #{$2.inspect}") if debughal
|
|
40
|
+
current_item[name] = $2.split("', '")
|
|
41
|
+
current_item[name][0] = current_item[name][0].sub(/^\'/,"") if current_item[name][0]
|
|
42
|
+
current_item[name][-1] = current_item[name][-1].sub(/\'$/,"") if current_item[name][-1]
|
|
43
|
+
when /^\s+(\S+) = \'(.*)\' \(string\)\s*$/
|
|
44
|
+
# string
|
|
45
|
+
current_item[$1] = $2
|
|
46
|
+
when /^\s+(\S+) = (false|true) \(bool\)\s*$/
|
|
47
|
+
# boolean
|
|
48
|
+
case $2
|
|
49
|
+
when "false"
|
|
50
|
+
current_item[$1] = false
|
|
51
|
+
when "true"
|
|
52
|
+
current_item[$1] = true
|
|
53
|
+
else
|
|
54
|
+
raise "Unexpected boolean value #{$2}"
|
|
55
|
+
end
|
|
56
|
+
when /^\s+(\S+) = (\-?\d+) \(.*\) \(int\)\s*$/,/^\s+(\S+) = (\d+) \(.*\) \(uint64\)\s*$/
|
|
57
|
+
raise "Convert to integer failed #{$2.to_i.to_s} != #{$2}." if $2.to_i.to_s != $2
|
|
58
|
+
current_item[$1] = $2.to_i
|
|
59
|
+
when /^\s+(\S+) = (\-?\d+\.\d+) \(.*\) \(double\)\s*$/
|
|
60
|
+
current_item[$1] = $2.to_f
|
|
61
|
+
when /^\s*$/
|
|
62
|
+
if current_udi
|
|
63
|
+
udis["udi"] = current_udi
|
|
64
|
+
udis[current_udi] = current_item
|
|
65
|
+
end
|
|
66
|
+
current_item = nil
|
|
67
|
+
current_udi = nil
|
|
68
|
+
when /^Dumping/,/^----/
|
|
69
|
+
when /^Dumped/
|
|
70
|
+
else
|
|
71
|
+
raise "Unexpected line in lshal #{current.inspect}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
}
|
|
75
|
+
rescue EOFError
|
|
76
|
+
udis
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.list
|
|
80
|
+
parse_hal.map {|udi, hash| Hal.new(udi,hash)}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
attr_accessor :udi, :hash
|
|
85
|
+
def initialize(udi, hash)
|
|
86
|
+
raise "udi is nil" unless udi
|
|
87
|
+
raise "hash is nil for #{udi}" unless hash
|
|
88
|
+
@udi = udi
|
|
89
|
+
@hash = hash
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def parent
|
|
93
|
+
Hal.get_by_udi(hash["info.parent"])
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def volume?
|
|
97
|
+
hash["info.category"] == "volume"
|
|
98
|
+
end
|
|
99
|
+
def partition?
|
|
100
|
+
hash["volume.is_partition"] and hash["volume.is_partition"] == true
|
|
101
|
+
end
|
|
102
|
+
def removable?
|
|
103
|
+
return parent.removable? if partition?
|
|
104
|
+
hash["storage.removable"] or (hash["storage.drive_type"] == "sd_mmc")
|
|
105
|
+
end
|
|
106
|
+
def storage?
|
|
107
|
+
hash["info.category"] == "storage"
|
|
108
|
+
end
|
|
109
|
+
def floppy?
|
|
110
|
+
hash["storage.drive_type"] == "floppy"
|
|
111
|
+
end
|
|
112
|
+
def mountable?
|
|
113
|
+
return true if hash["volume.crypto_luks.clear.backing_volume"]
|
|
114
|
+
(hash["volume.fstype"] or "") != "" or is_luks?
|
|
115
|
+
end
|
|
116
|
+
def mounted?
|
|
117
|
+
if is_luks?
|
|
118
|
+
luks_volume and luks_volume.mounted?
|
|
119
|
+
else
|
|
120
|
+
(hash["volume.is_mounted"] or "") != ""
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
def mounted_readonly?
|
|
124
|
+
hash["volume.is_mounted_read_only"]
|
|
125
|
+
end
|
|
126
|
+
def is_luks?
|
|
127
|
+
hash["volume.fstype"] == "crypto_LUKS"
|
|
128
|
+
end
|
|
129
|
+
def exist?
|
|
130
|
+
reload
|
|
131
|
+
return !hash.nil?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def mount_point
|
|
135
|
+
return nil unless mounted?
|
|
136
|
+
hash["volume.mount_point"]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def reload
|
|
140
|
+
|
|
141
|
+
# dbus_send("org.freedesktop.Hal.Device.Rescan",
|
|
142
|
+
# "string:#{$name}","string:","array:string:noexec")
|
|
143
|
+
|
|
144
|
+
@hash = Hal.parse_hal[udi]
|
|
145
|
+
end
|
|
146
|
+
def hal_lock
|
|
147
|
+
# DISABLED, because commands do not work
|
|
148
|
+
# DISABLED dbus_send("org.freedesktop.Hal.Device.Lock","string:litkeys")
|
|
149
|
+
begin
|
|
150
|
+
return yield
|
|
151
|
+
ensure
|
|
152
|
+
# DISABLED dbus_send("org.freedesktop.Hal.Device.UnLock")
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
def dbus_send_with_password(*arguments)
|
|
156
|
+
cmd = ["dbus-send","--print-reply", "--system","--dest=org.freedesktop.Hal","#{udi}"]
|
|
157
|
+
cmd += arguments
|
|
158
|
+
hal_lock {
|
|
159
|
+
raise "Dbus send error" unless system(*cmd)
|
|
160
|
+
}
|
|
161
|
+
reload
|
|
162
|
+
end
|
|
163
|
+
def dbus_send(*arguments)
|
|
164
|
+
cmd = ["dbus-send","--print-reply", "--system","--dest=org.freedesktop.Hal","#{udi}"]
|
|
165
|
+
cmd += arguments
|
|
166
|
+
if arguments[0].include?("Lock")
|
|
167
|
+
execute_command_popen3(cmd)
|
|
168
|
+
else
|
|
169
|
+
hal_lock {execute_command_popen3(cmd)}
|
|
170
|
+
end
|
|
171
|
+
reload
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# mount a volume
|
|
175
|
+
# usage: hal_volume_mount <volume_id> [<mountpoint name>]
|
|
176
|
+
def mount(name = nil, options = {})
|
|
177
|
+
$log.debug("Mount #{udi} to #{name.inspect}")
|
|
178
|
+
raise "Volume #{block_device.inspect} is not mountable" unless mountable?
|
|
179
|
+
return (luks_volume or luks_setup(options)).mount(name,options) if is_luks?
|
|
180
|
+
|
|
181
|
+
name ||= label
|
|
182
|
+
name ||= hash["storage.model"]
|
|
183
|
+
name = name.gsub(/\s/,"_")
|
|
184
|
+
|
|
185
|
+
if mounted?
|
|
186
|
+
raise "already mounted to another mount point #{mount_point.inspect}" if mount_point != "/media/#{name}"
|
|
187
|
+
return
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
$log.info("Going to mount under #{name.inspect}")
|
|
191
|
+
raise "Cannot mount with name #{name.inspect}" if name.nil? or name.to_s.strip == ""
|
|
192
|
+
#id = open("|id -u") {|f| f.readlines[0].to_i }
|
|
193
|
+
#"array:string:noexec,uid=#{id}
|
|
194
|
+
mount_options = ((options[:mount_options] or "").split(",") + ["noexec"]).uniq.join(",")
|
|
195
|
+
dbus_send("org.freedesktop.Hal.Device.Volume.Mount",
|
|
196
|
+
"string:#{$name}","string:","array:string:#{mount_options}")
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# unmount a volume
|
|
200
|
+
def umount; unmount ; end
|
|
201
|
+
def unmount
|
|
202
|
+
if luks_setup?
|
|
203
|
+
ret = luks_volume.unmount
|
|
204
|
+
luks_teardown
|
|
205
|
+
return ret
|
|
206
|
+
end
|
|
207
|
+
raise "Not mounted." unless mounted?
|
|
208
|
+
dbus_send("org.freedesktop.Hal.Device.Volume.Unmount","array:string:")
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# LUKS
|
|
212
|
+
# setup a luks volume, given its backingn volume
|
|
213
|
+
def luks_setup(options = {})
|
|
214
|
+
raise "Device is no luksdevice." unless is_luks?
|
|
215
|
+
|
|
216
|
+
storage_device = parent
|
|
217
|
+
device_name = nil
|
|
218
|
+
partition_no = nil
|
|
219
|
+
if parent.hash["info.category"] == 'storage'
|
|
220
|
+
device_name = "#{parent.hash["info.vendor"]} #{parent.hash["info.product"]}"
|
|
221
|
+
partition_no = hash["volume.partition.number"]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
if device_name and partition_no
|
|
225
|
+
prompt_description = "partition #{partition_no} on \"#{device_name}\" (#{block_device})"
|
|
226
|
+
else
|
|
227
|
+
prompt_description = block_device
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
password = (options[:password] or $ui.password("Enter LUKS password for #{prompt_description}"))
|
|
231
|
+
|
|
232
|
+
5.times {|t|
|
|
233
|
+
# BUG in HAL. Sometimes the label is not set.
|
|
234
|
+
# Retry with Luks Teardown and Setup again.
|
|
235
|
+
# Reload is not permitted for user.
|
|
236
|
+
dbus_send_with_password("org.freedesktop.Hal.Device.Volume.Crypto.Setup","string:#{password}")
|
|
237
|
+
sleep(t + 1)
|
|
238
|
+
if luks_volume.label != ""
|
|
239
|
+
break
|
|
240
|
+
else
|
|
241
|
+
$log.warn("Luks partition of device #{udi} has no label defined. Probably this is a bug in HAL, Teardown Luks again.")
|
|
242
|
+
dbus_send("org.freedesktop.Hal.Device.Volume.Crypto.Teardown")
|
|
243
|
+
end
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
luks_volume
|
|
247
|
+
end
|
|
248
|
+
# teardown a luks volume, given its backing volume
|
|
249
|
+
def luks_teardown
|
|
250
|
+
dbus_send("org.freedesktop.Hal.Device.Volume.Crypto.Teardown")
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def luks_setup?
|
|
254
|
+
!luks_volume.nil?
|
|
255
|
+
end
|
|
256
|
+
def luks_backing_volume
|
|
257
|
+
$log.debug("Looking for backing volume: #{hash["volume.crypto_luks.clear.backing_volume"]}")
|
|
258
|
+
Hal.get_by_udi(hash["volume.crypto_luks.clear.backing_volume"])
|
|
259
|
+
end
|
|
260
|
+
def luks_volume
|
|
261
|
+
Hal.list.select {|h| h.hash["volume.crypto_luks.clear.backing_volume"] == udi}[0]
|
|
262
|
+
end
|
|
263
|
+
=begin
|
|
264
|
+
# mount a luks volume given its backing volume
|
|
265
|
+
def luks_mount (name)
|
|
266
|
+
local lUdi=$1
|
|
267
|
+
local lName=$2
|
|
268
|
+
|
|
269
|
+
if [ -z "$lUdi" ]; then
|
|
270
|
+
return
|
|
271
|
+
fi
|
|
272
|
+
|
|
273
|
+
lSetupVolumeUdi=$(hal_luks_get_setup_volume $lUdi)
|
|
274
|
+
|
|
275
|
+
hal_volume_mount $lSetupVolumeUdi $lName
|
|
276
|
+
lRet=$?
|
|
277
|
+
return $lRet
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
# get the assigned volume in case this luks volume has been set up
|
|
281
|
+
# usage: hal_luks_get_setup_volume <luks udi>
|
|
282
|
+
def luks_get_setup_volume
|
|
283
|
+
local lUdi=$1
|
|
284
|
+
|
|
285
|
+
local lVolumeUdis=$(hal_get_volumes)
|
|
286
|
+
if [ -n "$lVolumeUdis" ]; then
|
|
287
|
+
for lVolumeUdi in $lVolumeUdis; do
|
|
288
|
+
if lshal -l -u $lVolumeUdi | grep -q "volume.crypto_luks.clear.backing_volume.*=.*$lHalPrefix/$lUdi"; then
|
|
289
|
+
echo $lVolumeUdi
|
|
290
|
+
return
|
|
291
|
+
fi
|
|
292
|
+
done
|
|
293
|
+
fi
|
|
294
|
+
|
|
295
|
+
# not found
|
|
296
|
+
echo ""
|
|
297
|
+
}
|
|
298
|
+
=end
|
|
299
|
+
def block_device
|
|
300
|
+
hash["block.device"]
|
|
301
|
+
end
|
|
302
|
+
def storage_device
|
|
303
|
+
hash["block.storage_device"]
|
|
304
|
+
end
|
|
305
|
+
def product
|
|
306
|
+
hash["info.product"]
|
|
307
|
+
end
|
|
308
|
+
def label
|
|
309
|
+
hash["volume.label"]
|
|
310
|
+
end
|
|
311
|
+
def fstype
|
|
312
|
+
hash["volume.fstype"]
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# list volume udis on stdout; one udi per line
|
|
316
|
+
# usage: hal_get_volumes
|
|
317
|
+
def self.get_volumes
|
|
318
|
+
list.select {|h| h.volume? }
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# list removable volume udis on stdout; one udi per line
|
|
322
|
+
# usage: hal_get_removable_volumes
|
|
323
|
+
def self.get_removable_volumes
|
|
324
|
+
list.select {|h| h.removable? }
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def self.get_by_udi(udi)
|
|
328
|
+
hash = Hal.parse_hal[udi]
|
|
329
|
+
return nil unless hash
|
|
330
|
+
Hal.new(udi, hash)
|
|
331
|
+
end
|
|
332
|
+
def self.get_by_block_device_name(block_device_name)
|
|
333
|
+
list.select {|h|
|
|
334
|
+
h.block_device == block_device_name
|
|
335
|
+
}[0]
|
|
336
|
+
end
|
|
337
|
+
def self.get_by_label(label)
|
|
338
|
+
list.select {|h| h.label == label}[0]
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def self.get_block_device(block_device_name)
|
|
342
|
+
list.select {|h| h.block_device == block_device_name}[0]
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# list floppy storage udis on stdout; one udi per line
|
|
346
|
+
# usage: hal_get_floppies
|
|
347
|
+
def self.get_floppies
|
|
348
|
+
list.select {|h| h.storage? and h.floppy? }
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# check whether a floppy is mounted
|
|
352
|
+
def self.floppy_is_mounted?
|
|
353
|
+
get_floppies.select {|f| f.mounted?}.length > 0
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
# check whether a floppy is mounted read-only
|
|
357
|
+
def self.floppy_is_mounted_readonly?
|
|
358
|
+
get_floppies.select {|f| f.mounted? and f.mounted_readonly?}.length > 0
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
def to_s
|
|
362
|
+
ret = "#{udi}:\n"
|
|
363
|
+
hash.each {|key, val| ret += " #{key}: #{val.inspect}\n" }
|
|
364
|
+
ret
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
=begin
|
|
369
|
+
# mount a floppy
|
|
370
|
+
# usage: hal_floppy_mount <floppy_id> [<mountpoint name>]
|
|
371
|
+
hal_floppy_mount () {
|
|
372
|
+
local lUdi=$1
|
|
373
|
+
local lName=$2
|
|
374
|
+
|
|
375
|
+
local lVolumeUdi=$(hal_floppy_get_volume $lUdi)
|
|
376
|
+
if [ -z "$lVolumeUdi" ]; then
|
|
377
|
+
# wait for floppy if not yet ready...
|
|
378
|
+
echo -n "floppy not yet ready, waiting "
|
|
379
|
+
for i in $(seq 1 10); do
|
|
380
|
+
echo -n "."
|
|
381
|
+
sleep 1
|
|
382
|
+
lVolumeUdi=$(hal_floppy_get_volume $lUdi)
|
|
383
|
+
if [ -n "$lVolumeUdi" ]; then
|
|
384
|
+
# found, continue
|
|
385
|
+
break
|
|
386
|
+
fi
|
|
387
|
+
done
|
|
388
|
+
|
|
389
|
+
if [ -z "$lVolumeUdi" ]; then
|
|
390
|
+
# really not available, nothing to do
|
|
391
|
+
return 0
|
|
392
|
+
fi
|
|
393
|
+
|
|
394
|
+
echo " ok."
|
|
395
|
+
fi
|
|
396
|
+
|
|
397
|
+
hal_volume_mount $lVolumeUdi $lName
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
# unmount a floppy
|
|
402
|
+
# usage: hal_floppy_unmount <floppy_id>
|
|
403
|
+
hal_floppy_unmount () {
|
|
404
|
+
local lUdi=$1
|
|
405
|
+
|
|
406
|
+
local lVolumeUdi=$(hal_floppy_get_volume $lUdi)
|
|
407
|
+
if [ -z "$lVolumeUdi" ]; then
|
|
408
|
+
# volume not available, nothing to do
|
|
409
|
+
return 0
|
|
410
|
+
fi
|
|
411
|
+
|
|
412
|
+
hal_volume_unmount $lVolumeUdi
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
# get the volume of a floppy drive
|
|
416
|
+
# usage: hal_floppy_get_volume <storage_udi>
|
|
417
|
+
hal_floppy_get_volume () {
|
|
418
|
+
local lUdi=$1
|
|
419
|
+
|
|
420
|
+
local lVolumeUdis=$(hal_get_volumes)
|
|
421
|
+
if [ -n "$lVolumeUdis" ]; then
|
|
422
|
+
for lVolumeUdi in $lVolumeUdis; do
|
|
423
|
+
if lshal -l -u $lVolumeUdi | grep -q "info.parent.*=.*$lHalPrefix/$lUdi"; then
|
|
424
|
+
echo $lVolumeUdi
|
|
425
|
+
return
|
|
426
|
+
fi
|
|
427
|
+
done
|
|
428
|
+
fi
|
|
429
|
+
|
|
430
|
+
# not found
|
|
431
|
+
echo ""
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
# get the corresponding luks volume to this "setup" volume
|
|
436
|
+
# usage: hal_luks_get_luks_volume <setup udi>
|
|
437
|
+
hal_luks_get_luks_volume () {
|
|
438
|
+
local lUdi=$1
|
|
439
|
+
|
|
440
|
+
local lLuksVolume=$(lshal -u $lUdi -l | grep 'volume.crypto_luks.clear.backing_volume' | sed -e "s/^.*'\(.*\)'.*$/\1/" | sed -e "s!^.*/!!")
|
|
441
|
+
echo $lLuksVolume
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
# show a given volume (for testing)
|
|
446
|
+
# usage: hal_volume_show <udi>
|
|
447
|
+
hal_volume_show () {
|
|
448
|
+
local lUdi=$1
|
|
449
|
+
|
|
450
|
+
lDevice=$(hal_volume_get_device $lUdi)
|
|
451
|
+
lParentUdi=$(hal_get_storage $lUdi)
|
|
452
|
+
lProduct=$(hal_volume_get_product $lUdi)
|
|
453
|
+
lLabel=$(hal_volume_get_label $lUdi)
|
|
454
|
+
|
|
455
|
+
if hal_storage_is_removable $lParentUdi; then
|
|
456
|
+
lRemovable="true"
|
|
457
|
+
else
|
|
458
|
+
lRemovable="false"
|
|
459
|
+
fi
|
|
460
|
+
|
|
461
|
+
if [ "$lRemovable" != true ]; then
|
|
462
|
+
return
|
|
463
|
+
fi
|
|
464
|
+
|
|
465
|
+
if hal_volume_is_mounted $lUdi; then
|
|
466
|
+
lMounted="true"
|
|
467
|
+
else
|
|
468
|
+
lMounted="false"
|
|
469
|
+
fi
|
|
470
|
+
|
|
471
|
+
if hal_volume_is_mounted_readonly $lUdi; then
|
|
472
|
+
lReadonly="true"
|
|
473
|
+
else
|
|
474
|
+
lReadonly="false"
|
|
475
|
+
fi
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
lMountpoint=$(hal_volume_get_mountpoint $lUdi)
|
|
480
|
+
lFilesystem=$(hal_volume_get_filesystem $lUdi)
|
|
481
|
+
|
|
482
|
+
local lLuksSetupVolumeUdi=""
|
|
483
|
+
if [ "$lFilesystem" = "crypto_LUKS" ]; then
|
|
484
|
+
lLuksSetupVolumeUdi=$(hal_luks_get_setup_volume $lUdi)
|
|
485
|
+
if [ -n "$lLuksSetupVolumeUdi" ]; then
|
|
486
|
+
lLuksSetupVolumeDevice=$(hal_volume_get_device $lLuksSetupVolumeUdi)
|
|
487
|
+
fi
|
|
488
|
+
fi
|
|
489
|
+
|
|
490
|
+
echo "Product: $lProduct"
|
|
491
|
+
echo "Device: $lDevice"
|
|
492
|
+
echo "Label: $lLabel"
|
|
493
|
+
echo "Mounted: $lMounted"
|
|
494
|
+
echo "Readonly: $lReadonly"
|
|
495
|
+
echo "Mountpoint: $lMountpoint"
|
|
496
|
+
echo "Filesystem: $lFilesystem"
|
|
497
|
+
echo "Removable: $lRemovable"
|
|
498
|
+
echo "Udi: $lUdi"
|
|
499
|
+
if [ -n "$lLuksSetupVolumeUdi" ]; then
|
|
500
|
+
echo "LUKS: Setup at $lLuksSetupVolumeDevice ($lLuksSetupVolumeUdi)"
|
|
501
|
+
fi
|
|
502
|
+
echo
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
# show a given floppy (for testing)
|
|
506
|
+
# usage: hal_floppy_show <udi>
|
|
507
|
+
hal_floppy_show () {
|
|
508
|
+
local lUdi=$1
|
|
509
|
+
|
|
510
|
+
lDevice=$(hal_storage_get_device $lUdi)
|
|
511
|
+
lProduct=$(hal_storage_get_product $lUdi)
|
|
512
|
+
## lLabel=$(hal_volume_get_label $lUdi)
|
|
513
|
+
|
|
514
|
+
if hal_storage_is_removable $lUdi; then
|
|
515
|
+
lRemovable="true"
|
|
516
|
+
else
|
|
517
|
+
lRemovable="false"
|
|
518
|
+
fi
|
|
519
|
+
|
|
520
|
+
if [ "$lRemovable" != true ]; then
|
|
521
|
+
return
|
|
522
|
+
fi
|
|
523
|
+
|
|
524
|
+
if hal_floppy_is_mounted $lUdi; then
|
|
525
|
+
lMounted="true"
|
|
526
|
+
else
|
|
527
|
+
lMounted="false"
|
|
528
|
+
fi
|
|
529
|
+
|
|
530
|
+
lVolumeUdi=$(hal_floppy_get_volume $lUdi)
|
|
531
|
+
if [ -n "$lVolumeUdi" ]; then
|
|
532
|
+
lMountpoint=$(hal_volume_get_mountpoint $lVolumeUdi)
|
|
533
|
+
lLabel=$(hal_volume_get_label $lVolumeUdi)
|
|
534
|
+
else
|
|
535
|
+
lMountpoint="NOT INSERTED"
|
|
536
|
+
lLabel=""
|
|
537
|
+
fi
|
|
538
|
+
|
|
539
|
+
if hal_floppy_is_mounted_readonly $lUdi; then
|
|
540
|
+
lReadonly=true
|
|
541
|
+
else
|
|
542
|
+
lReadonly=false
|
|
543
|
+
fi
|
|
544
|
+
|
|
545
|
+
echo "Product: $lProduct"
|
|
546
|
+
echo "Device: $lDevice"
|
|
547
|
+
echo "Label: $lLabel"
|
|
548
|
+
echo "Mounted: $lMounted"
|
|
549
|
+
echo "Readonly: $lReadonly"
|
|
550
|
+
echo "Mountpoint: $lMountpoint"
|
|
551
|
+
echo "Removable: $lRemovable"
|
|
552
|
+
echo "Udi: $lUdi"
|
|
553
|
+
echo "VolumeUdi: $lVolumeUdi"
|
|
554
|
+
echo
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
end
|
|
558
|
+
=end
|