{"id":834,"date":"2015-11-03T19:09:05","date_gmt":"2015-11-03T18:09:05","guid":{"rendered":"http:\/\/www.hauweele.net\/~gawen\/blog\/?p=834"},"modified":"2015-11-03T19:27:24","modified_gmt":"2015-11-03T18:27:24","slug":"use-notify-send-as-root","status":"publish","type":"post","link":"https:\/\/hauweele.net\/~gawen\/blog\/?p=834","title":{"rendered":"Use notify-send as root"},"content":{"rendered":"<p>The <a href=\"https:\/\/github.com\/vermaden\/automount\">automount<\/a> script is a neat devd based automounter for FreeBSD. Just <code>pkg install automount<\/code> and all your removable media will mount themselves automatically in <code>\/media<\/code> when you plug them in. It&#8217;s very clean. You may also check <a href=\"https:\/\/raw.githubusercontent.com\/gawen947\/scripts\/master\/bin\/vumount.sh\">vumount<\/a>, a short script that I made to list all removable media and remove the mount point when you unmount them.<\/p>\n<p>It&#8217;s possible to configure automount to send a notification to your desktop using <i>notify-send<\/i> from libnotify. What it does exactly is (as root):<\/p>\n<pre>env DISPLAY=:0 notify-send automount \"Device '${1}' mounted on '${3}' directory.\"\r\n<\/pre>\n<p>Except that it doesn&#8217;t work&#8230; I started <i>dbus-monitor<\/i> and tried notify-send as root (from ttyv2) but didn&#8217;t receive anything and notify-send did not complain. So I tried to start dbus-monitor from root instead, in the hope that it would be a bit more verbose than notify-send. I got this error message:<\/p>\n<blockquote><p>Failed to open connection to session message bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.<\/p><\/blockquote>\n<p>By default DBus sessions are private and don&#8217;t accept connections from other users than the one that own the bus, even root. The solution is to configure DBus to allow root on the session bus. Edit <code>\/usr\/local\/etc\/dbus-1\/session.conf<\/code> and add this line to the default policy:<\/p>\n<pre>&lt;allow user=\"root\"\/&gt;<\/pre>\n<p>But you still need tell DBus how to connect to the session bus. To do so you have to specify the session bus address in <code>DBUS_SESSION_BUS_ADDRESS<\/code>. Fortunately automount is a shell script, so you can fetch and export the bus address from its configuration file. Just add this to <code>\/usr\/local\/etc\/automount.conf<\/code>:<\/p>\n<pre>\r\n# Load DBus session bus address\r\nDBUS_USER=your-user\r\nif [ -d \/home\/$DBUS_USER\/.dbus\/session-bus ]\r\nthen\r\n  dbus_file=$(ls -t1 \/home\/$DBUS_USER\/.dbus\/session-bus | head -n1)\r\n  export DBUS_SESSION_BUS_ADDRESS=$(cat \/home\/$DBUS_USER\/.dbus\/session-bus\/$dbus_file | \\\r\n                                    grep \"DBUS_SESSION_BUS_ADDRESS=\" | \\\r\n                                    sed 's\/[A-Z_]*=\/\/')\r\nfi\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The automount script is a neat devd based automounter for FreeBSD. Just pkg install automount and all your removable media will mount themselves automatically in \/media when you plug them in. It&#8217;s very clean. You may also check vumount, a &hellip; <a href=\"https:\/\/hauweele.net\/~gawen\/blog\/?p=834\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[641,434,638,640,389,637,243,639],"class_list":["post-834","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-automount","tag-dbus","tag-dbus-monitor","tag-devd","tag-freebsd","tag-notify-send","tag-root","tag-session-bus"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=834"}],"version-history":[{"count":0,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions"}],"wp:attachment":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}