{"id":610,"date":"2009-06-23T01:10:06","date_gmt":"2009-06-22T22:10:06","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=610"},"modified":"2009-10-03T12:29:19","modified_gmt":"2009-10-03T09:29:19","slug":"using-halevt-to-automount-media-and-make-them-appear-on-rox-desktop","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2009\/06\/23\/using-halevt-to-automount-media-and-make-them-appear-on-rox-desktop\/","title":{"rendered":"Using halevt to automount media and make them appear on ROX desktop"},"content":{"rendered":"<p>With the recent addition of <a href=\"http:\/\/packages.gentoo.org\/package\/sys-apps\/halevt\">halevt in Gentoo&#8217;s portage<\/a> it is now relatively easy to automatically mount media like USB sticks and CD\/DVD discs on \/media. <\/p>\n<p>What I wanted to do was to emulate my <a href=\"http:\/\/www.void.gr\/kargig\/blog\/2006\/07\/24\/create-icons-on-rox-desktop-of-automounted-media-by-ivman\/\">previous set of configs<\/a> and <a href=\"http:\/\/www.void.gr\/kargig\/blog\/2006\/09\/23\/rox-icons-ivman-continued\/\">scripts<\/a> that ivman used to create icons of automatically mounted media on <a href=\"http:\/\/roscidus.com\/desktop\/node\/169\">ROX desktop (called pinboard)<\/a>. I am using ROX pinboard on top of my favorite window manager, <a href=\"http:\/\/fluxbox.org\">fluxbox<\/a>.<\/p>\n<p>The idea is that <a href=\"http:\/\/www.nongnu.org\/halevt\/\">halevt<\/a> is started by the fluxbox startup config file and when a new device is attached to the computer, halevt config calls a script that creates an icon on the ROX pinboard using ROX rpc. When a device needs to be removed ROX pinboard is configured to call a special eject command that checks for a couple of things before unmounting the device and calling the script to remove the icon from ROX pinboard.<br \/>\nApart from automatically mounting\/unmounting of devices I have also added a nice option in the halevt config to unmount and eject the CD\/DVD drive when the eject button on the device is used and of course when the CD\/DVD is not in use. That emulates a bit the windows behavior that so many users have gotten used to.<\/p>\n<p>Since the script used by halevt involves a lot of file reading\/writing and parsing I thought it would be wise to convert my old <a href=\"http:\/\/www.void.gr\/kargig\/blog\/2006\/09\/23\/rox-icons-ivman-continued\/\">rox.panelput bash script<\/a> to perl. And I was correct, the speed difference, even for such simple tasks is more than noticeable.<\/p>\n<p>The <strong>installation process<\/strong>. Please take notice of the user executing the commands, $ is for normal user, # is for root:<br \/>\n0) <strong>create \/usr\/local\/bin\/ path and put it in your shell&#8217;s PATH<\/strong><br \/>\n<code># mkdir \/usr\/local\/bin<br \/>\n$ echo \"export PATH=$PATH:\/usr\/local\/bin\/\" >> ~\/.bashrc<\/code><\/p>\n<p>1) <strong>install halevt<\/strong><br \/>\n<code># echo \"sys-apps\/halevt ~x86\" >> \/etc\/portage\/package.keywords<br \/>\n# emerge halevt<br \/>\n<\/code><br \/>\n<!--more--><br \/>\n2) create <strong>~\/.halevt\/HalevtConfigActions.xml<\/strong> in your home directory:<br \/>\nFile: <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/HalevtConfigActions.xml'>HalevtConfigActions.xml<\/a>  (right click->Save-as)<\/p>\n<p>3) <strong>Create \/usr\/bin\/eject.hal<\/strong>. Take notice that the script uses bash and not dash!<br \/>\n<pre><code2>#!\/bin\/bash\nif [ -z $1 ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Usage: eject.hal &lt;device&gt;&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;exit\nelse\n&nbsp;&nbsp;echo &quot;$1&quot; | egrep &quot;^\/dev&quot;\n&nbsp;&nbsp;if [ &quot;$?&quot; == &quot;0&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;#echo &quot;Device First, find mount point&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;TOSCAN=`echo &quot;$1&quot; | sed -e &#039;s\/ \/\\\\\\\\\\\\\\\\040\/g&#039;`\n&nbsp;&nbsp;&nbsp;&nbsp;TOUMOUNT=`grep &quot;$TOSCAN&quot; \/proc\/mounts | cut -d&quot; &quot; -f2`\n&nbsp;&nbsp;&nbsp;&nbsp;UDI=`hal-find-by-property --key volume.mount_point --string &quot;$TOUMOUNT&quot;`\n&nbsp;&nbsp;&nbsp;&nbsp;DISC=`hal-get-property --udi &quot;$UDI&quot; --key volume.is_disc`\n&nbsp;&nbsp;&nbsp;&nbsp;\/usr\/local\/bin\/rox.panelput.pl Remove &quot;$TOUMOUNT&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;halevt-umount &quot;$1&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;halevt-umount -s\n&nbsp;&nbsp;&nbsp;&nbsp;if [ &quot;$DISC&quot; == &quot;true&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/usr\/bin\/eject -p &quot;$1&quot; &amp;&gt;\/dev\/null\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;#echo &quot;Mount Point First, find device&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;UDI=`hal-find-by-property --key volume.mount_point --string &quot;$1&quot;`\n&nbsp;&nbsp;&nbsp;&nbsp;DISC=`hal-get-property --udi &quot;$UDI&quot; --key volume.is_disc`\n&nbsp;&nbsp;&nbsp;&nbsp;TOSCAN=`echo &quot;$1&quot; | sed -e &#039;s\/ \/\\\\\\\\\\\\\\\\040\/g&#039;`\n&nbsp;&nbsp;&nbsp;&nbsp;TOUMOUNT=`grep &quot;$TOSCAN&quot; \/proc\/mounts | cut -d&quot; &quot; -f1`\n&nbsp;&nbsp;&nbsp;&nbsp;\/usr\/local\/bin\/rox.panelput.pl Remove &quot;$1&quot; nowait\n&nbsp;&nbsp;&nbsp;&nbsp;halevt-umount &quot;$1&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;halevt-umount -s\n&nbsp;&nbsp;&nbsp;&nbsp;if [ &quot;$DISC&quot; == &quot;true&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/usr\/bin\/eject -p &quot;$TOUMOUNT&quot; &amp;&gt;\/dev\/null\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;fi\nfi\n&lt;\/device&gt;<\/code2><\/pre><br \/>\nFile: <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/eject.hal'>eject.hal<\/a><\/p>\n<p>4) <strong>Create \/usr\/bin\/rox.panelput.pl<\/strong> perl script. The script is written very simplistically to be easily understandable and changable.<br \/>\nFile: <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/rox.panelput.pl'>rox.panelput.pl<\/a><\/p>\n<p>5) <strong>Start halevt from fluxbox startup<\/strong>..make sure <strong>~\/.fluxbox\/startup<\/strong> file contains at least the following, changing YOURUSERNAME to the one appropriate:<br \/>\n<code>\/usr\/local\/bin\/rox.panelput.pl Restore<br \/>\nkillall -9 halevt; halevt -f -u YOURUSERNAME -g plugdev &<br \/>\n\/usr\/bin\/rox -p pinboard<\/code><\/p>\n<p>6) <strong>go to ROX options and change &#8216;eject command&#8217; to use eject.hal<\/strong><br \/>\n<a href=\"http:\/\/www.void.gr\/kargig\/blog\/wp-content\/rox-using-eject-hal-screenshot.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.void.gr\/kargig\/blog\/wp-content\/rox-using-eject-hal-screenshot-300x186.jpg\" alt=\"rox-using-eject-hal-screenshot\" title=\"rox-using-eject-hal-screenshot\" width=\"300\" height=\"186\" class=\"alignnone size-medium wp-image-622\" srcset=\"https:\/\/www.void.gr\/kargig\/blog\/wp-content\/rox-using-eject-hal-screenshot-300x186.jpg 300w, https:\/\/www.void.gr\/kargig\/blog\/wp-content\/rox-using-eject-hal-screenshot.jpg 740w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>That should be all. Upon fluxbox restart halevt should start and when you plug in your usb the set of scripts will create an icons on ROX pinboard for you.<\/p>\n<p>Example:<br \/>\n<a href=\"http:\/\/www.void.gr\/kargig\/blog\/wp-content\/usb-mounted-by-halevt-and-rox.panelput.pl.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.void.gr\/kargig\/blog\/wp-content\/usb-mounted-by-halevt-and-rox.panelput.pl-300x240.jpg\" alt=\"usb-mounted-by-halevt-and-rox.panelput.pl\" title=\"usb-mounted-by-halevt-and-rox.panelput.pl\" width=\"300\" height=\"240\" class=\"alignnone size-medium wp-image-624\" srcset=\"https:\/\/www.void.gr\/kargig\/blog\/wp-content\/usb-mounted-by-halevt-and-rox.panelput.pl-300x240.jpg 300w, https:\/\/www.void.gr\/kargig\/blog\/wp-content\/usb-mounted-by-halevt-and-rox.panelput.pl-1024x819.jpg 1024w, https:\/\/www.void.gr\/kargig\/blog\/wp-content\/usb-mounted-by-halevt-and-rox.panelput.pl.jpg 1280w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>References: <a href=\"http:\/\/forums.gentoo.org\/viewtopic-t-731555-highlight-halevt.html\">http:\/\/forums.gentoo.org\/viewtopic-t-731555-highlight-halevt.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the recent addition of halevt in Gentoo&#8217;s portage it is now relatively easy to automatically mount media like USB sticks and CD\/DVD discs on \/media. What I wanted to do was to emulate my previous set of configs and scripts that ivman used to create icons of automatically mounted media on ROX desktop (called [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[3],"tags":[102,25,135,601,100,137,134,48,136,86,103],"class_list":["post-610","post","type-post","status-publish","format-standard","hentry","category-linux","tag-automount","tag-bash","tag-desktop","tag-gentoo","tag-halevt","tag-icons","tag-mount","tag-perl","tag-pinboard","tag-portage","tag-rox"],"aioseo_notices":[],"views":18017,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=610"}],"version-history":[{"count":26,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":636,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/610\/revisions\/636"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}