<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
					xmlns:content="http://purl.org/rss/1.0/modules/content/"
					xmlns:wfw="http://wellformedweb.org/CommentAPI/"
					xmlns:atom="http://www.w3.org/2005/Atom"
				  >
<channel>
<atom:link rel="self"  type="application/rss+xml"  href="http://rulinux.net/rss_from_sect_2_subsect_2"  />
<title>rulinux.net - Статьи - Desktop</title>
<link>http://rulinux.net/</link>
<description><![CDATA[Портал о GNU/Linux и не только]]></description>
<image><title>rulinux.net - Статьи - Desktop</title>
<link>http://rulinux.net/</link>
<url>http://rulinux.net/rss_icon.png</url>
</image>
<item>
<title>Тот самый маунтманагер</title>
<link>https://rulinux.net/message.php?newsid=34861&amp;page=1</link>
<guid>https://rulinux.net/message.php?newsid=34861&amp;page=1</guid>
<pubDate>Fri, 18 Sep 2009 06:26:00 +0400</pubDate>
<description><![CDATA[<p><b>Цель:</b> при вставке устройства хранения данных вызывать цепочку баш скриптов, делающее с вставленным и отмонтированным носителем разные непотребства.</p><p><b>Реализация:</b> Раньше для этого я использовал ivman, но чего-то он слишком громоздкий был. За основу взят комментер событий на питоне от radiofun, из которого вырезана часть составляющая комментарии (теперь комментируем события из баш скриптов, по мере надобности. На моей станции комментирует самописная прога на сях lsay ( проприетарный цепстраловский синтез + зажигание светодиодов в lpt в зависимости от амплитуды речи ))</p><p>Собственно сырец маунт манагера и комменты к нему ниже</p><p><fieldset><legend>python</legend><code><br />
<span style="color: #808080; font-style: italic;">#!/usr/bin/python</span><br />
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span><br />
<span style="color: #808080; font-style: italic;">###########################################################################</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp;Event Commenter + automount via hal &nbsp;+ bash handlers &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # </span><br />
<span style="color: #808080; font-style: italic;"># ------------------------------ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span><br />
<span style="color: #808080; font-style: italic;"># copyright : © 2008 radiofun; © 2009 Necromant &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;"># jabber &nbsp; &nbsp;: radiofun@jabber.ru &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span><br />
<span style="color: #808080; font-style: italic;"># jabber &nbsp; &nbsp;: aifiltr0@invyl.ath.cx &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;">###########################################################################</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; This program is free software; you can redistribute it and/or modify &nbsp;#</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; it under the terms of the GNU General Public License as published by &nbsp;#</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; the Free Software Foundation; either version 2 of the License, or &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; (at your option) any later version. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #</span><br />
<span style="color: #808080; font-style: italic;">###########################################################################</span><br />
&nbsp;<br />
<span style="color: #ff7700;font-weight:bold;">import</span> gobject<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">threading</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> dbus<br />
<span style="color: #ff7700;font-weight:bold;">import</span> dbus.<span style="color: black;">mainloop</span>.<span style="color: black;">glib</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span><br />
&nbsp;<br />
handler_script = <span style="color: #483d8b;">&quot;/home/aifiltr0/.config/NMountManager/storage_handler.sh&quot;</span><br />
&nbsp;<br />
<span style="color: #ff7700;font-weight:bold;">class</span> NMountMgr<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<span style="color: #808080; font-style: italic;">#threading.Thread):</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#threading.Thread.__init__(self)</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__bus = dbus.<span style="color: black;">SystemBus</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__hm = <span style="color: #008000;">self</span>.__bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'org.freedesktop.Hal'</span>,<span style="color: #483d8b;">'/org/freedesktop/Hal/Manager'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__hm.<span style="color: black;">connect_to_signal</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'DeviceAdded'</span>, <span style="color: #008000;">self</span>.<span style="color: black;">deviceAdded</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__hm.<span style="color: black;">connect_to_signal</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'DeviceRemoved'</span>, <span style="color: #008000;">self</span>.<span style="color: black;">deviceRemoved</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">handler_script</span> = handler_script<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__connectedDevices = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> deviceAdded<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, devID<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; device = dbus.<span style="color: black;">Interface</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.__bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;org.freedesktop.Hal&quot;</span>, devID<span style="color: black;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;org.freedesktop.Hal.Device&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #008000;">self</span>.__prepareAction<span style="color: black;">&#40;</span>device<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>exec_line<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> 0:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__connectedDevices<span style="color: black;">&#91;</span>devID<span style="color: black;">&#93;</span>=exec_line<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">handler_script</span> + <span style="color: #483d8b;">&quot; connect &quot;</span> + exec_line<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> deviceRemoved<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, devID<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> devID <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.__connectedDevices:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #008000;">self</span>.__connectedDevices.<span style="color: black;">pop</span><span style="color: black;">&#40;</span>devID<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">handler_script</span> + <span style="color: #483d8b;">&quot; disconnect &quot;</span> + exec_line<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#self.__say(message);</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#prepare device comment!</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> __prepareAction<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, device<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> device.<span style="color: black;">PropertyExists</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'info.capabilities'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isCD = device.<span style="color: black;">QueryCapability</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.disc'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#if &quot;volume&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> device.<span style="color: black;">QueryCapability</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> isCD:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size =<span style="color: #008000;">self</span>.__getHumanReadableSize<span style="color: black;">&#40;</span>device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.size'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.label'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>label<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">1</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.fsversion'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#message += &quot;Volume connected: label is &quot; + label + &quot;, Total size &quot;+ size</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#device.Mount(label,&quot;rw&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uuid = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.uuid'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uuid = uuid.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-&quot;</span>,<span style="color: #483d8b;">&quot;_&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vol = <span style="color: #008000;">self</span>.__bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'org.freedesktop.Hal'</span>, <span style="color: #483d8b;">'/org/freedesktop/Hal/devices/volume_uuid_'</span> + uuid<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#Dirty hack for vfat unicode mount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.fstype'</span><span style="color: black;">&#41;</span>==<span style="color: #483d8b;">'vfat'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mopts=<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;utf8&quot;</span>,<span style="color: #483d8b;">&quot;uid=1000&quot;</span>,<span style="color: #483d8b;">&quot;shortname=mixed&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mopts=<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;uid=1000&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vol.<span style="color: black;">Mount</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>, device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.fstype'</span><span style="color: black;">&#41;</span>, mopts , dbus_interface=<span style="color: #483d8b;">&quot;org.freedesktop.Hal.Device.Volume&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mpoint = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.mount_point'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #483d8b;">&quot; volume <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + mpoint + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + label + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> + uuid<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># if CD or dvd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># I have no cd/dvd on my netbook, so the following is not well tested</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> isCD:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label = <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.disc.has_audio'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label += <span style="color: #483d8b;">&quot; audio &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.disc.is_blank'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label += <span style="color: #483d8b;">&quot; empty &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label += device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.disc.type'</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label += device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.label'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uuid = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.uuid'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uuid = uuid.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-&quot;</span>,<span style="color: #483d8b;">&quot;_&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vol = <span style="color: #008000;">self</span>.__bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'org.freedesktop.Hal'</span>, <span style="color: #483d8b;">'/org/freedesktop/Hal/devices/volume_uuid_'</span> + uuid<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vol.<span style="color: black;">Mount</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>, device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.fstype'</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;&quot;</span>, dbus_interface=<span style="color: #483d8b;">&quot;org.freedesktop.Hal.Device.Volume&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mpoint = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'volume.mount_point'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #483d8b;">&quot; cd <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + mpoint + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + label + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> + uuid<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#if storage</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">elif</span> device.<span style="color: black;">QueryCapability</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'storage'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#message += 'Device connection detected: '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#message += self.__getDeviceName(device) + &quot; storage&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #483d8b;">&quot;stgdev <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + <span style="color: #008000;">self</span>.__getDeviceName<span style="color: black;">&#40;</span>device<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#это должно быть саммы последним! &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>device.<span style="color: black;">PropertyExists</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'linux.subsystem'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: black;">&#40;</span>device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'linux.subsystem'</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">'usb'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> :<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; category = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'info.category'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; devName = <span style="color: #008000;">self</span>.__getDeviceName<span style="color: black;">&#40;</span>device<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#message += devName + &quot; &quot; + category</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec_line = <span style="color: #483d8b;">&quot;usbdev <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + <span style="color: #008000;">self</span>.__getDeviceName<span style="color: black;">&#40;</span>device<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> exec_line<br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># in uint64!</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> __getHumanReadableSize<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, size<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; dim = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">math</span>.<span style="color: black;">log</span><span style="color: black;">&#40;</span>size, 1024<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result = <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 : <span style="color: #ff7700;font-weight:bold;">lambda</span> x: <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' bytes'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 : <span style="color: #ff7700;font-weight:bold;">lambda</span> x: <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>x/<span style="color: #ff4500;">1024</span>+<span style="color: #ff4500;">0.5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' kilobytes'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 : <span style="color: #ff7700;font-weight:bold;">lambda</span> x: <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>x/1.048576e6+<span style="color: #ff4500;">0.5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' megabytes'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 : <span style="color: #ff7700;font-weight:bold;">lambda</span> x: <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>x/1.073741824e9+<span style="color: #ff4500;">0.5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' gigabytes'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span>dim<span style="color: black;">&#93;</span><span style="color: black;">&#40;</span>size<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> result<br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> __getDeviceName<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, device<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; result = <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> device.<span style="color: black;">PropertyExists</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'info.vendor'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'info.vendor'</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> device.<span style="color: black;">PropertyExists</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'info.product'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result += device.<span style="color: black;">GetProperty</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'info.product'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result += <span style="color: #483d8b;">&quot;unknown&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> result<br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> __say<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, text<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#pipe = os.popen('espeak -vmb/mb-fr4-en -s 150 -a 100','w')</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pipe = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'lsay <span style="color: #000099; font-weight: bold;">\'</span>'</span> + text+ <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span>,<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> text<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#pipe.write(text)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pipe.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__del__</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.__bus.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
dbus.<span style="color: black;">mainloop</span>.<span style="color: black;">glib</span>.<span style="color: black;">DBusGMainLoop</span><span style="color: black;">&#40;</span>set_as_default=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span><br />
&nbsp;<br />
ec = NMountMgr<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
mainloop = gobject.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
mainloop.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp;</code></fieldset></p><p>В самом начале поправьте урл скрипта-хэндлера. у меня он на баше, но Вы можете его на чем угодно делать. Его задача минимальна, исходник привожу ниже. из папки handler_dir (не забудьте выставить свою!) Вызывает все скрипты предварительно установив полученные аргументы в переменные к которым легко обращаться и export’нув их.</p><p><fieldset><legend>bash</legend><code><br />
<span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #007800;">handler_dir</span>=<span style="color: #ff0000;">&quot;/home/aifiltr0/.config/NMountManager/stg_handlers.d/&quot;</span><br />
&nbsp;<br />
report<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
<span style="color: #c20cb9; font-weight: bold;">kdialog</span> <span style="color: #660033;">--passivepopup</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;NMountManager&quot;</span><span style="color: #000000; font-weight: bold;">&amp;</span><br />
lsay <span style="color: #ff0000;">&quot;$1&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">#Comment this if you do not want reports about what is connected</span><br />
early_report<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
report $1<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
&nbsp;<br />
<span style="color: #7a0874; font-weight: bold;">export</span> report<br />
&nbsp;<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> $1 $2 $3 $4 $5<br />
&nbsp;<br />
<span style="color: #007800;">ACTION</span>=$1<br />
<span style="color: #7a0874; font-weight: bold;">export</span> ACTION<br />
&nbsp;<br />
<span style="color: #007800;">TYPE</span>=$2<br />
<span style="color: #7a0874; font-weight: bold;">export</span> TYPE<br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TYPE</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; volume<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp;<br />
&nbsp; <span style="color: #007800;">MPOINT</span>=$3<br />
&nbsp; <span style="color: #007800;">LABEL</span>=$4<br />
&nbsp; <span style="color: #007800;">UUID</span>=$5<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> MPOINT<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> LABEL<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> UUID<br />
&nbsp;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$ACTION</span> == <span style="color: #ff0000;">&quot;connect&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;A new storage volume has been connected. Label is <span style="color: #007800;">$LABEL</span>. I have attached it to <span style="color: #007800;">$MPOINT</span>&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;Storage volume <span style="color: #007800;">$LABEL</span> removed&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; <span style="color: #007800;">MPOINT</span>=$3<br />
&nbsp; <span style="color: #007800;">LABEL</span>=$4<br />
&nbsp; <span style="color: #007800;">UUID</span>=$5<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> MPOINT<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> LABEL<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> UUID<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$ACTION</span> == <span style="color: #ff0000;">&quot;connect&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;A compact disk has been inserted. Label is <span style="color: #007800;">$LABEL</span>. I have attached it to <span style="color: #007800;">$MPOINT</span>&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;Compact disk ejected.&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<br />
&nbsp; stgdev<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; <span style="color: #007800;">DEVICENAME</span>=$3<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> DEVICENAME<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$ACTION</span> == <span style="color: #ff0000;">&quot;connect&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;A storage device called <span style="color: #007800;">$DEVICENAME</span> has been connected. &quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<br />
&nbsp; usbdev<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; <span style="color: #007800;">DEVICENAME</span>=$3<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> DEVICENAME<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$ACTION</span> == <span style="color: #ff0000;">&quot;connect&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;A USB device called <span style="color: #007800;">$DEVICENAME</span> has been connected. &quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;A USB device called <span style="color: #007800;">$DEVICENAME</span> has been disconnected. &quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
&nbsp;<br />
&nbsp;<br />
<span style="color: #007800;">BROWSEABLE</span>=0<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$ACTION</span> == <span style="color: #ff0000;">&quot;connect&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$TYPE</span> == <span style="color: #ff0000;">&quot;cd&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;cd&quot;</span><br />
&nbsp; <span style="color: #007800;">BROWSEABLE</span>=1<br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$TYPE</span> == <span style="color: #ff0000;">&quot;volume&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;vol&quot;</span><br />
&nbsp; <span style="color: #007800;">BROWSEABLE</span>=1<br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp;<br />
&nbsp;<br />
<span style="color: #7a0874; font-weight: bold;">export</span> BROWSEABLE<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ACTION</span> TYPE: <span style="color: #007800;">$TYPE</span> MPOINT=<span style="color: #007800;">$MPOINT</span> LABEL=<span style="color: #007800;">$LABEL</span> UUID=<span style="color: #007800;">$UUID</span> BROWSEABLE=<span style="color: #007800;">$BROWSEABLE</span>&quot;</span><br />
&nbsp;<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$handler_dir</span><br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">*</span>~<br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span><br />
. <span style="color: #007800;">$file</span><br />
<span style="color: #000000; font-weight: bold;">done</span>;<br />
&nbsp;</code></fieldset></p><p>В папке с хэндлерами мы можем складывать свои баш скрипты на все случае жизни. Из каждого скрипта нам доступно: $ACTION – connect или disconnect $TYPE – тип устройства: usbdev, stgdev, cd, volume. Последние два монтируются автоматом, а куда именно – узнать можем через $MPOINT. Там путь к точке монтирования. $BROWSEABLE – это для ленивых, чтобы не проверять несколько разом и сэкономить на ифе: Если 1 – значит нечто отмонтировано и в $MPOINT можно минимум почитать данные. usbdev и stgdev выставляют $DEVICENAME, для cd и volume есть еще $LABEL и $UUID, так что свои флешки распознатиь легко.</p><p>Вот примеры простых скриптов-хэндлеров: Этот проверяет по ууиду (ам) моя ли эта флешка и экспортирует переменную STG_OWNER.</p><p><fieldset><legend>bash</legend><code><br />
<span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;"># This script checks who does this storage belong to. </span><br />
<span style="color: #666666; font-style: italic;"># And exports a variable</span><br />
<span style="color: #666666; font-style: italic;"># This can be: 0 - ours 1 - foreign, quite simple, but nevertheless</span><br />
&nbsp;<br />
<span style="color: #007800;">stg_pdacard</span>=B4DC_999E<br />
&nbsp;<br />
verify_storage<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">for</span> dev <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #000000; font-weight: bold;">@</span>; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dev</span>&quot;</span> == <span style="color: #ff0000;">&quot;<span style="color: #007800;">$UUID</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dev</span> matched owner list!&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">done</span>;<br />
<span style="color: #7a0874; font-weight: bold;">return</span> 1<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> &nbsp;<span style="color: #007800;">$BROWSEABLE</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
verify_storage <span style="color: #007800;">$stg_pdacard</span><br />
<span style="color: #007800;">STG_OWNER</span>=<span style="color: #007800;">$?</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OWNER IS: <span style="color: #007800;">$STG_OWNER</span>&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">export</span> STG_OWNER<br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp;</code></fieldset></p><p>Я задолбался сносить с флешки автораны с вирусней, когда попользую ее на вендовозных машинах в инсте. Надо бы написать парсер авторан.инфа чтобы еще и сообразить где лежит вирусня, но лень.</p><p><fieldset><legend>bash</legend><code><br />
<span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #666666; font-style: italic;">#ToDo: Properly parse ini file to locate the f*cking shit</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==&gt; <span style="color: #007800;">$ACTION</span> <span style="color: #007800;">$TYPE</span>&quot;</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$ACTION</span> == <span style="color: #ff0000;">&quot;connect&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$TYPE</span> == <span style="color: #ff0000;">&quot;volume&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$MPOINT</span><span style="color: #000000; font-weight: bold;">/</span>autorun.inf <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;Security alert! The removable device has probably been infected and is dangerous for windows systems. Initiating disinfection sequence.&quot;</span><br />
&nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$MPOINT</span><span style="color: #000000; font-weight: bold;">/</span>autorun.inf<br />
&nbsp; report <span style="color: #ff0000;">&quot;Disinfection complete&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp;</code></fieldset></p><p>Коммуниздим потихоньку музочку с флешек друзей в фоновом режиме. Всю, какую находим и складываем в ~/msx4sort/UUID. Зависит от первого скрипта-хэндлера, который проверяет наша ли это флешка и если наша – то игнорирует. (свою-то музыку нафига копировать?)</p><p><fieldset><legend>bash</legend><code><br />
<span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">#This script make sure you get all the mp3 from a flash drive of your friend without him/her ever noticing it</span><br />
<span style="color: #666666; font-style: italic;">#Just make sure you fill in the data required</span><br />
<span style="color: #007800;">TARGET_DIR</span>=~<span style="color: #000000; font-weight: bold;">/</span>msx4sort<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp;<br />
sync_type<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`pwd`</span> $1&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-iname</span> $<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> FILE; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILE</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TARGET_DIR</span><span style="color: #007800;">$FILE</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">--parents</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILE</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TARGET_DIR</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==&gt;&quot;</span><span style="color: #007800;">$FILE</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
&nbsp;<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$BROWSEABLE</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$STG_OWNER</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; report <span style="color: #ff0000;">&quot;Music leech in progress.&quot;</span><br />
&nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$TARGET_DIR</span><span style="color: #007800;">$UUID</span><br />
&nbsp; <span style="color: #007800;">TARGET_DIR</span>=<span style="color: #007800;">$TARGET_DIR</span><span style="color: #007800;">$UUID</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$MPOINT</span><br />
&nbsp; sync_type \<span style="color: #000000; font-weight: bold;">*</span>mp3<br />
&nbsp; sync_type \<span style="color: #000000; font-weight: bold;">*</span>ogg<br />
&nbsp; sync_type \<span style="color: #000000; font-weight: bold;">*</span>avi<br />
&nbsp; sync_type \<span style="color: #000000; font-weight: bold;">*</span>flv<br />
&nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;skipping owned devices&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp;</code></fieldset></p><p>Ну и на последок: автоматом скопировать фотографии с карточки фотика, которую определяем по ууид.</p><p><fieldset><legend>bash</legend><code><br />
<span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #007800;">target_dir</span>=<span style="color: #ff0000;">&quot;/home/aifiltr0/Фотографии&quot;</span><br />
<span style="color: #007800;">target_vid_dir</span>=<span style="color: #ff0000;">&quot;/home/aifiltr0/кЫно/видеозаписи/с коммуникатора&quot;</span><br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$BROWSEABLE</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$UUID</span> == <span style="color: #ff0000;">&quot;B4DC_999E&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp;<br />
&nbsp; report <span style="color: #ff0000;">&quot;This is your smartphone's card. Multimedia data transfer in progress.&quot;</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MPOINT</span>/My Pictures&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-iname</span> \<span style="color: #000000; font-weight: bold;">*</span>jpg<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$target_dir</span>/<span style="color: #007800;">$file</span>&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">done</span>;<br />
&nbsp;<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MPOINT</span>/My Videos&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-iname</span> \<span style="color: #000000; font-weight: bold;">*</span>3gp<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$target_vid_dir</span>/<span style="color: #007800;">$file</span>&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">done</span>;<br />
&nbsp;<br />
&nbsp; report <span style="color: #ff0000;">&quot;Transfer complete&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp;</code></fieldset></p><p>Все скрипты пронумерованы, то есть в имени в лучших традиция 00, 01, 02 в самом начале. Так можно задать очередность выполнения. Все. спасибо radiofun за начальный скрипт.</p><p>З.Ы. Там в самом первом баш скрипте определен report() так как я кдешник, вывожу сообщения через kdialog и на синтез речи. гномерам и прочим просто поправить и все будет ку. Не забудьте на всех скриптах сделать chmod +x ну и запускать ./mount_manager.py при загрузке. Вот собственно и все, хотя по хорошему надо бы еще и код подчистить местами. </p><p>Автор статьи <b><a href="/profile.php?user=AiFiLTr0">AiFiLTr0</a></b></p><p>Репост статьи с &nbsp;<a href="http://invyl.ath.cx:8080/wp/?p=35">http://invyl.ath.cx:8080/wp/?p=35</a></p>]]></description>
</item>
</channel>
</rss>