<?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:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ninetynine.be &#187; ruben</title>
	<atom:link href="http://ninetynine.be/blog/author/ruben/feed/" rel="self" type="application/rss+xml" />
	<link>http://ninetynine.be/blog</link>
	<description>Just another blog with no useful content on it at all.</description>
	<lastBuildDate>Sun, 08 Jan 2012 10:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Setting up OpenCV 2.3.1 and Netbeans 7.1 on Ubuntu Oneiric 11.10</title>
		<link>http://ninetynine.be/blog/2012/01/setting-up-opencv-2-3-1-and-netbeans-7-1-on-ubuntu-oneiric-11-10/</link>
		<comments>http://ninetynine.be/blog/2012/01/setting-up-opencv-2-3-1-and-netbeans-7-1-on-ubuntu-oneiric-11-10/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 22:05:25 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=839</guid>
		<description><![CDATA[A tutorial for installing OpenCV 2.3.1 on Ubuntu 11.10 using Gijs Molenaar (Gijzelaar) PPA. The tutorial shows how to configure Netbeans 7.1 and show a small example in C++.]]></description>
			<content:encoded><![CDATA[<p>Hi there,</p>
<blockquote><p><em>This is a follow-up of my previous post: <a href="http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/" title="Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10" target="_blank">Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10</a>. A couple of days ago Gijzelaar&#8217;s PPA for OpenCV has updated from 2.3 to version 2.3.1. So I thought I&#8217;d share this with you guys. I also think this is a slightly better approach</em></p>
<p>OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real time computer vision, developed by Intel and now supported by Willow Garage. It is free for use under the open source BSD license. The library is cross-platform. It focuses mainly on real-time image processing. (<a href="http://en.wikipedia.org/wiki/OpenCV" title="Wikipedia" target="_blank">Wikipedia</a>)</p></blockquote>
<p>The upgrade did leave my machine with some broken packages, so be cautious! I managed to fix the broken packages, but that&#8217;s another story and it probably was a rare case.</p>
<p>Okay, so here is a quick guide:</p>
<h2>1. Installation of OpenCV 2.3.1</h2>
<p>Launch a terminal and execute these commands. This adds the PPA of our friend <a href="https://launchpad.net/~gijzelaar/+archive/opencv2.3" title="Gijzelaar PPA" target="_blank">Gijs Molenaar</a>, which now contains OpenCV 2.3.1.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">$ sudo add-apt-repository ppa:gijzelaar/cuda
$ sudo add-apt-repository ppa:gijzelaar/opencv2.3
$ sudo apt-get update
$ sudo apt-get install libopencv-dev</pre></div></div>

<p></code></p>
<h2>2. Installation of Netbeans 7.1</h2>
<p>Ubuntu 11.10 also comes with Netbeans 6.9, just download the Netbeans 7.1 from the <a href="http://netbeans.org" title="Netbeans Homepage" target="_blank">Netbeans Homepage</a> and you’re all set. Be sure you download the version with C/C++ support.</p>
<p><span id="more-839"></span></p>
<h2>3. Set the project properties</h2>
<p>Create a new C/C++ project in Netbeans 7.1. First, set the project properties correctly. These settings worked for me.</p>
<p>In the <em>C++ Compiler dialog</em> add “/usr/locale/opencv2″ to the “Include Directories” field. </p>
<p>In the <em>Linker Dialog</em>, Click on the &#8220;&#8230;&#8221; button for <em>Libraries</em>, a new Dialog appears, choose &#8220;Add PkgConfig Library&#8230;&#8221;. Search for &#8220;opencv&#8221; and add it.</p>
<p>This should add the following library expression <code></p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">`pkg-config --libs opencv`</pre></div></div>

<p></code> (Note that this is a better solution than in my previous post)</p>

<a href='http://ninetynine.be/blog/2012/01/setting-up-opencv-2-3-1-and-netbeans-7-1-on-ubuntu-oneiric-11-10/compiler_dialog/' title='compiler_dialog'><img width="150" height="150" src="http://ninetynine.be/blog/wp-content/uploads/2012/01/compiler_dialog-150x150.png" class="attachment-thumbnail" alt="compiler_dialog" title="compiler_dialog" /></a>
<a href='http://ninetynine.be/blog/2012/01/setting-up-opencv-2-3-1-and-netbeans-7-1-on-ubuntu-oneiric-11-10/linker_dialog/' title='linker_dialog'><img width="150" height="150" src="http://ninetynine.be/blog/wp-content/uploads/2012/01/linker_dialog-150x150.png" class="attachment-thumbnail" alt="linker_dialog" title="linker_dialog" /></a>

<h2>4. Set the includes</h2>
<p>Note: this has also changed since my previous post!</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">#include &quot;opencv2/highgui/highgui.hpp&quot;
#include &quot;opencv2/core/core.hpp&quot; 
#include &quot;opencv2/imgproc/imgproc.hpp&quot;</pre></div></div>

<p></code></p>
<p>I find it easy to work with the cv and std namespace by default, so I don’t have to type “cv::” before every function.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">using namespace cv;
using namespace std;</pre></div></div>

<p></code></p>
<p>And if we re-use our previous example (yea, I&#8217;m lazy), a little program that shows an image, you have something like this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">#include &quot;opencv2/highgui/highgui.hpp&quot;
#include &quot;opencv2/core/core.hpp&quot; 
#include &quot;opencv2/imgproc/imgproc.hpp&quot;
#include &lt;iostream&gt;
using namespace cv;
using namespace std;
&nbsp;
int main(int argc, char *argv[]) {
&nbsp;
    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
&nbsp;
    if (!image.data) // Check for invalid input
    {
        cout &lt;&lt; &quot;Could not open or find the image&quot; &lt;&lt; endl;
        return -1;
    }
&nbsp;
    namedWindow(&quot;Display window&quot;, CV_WINDOW_AUTOSIZE); // Create a window for display.
    imshow(&quot;Display window&quot;, image);
&nbsp;
    return 0;
}</pre></div></div>

<p></code></p>
<p>OpenCV has really poor/decentralized documentation, which makes these simple things over-complicated. I hope this helps some people struggling with getting OpenCV to work. Let me know if it works!</p>
<p>Cheers!<br />
Ruben Verhack</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2012/01/setting-up-opencv-2-3-1-and-netbeans-7-1-on-ubuntu-oneiric-11-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10</title>
		<link>http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/</link>
		<comments>http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 11:47:18 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=795</guid>
		<description><![CDATA[I don&#8217;t like Eclipse. There, I said it. However, in the past Netbeans and C/C++ didn&#8217;t play along. Since I upgraded to Ubuntu 11.10, I decided to give it another go, and the results are pleasing! As there was no install guide available online for my situation, I decided to summarize the steps I used in order [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ninetynine.be/blog/wp-content/uploads/2011/11/netbeans-logo.png" rel="lightbox[795]" title="netbeans-logo"><img src="http://ninetynine.be/blog/wp-content/uploads/2011/11/netbeans-logo.png" alt="" title="netbeans-logo" width="224" height="224" class="alignleft size-full wp-image-835" /></a><br />
<address>I don&#8217;t like Eclipse. There, I said it. However, in the past Netbeans and C/C++ didn&#8217;t play along. Since I upgraded to Ubuntu 11.10, I decided to give it another go, and the results are pleasing! As there was no install guide available online for my situation, I decided to summarize the steps I used in order to get things running.</address>
<address> </address>
<p>OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real time computer vision, developed by Intel and now supported by Willow Garage. It is free for use under the open source BSD license. The library is cross-platform. It focuses mainly on real-time image processing.</p>
<p>&nbsp;</p>
<h2>1. Installation of OpenCV 2.3</h2>
<p>First of all, Ubuntu 11.10 comes with OpenCV 2.1, and I wanted 2.3. Luckely our friend <a href="https://launchpad.net/~gijzelaar/+archive/opencv2.3">Gijs Molenaar provides us with a PPA for OpenCV 2.3</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">$ sudo add-apt-repository ppa:gijzelaar/cuda
$ sudo add-apt-repository ppa:gijzelaar/opencv2.3
$ sudo apt-get update
$ sudo apt-get install libopencv-dev</pre></div></div>

<p>(Little notice: the package that comes with Ubuntu 11.10 is called libcv-dev, however in the PPA of Gijs the package is called libopencv-dev)</p>
<p>You might also want to install other packages related to OpenCV, just search for them in the Ubuntu Software Center. However, libopencv-dev will do.</p>
<h2>2. Installation of Netbeans 7.0</h2>
<p>Ubuntu 11.10 also comes with Netbeans 6.9, just download the new version from <a href="http://netbeans.org">http://netbeans.org</a> and you&#8217;re all set. Be sure you download the version with C/C++ support.</p>
<h2>3. Set the project properties</h2>
<p>Then create a new C/C++ project in Netbeans 7.0. First, set the project properties correctly. These settings worked for me.</p>
<p>In the C++ Compiler dialog add &#8220;/usr/locale/opencv2&#8243; to the &#8220;Include Directories&#8221; field, also do this in the Linker dialog. In the Linker Dialog, also add the libraries opencv_core and opencv_highgui. You can find these libraries directly under &#8220;/usr/lib/&#8221;.</p>

<a href='http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/schermafdruk-op-2011-11-26-120551/' title='C++ Compiler Config'><img width="150" height="150" src="http://ninetynine.be/blog/wp-content/uploads/2011/11/Schermafdruk-op-2011-11-26-120551-150x150.png" class="attachment-thumbnail" alt="C++ Compiler Config" title="C++ Compiler Config" /></a>
<a href='http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/schermafdruk-op-2011-11-26-120533/' title='Linker Config'><img width="150" height="150" src="http://ninetynine.be/blog/wp-content/uploads/2011/11/Schermafdruk-op-2011-11-26-120533-150x150.png" class="attachment-thumbnail" alt="Linker Config" title="Linker Config" /></a>
<a href='http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/netbeans-logo/' title='netbeans-logo'><img width="150" height="150" src="http://ninetynine.be/blog/wp-content/uploads/2011/11/netbeans-logo-150x150.png" class="attachment-thumbnail" alt="netbeans-logo" title="netbeans-logo" /></a>

<h2>4. Set the includes</h2>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">#include &lt;opencv2/core/core.hpp&gt;
#include &lt;opencv2/highgui/highgui.hpp&gt;</pre></div></div>

<p>I find it easy to work with the cv and std namespace by default, so I don&#8217;t have to type &#8220;cv::&#8221; before every function.</p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">using namespace cv;
using namespace std;</pre></div></div>

<p>And if we put this all together in to a little program that shows an image, you have something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="default" style="font-family:monospace;">#include &lt;opencv2/core/core.hpp&gt;
#include &lt;opencv2/highgui/highgui.hpp&gt;
#include &lt;iostream&gt;
using namespace cv;
using namespace std;
&nbsp;
int main(int argc, char *argv[]) {
&nbsp;
    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
&nbsp;
    if (!image.data) // Check for invalid input
    {
        cout &amp;lt;&amp;lt; &quot;Could not open or find the image&quot; &amp;lt;&amp;lt; endl;
        return -1;
    }
&nbsp;
    namedWindow(&quot;Display window&quot;, CV_WINDOW_AUTOSIZE); // Create a window for display.
    imshow(&quot;Display window&quot;, image);
&nbsp;
    return 0;
}</pre></div></div>

<p>There we go: Our first OpenCV program in Netbeans! I hope this will work for you too <img src='http://ninetynine.be/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2011/11/setting-up-opencv-2-3-and-netbeans-7-0-on-ubuntu-oneiric-11-10/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Quick workaround for missing &#8220;switch-display&#8221;-key or &#8220;lcd/crt&#8221;-key</title>
		<link>http://ninetynine.be/blog/2010/05/quick-workaround-for-missing-switch-display-key-or-lcdcrt-key-on-ubuntu/</link>
		<comments>http://ninetynine.be/blog/2010/05/quick-workaround-for-missing-switch-display-key-or-lcdcrt-key-on-ubuntu/#comments</comments>
		<pubDate>Fri, 21 May 2010 19:53:52 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Dell]]></category>
		<category><![CDATA[switch displays]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=599</guid>
		<description><![CDATA[What a wonderful day it is, sir It&#8217;s been a while since I wrote something, but I liked to share this with you all. I bought a new Dell Studio 1558 and all the fn-keys were working except the one to switch the displays&#8230; I enjoy switching between dual-screen, using only my external 22&#8243; or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ninetynine.be/blog/wp-content/uploads/2010/05/Schermafdruk-Sneltoetsen.png" rel="lightbox[599]" title="gnome-keybinding-properties"><img class="size-medium wp-image-603 alignright" title="gnome-keybinding-properties" src="http://ninetynine.be/blog/wp-content/uploads/2010/05/Schermafdruk-Sneltoetsen-300x141.png" alt="gnome-keybinding-properties" width="300" height="141" /></a><strong>What a wonderful day it is, sir</strong></p>
<p>It&#8217;s been a while since I wrote something, but I liked to share this with you all. I bought a new Dell Studio 1558 and all the fn-keys were working except the one to switch the displays&#8230;</p>
<p>I enjoy switching between dual-screen, using only my external 22&#8243; or using only my laptop, when I&#8217;m on the road. So I was looking for a workaround.</p>
<p>This laptop, is my first machine with Ubuntu that uses an ATI graphics chip, so this was all quite new to me. But I have to say; I&#8217;m very very pleased with it.</p>
<p>Ok, so what do you have to do to get things working?</p>
<p><strong>1. Create the script</strong><br />
Create the script, I called it toggleDisplay.sh and this is how it looks in my case:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Script to toggle display configuration on Dell Studio 1558</span>
<span style="color: #666666; font-style: italic;"># author: Ruben Verhack</span>
&nbsp;
<span style="color: #007800;">config</span>=<span style="color: #ff0000;">&quot;/tmp/display.conf&quot;</span>
<span style="color: #007800;">current</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$config</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check if config exists</span>
<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;">-a</span> <span style="color: #007800;">$config</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #666666; font-style: italic;"># Empty file executes default</span>
   <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$config</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check if CRT2 is connected</span>
<span style="color: #000000; font-weight: bold;">if</span> xrandr <span style="color: #660033;">-q</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;CRT2 connected&quot;</span>
<span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #666666; font-style: italic;"># Toggle between states</span>
   <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$current</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
   <span style="color: #ff0000;">''</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #666666; font-style: italic;"># default</span>
      xrandr <span style="color: #660033;">--output</span> LVDS <span style="color: #660033;">--auto</span> <span style="color: #660033;">--output</span> CRT2 <span style="color: #660033;">--left-of</span> LVDS <span style="color: #660033;">--output</span> CRT2 <span style="color: #660033;">--auto</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dual&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$config</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #ff0000;">'dual'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #666666; font-style: italic;"># was dual, now external only</span>
      xrandr <span style="color: #660033;">--output</span> LVDS <span style="color: #660033;">--off</span> <span style="color: #660033;">--output</span> CRT2 <span style="color: #660033;">--auto</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;external&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$config</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #ff0000;">'external'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #666666; font-style: italic;"># was external, now laptop only</span>
      xrandr <span style="color: #660033;">--output</span> LVDS <span style="color: #660033;">--auto</span> <span style="color: #660033;">--output</span> CRT2 <span style="color: #660033;">--off</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;laptop&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$config</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #ff0000;">'laptop'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #666666; font-style: italic;"># was laptop, now both</span>
      xrandr <span style="color: #660033;">--output</span> LVDS <span style="color: #660033;">--auto</span> <span style="color: #660033;">--output</span> CRT2 <span style="color: #660033;">--left-of</span> LVDS <span style="color: #660033;">--output</span> CRT2 <span style="color: #660033;">--auto</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dual&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$config</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">else</span>
   xrandr <span style="color: #660033;">--output</span> LVDS <span style="color: #660033;">--auto</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>This toggles your displays from dual screen to external only to laptop only, and from there to dual screen again. Note that my monitors were called LVDS and CRT2, you can easily check how your monitors are called by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xrandr <span style="color: #660033;">-q</span></pre></div></div>

<p><span id="more-599"></span><br />
It&#8217;s pretty easy, huh?</p>
<p><strong>2. Bind the key to the script</strong><br />
Make sure you given the script rights to be executed, let&#8217;s assume you&#8217;ve put the shell script in your home-folder.<br />
<code>chmod +x ~/toggleDisplay.sh</code></p>
<p>Next launch Gnome Keybinding by launching System &gt; Preferences &gt; Keybindings .</p>
<p>Add a custom action:<br />
- Name: Toggle Displays<br />
- Action: sh ~/toggleDisplay.sh</p>
<p>Select it, click on the shortcut and press the key you want to bind to this action and presto!</p>
<p>I hope this helped someone!</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2010/05/quick-workaround-for-missing-switch-display-key-or-lcdcrt-key-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Use CodeIgniter on localhost with Ubuntu Jaunty</title>
		<link>http://ninetynine.be/blog/2009/05/use-codeigniter-on-localhost-with-ubuntu-jaunty/</link>
		<comments>http://ninetynine.be/blog/2009/05/use-codeigniter-on-localhost-with-ubuntu-jaunty/#comments</comments>
		<pubDate>Sat, 02 May 2009 11:22:55 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Xampp]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=195</guid>
		<description><![CDATA[Hi, As a PHP developer it comes in handy to run your websites without having to upload them to your server. You can run them on your own computer if you want to, there isn&#8217;t much to it. I also like using the CodeIgniter framework for my projects, this is a really speeds up the [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>As a PHP developer it comes in handy to run your websites without having to upload them to your server. You can run them on your own computer if you want to, there isn&#8217;t much to it. I also like using the <a href="http://www.codeigniter.com">CodeIgniter framework</a> for my projects, this is a really speeds up the whole process!</p>
<p>I will take you through the basic steps to set up your localhost to get CodeIgniter running.<br />
<strong><br />
1) Use Synaptic package manager to install &#8220;apache2&#8243;, &#8220;php5&#8243; and &#8220;mysql-server&#8221;.</strong></p>
<p>During the installation you will be asked to enter the password for the root user for your mysql-server.</p>
<p><strong>2) Create a symbolic link, so that when you go to localhost in your browser, you get the website you want.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> www<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>website www</pre></div></div>

<p>Always look before you delete something with &#8220;rm -r&#8221;, normally there should only be a index.html file in your www/ folder.</p>
<p>I prefer creating a link to my website that I put somewhere in my home directory, as this is being back-upped frequently, and is on another partition.<br />
<br/><span id="more-195"></span><br />
<strong><br />
3) Install the package &#8220;phpmyadmin&#8221; through synaptic.</strong></p>
<p>It is important that you wait to install phpmyadmin until you have installed the other packages and created the symbolic link. Otherwise it can be a mess to get things running.</p>
<p><strong>4) To allow mod-rewrite, to get the clean CodeIgniter URL&#8217;s, you need to do the following.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod rewrite
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>default</pre></div></div>

<p>You will see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        DocumentRoot <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www
        <span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #000000; font-weight: bold;">/&gt;</span>
                Options FollowSymLinks
                AllowOverride None
        <span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/&gt;</span>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        <span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Change the AllowOverride&#8217;s to All.</p>
<p><strong>5) Restart Apache</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p>This wasn&#8217;t so hard, and it really makes life easier!</p>
<p>Note: You can&#8217;t use the function mail() or CodeIgniter&#8217;s mail-class without further configuration. I won&#8217;t go into details about this.</p>
<p>Also note that there are many ways to tackle this, this is only one easy suggestion. If you need to switch a lot between different websites, then changing the symbolic link each time is too much work. You can check out <a href="http://www.debian-administration.org/articles/412">this article here</a>.</p>
<p>Happy coding!</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/05/use-codeigniter-on-localhost-with-ubuntu-jaunty/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Photoshop CS4 on Ubuntu 9.04</title>
		<link>http://ninetynine.be/blog/2009/04/photoshop-cs4-on-ubuntu-904/</link>
		<comments>http://ninetynine.be/blog/2009/04/photoshop-cs4-on-ubuntu-904/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 20:08:07 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=181</guid>
		<description><![CDATA[Yes, it is possible! To my own suprise, I was able to install Photoshop CS4 on Ubuntu. I did it on a fresh install of Ubuntu 9.04 RC. It has known to work on Ubuntu 8.10, but it gave me a segmentation fault, probably because I had been messing around . I tested it with [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ninetynine.be/blog/wp-content/uploads/2009/04/pscs4ubuntu9042-300x177.png" alt="Photoshop 9.04 on Ubuntu" title="Photoshop 9.04 on Ubuntu" width="300" height="177" class="alignleft size-medium wp-image-193" />Yes, it is possible! To my own suprise, I was able to install Photoshop CS4 on Ubuntu.</p>
<p>I did it on a fresh install of Ubuntu 9.04 RC. It has known to work on Ubuntu 8.10, but it gave me a segmentation fault, probably because I had been messing around <img src='http://ninetynine.be/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . I tested it with the trial version downloaded from <a href="http://adobe.com">adobe.com</a>.</p>
<p>To do so, you need <a href="http://www.winehq.org/">Wine</a>. I will take you through the steps that I&#8217;ve taken:<br />
<br/><span id="more-181"></span></p>
<p>1. If you have used wine before, please start of with a clean .wine folder. Or bottle you Photoshop by doing every action with a specific wineprefix.<br />
2. Install Wine 1.1.16 from <a href="http://wine.budgetdedicated.com/archive/index.html">here</a>.<br />
3. Download winetricks and install necessary libraries. Also make sure you have a decent driver for your graphics card installed.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.kegel.com<span style="color: #000000; font-weight: bold;">/</span>wine<span style="color: #000000; font-weight: bold;">/</span>winetricks
<span style="color: #c20cb9; font-weight: bold;">sh</span> winetricks msxml6 gdiplus gecko vcrun2005
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> msttcorefonts</pre></div></div>

<p>3. If you have a non-english Ubuntu installed please put LANG=C before the following command like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LANG</span>=C wine Setup.exe</pre></div></div>

<p>4. Install Wine 1.1.19 from <a href="http://wine.budgetdedicated.com/archive/index.html">here</a>, to fix the menu bar bug.<br />
5. To fix the text-layer bug, put atmlib.dll in &#8220;~/.wine/drive_c/windows/system 32&#8243;. You can download it from several places if you search it on google.<br />
6. Run it!</p>
<p>It was tested on an amd64 and i386.</p>
<p>The reason why you have to set the &#8220;LANG&#8221; variable, is that Photoshop searches for files in &#8220;Program files&#8221;, if you don&#8217;t set it, wine installs it into a local translation of Program files.</p>
<p>Very happy that Wine made such a big progress over the last years. But there are a lot of regressions in the last versions. That is the reason you sometimes have to try other versions of wine for the installer. But 1.1.16 and 1.1.19 are not stable versions, so I forgive them. Last version that was declared stable till today was 1.0.1.</p>
<p>I also got Ableton 7 and MS Office Excel, Word and Powerpoint 2007 working with wine!</p>
<p>Big thanks to Quitte for helping me out.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/04/photoshop-cs4-on-ubuntu-904/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Fix random crashes Firefox, Thunderbird and Evolution on Ubuntu 8.10</title>
		<link>http://ninetynine.be/blog/2009/04/fix-random-crashes-firefox-thunderbird-and-evolution-on-ubuntu-810/</link>
		<comments>http://ninetynine.be/blog/2009/04/fix-random-crashes-firefox-thunderbird-and-evolution-on-ubuntu-810/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 13:22:38 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[Evolution]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Thunderbird]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=104</guid>
		<description><![CDATA[What do you expect of a decent modern OS? A great browsing experience and a decent mail client. Since I upgraded to Ubuntu 8.10 I had troubles with random crashes of Firefox when loading pages, and entirely random crashes of Evolution mail client. So I switched to Thunderbird. But then same symptoms started showing. Giving [...]]]></description>
			<content:encoded><![CDATA[<p>What do you expect of a decent modern OS? A great browsing experience and a decent mail client. Since I upgraded to Ubuntu 8.10 I had troubles with random crashes of Firefox when loading pages, and entirely random crashes of Evolution mail client.</p>
<p>So I switched to Thunderbird. But then same symptoms started showing. Giving me 5-10 crashes of Thunderbird a day, and serious troubles on heavy browsing.</p>
<p>The first things to do when getting crashes of Mozilla products are:</p>
<ol>
<li> Make sure you don&#8217;t have a lethal combination of add-ons</li>
<li> Check if Flash isn&#8217;t the evil spirit haunting your browser, try the<a href="https://addons.mozilla.org/en/firefox/addon/433"> Flashblock add-on</a></li>
<li> Make a new profile for Firefox and Thunderbird, by renaming your old configuration. You can find the configuration folders in your home. Mostly ~/.mozilla for Firefox, and ~/.mozilla-thunderbird for Thunderbird.</li>
<li> Completely remove Firefox (make a backup of your configuration) and reïnstall it</li>
</ol>
<p>I tried every possible thing I could do to fix Thunderbird or Firefox. But then again, why was Evolution suffering as well? Well the deal was that I had <a href="http://www.webopedia.com/TERM/W/WINS.html">WINS resolution</a> enabled in <a href="http://en.wikipedia.org/wiki/Samba_(software)">Samba</a>. Found it in this <a href="https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/282287/comments/11">bug report</a>.</p>
<p>When upgrading to 8.10, Samba was upgraded too. This bug has been reported and hopefully will be solved in Ubuntu 9.04, launching 23rd of April.</p>
<p>So how do we fix this?</p>
<p><span id="more-104"></span><br />
Enter this in your console:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nsswitch.conf</pre></div></div>

<p>And look for a line like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hosts:          files mdns4_minimal <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">NOTFOUND</span>=<span style="color: #7a0874; font-weight: bold;">return</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> wins dns mdns4</pre></div></div>

<p>Change it into</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hosts:          files mdns4_minimal <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">NOTFOUND</span>=<span style="color: #7a0874; font-weight: bold;">return</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> dns mdns4</pre></div></div>

<p>and everything should go back to normal.</p>
<p>However the WINS resolution is a good tool in Samba. I don&#8217;t really need it, because I don&#8217;t have the need to use a local network with Windows computers, but I can imagine it&#8217;s not that pleasant for people who do. Downgrading your Samba (or Ubuntu) is another option.</p>
<p><a href="http://www.webopedia.com/TERM/W/WINS.html">WINS resolution</a> is used to communicate to Windows computers using their computer name, rather than their IP.</p>
<p>That&#8217;s it!</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/04/fix-random-crashes-firefox-thunderbird-and-evolution-on-ubuntu-810/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thickbox: reinitialize Thickbox after change by Ajax</title>
		<link>http://ninetynine.be/blog/2009/03/thickbox-reinitialize-thickbox-after-change-by-ajax/</link>
		<comments>http://ninetynine.be/blog/2009/03/thickbox-reinitialize-thickbox-after-change-by-ajax/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:08:20 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=52</guid>
		<description><![CDATA[Hi, Thickbox is a very nice javascript library based on jQuery (which is also a very neat library). It is used to show images and documents in a sort of popup like Lightbox does. Let me sketch the problem: 1) I load my page (also loading thickbox.js) 2) I change my content in one dom-element, [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p><a href="http://jquery.com/demo/thickbox/">Thickbox</a> is a very nice javascript library based on <a href="http://jquery.com/">jQuery</a> (which is also a very neat library). It is used to show images and documents in a sort of popup like <a href="http://www.huddletogether.com/projects/lightbox/">Lightbox</a> does.</p>
<p>Let me sketch the problem:</p>
<p>1) I load my page (also loading thickbox.js)<br />
2) I change my content in one dom-element, for example a div element, through Ajax.<br />
3) Then I want to call thickbox on an element in the new div.</p>
<p>You will that see nothing happens, because Thickbox hasn&#8217;t been able to register this object.</p>
<p>So basically we need to reinitialize Thickbox. <br/><br />
<span id="more-52"></span><br />
Notice that you should download &#8220;thickbox.js&#8221; and not &#8220;thickbox-compressed.js&#8221; for this feature.</p>
<p>In thickbox.js there is a function tb_init(). This is called when the script is being loaded to add the click-events to the elements which have &#8220;thickbox&#8221; as class.</p>
<p>Recalling this function alone is not enough! Because in some cases elements will have two or more same click-events. It is better to remove the click-events first.</p>
<p>Add this to your thickbox.js:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> tb_reinit<span style="color: #009900;">&#40;</span>domChunk<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span>domChunk<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	tb_init<span style="color: #009900;">&#40;</span>domChunk<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And call this function whenever you load new content through Ajax which can possibly contain new Thickbox elements.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">tb_reinit<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.thickbox, area.thickbox, input.thickbox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Last but not least: Be careful when upgrading to a new version of thickbox, This was written for Thickbox version 3.1 .</p>
<p>And that&#8217;s it!</p>
<p>Hope this was useful.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/03/thickbox-reinitialize-thickbox-after-change-by-ajax/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Ubuntu: backup to USB drive on mount</title>
		<link>http://ninetynine.be/blog/2009/03/ubuntu-backup-to-usb-drive-on-mount/</link>
		<comments>http://ninetynine.be/blog/2009/03/ubuntu-backup-to-usb-drive-on-mount/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 16:37:14 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[usb drive]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=17</guid>
		<description><![CDATA[Hi everyone, I always was sloppy with my backups and I really needed to do something about it. I bought a new Freecom HDD 500GB and what I wanted to do is quickly backup my files every time I plug the device in, and it should give me a proper notice when the backup is [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>I always was sloppy with my backups and I really needed to do something about it. I bought a new Freecom HDD 500GB and what I wanted to do is quickly backup my files every time I plug the device in, and it should give me a proper notice when the backup is done.</p>
<p>Doesn&#8217;t sound that hard, or does it?</p>
<p>It became clear that I needed a little thingy called &#8220;udev&#8221;. And with big help from unutbu from <a href="http://ubuntuforums.org">ubuntuforums.org</a> I managed to get a very nice script up and running.</p>
<p>First thing you have to do is to know how your system recognizes your USB drive. </p>
<p>I followed <a href="http://ubuntuforums.org/showthread.php?t=168221">this great tutorial here</a>. (Don&#8217;t bother the fstab!)</p>
<p>My rules look like these.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #007800;">SUBSYSTEMS</span>==<span style="color: #ff0000;">&quot;usb&quot;</span>, <span style="color: #007800;">KERNEL</span>==<span style="color: #ff0000;">&quot;sd?1&quot;</span>, ATTRS<span style="color: #7a0874; font-weight: bold;">&#123;</span>product<span style="color: #7a0874; font-weight: bold;">&#125;</span>==<span style="color: #ff0000;">&quot;Freecom Network Drive&quot;</span>, <span style="color: #007800;">NAME</span>=<span style="color: #ff0000;">&quot;freecomHD&quot;</span>, RUN+=<span style="color: #ff0000;">&quot;/usr/bin/usb_backup.sh&quot;</span></pre></td></tr></table></div>

<p>Note that I have saved them under &#8220;/etc/udev/rules.d/81-local.rules&#8221;, because /etc/udev/rules.d/README says. It would also be safer I you select your device using UUID. </p>
<blockquote><p>
Files should be named xx-descriptive-name.rules, the xx should be<br />
chosen first according to the following sequence points:</p>
<p>80 rules that run programs (but do not load modules)</p></blockquote>
<p>After adding your rule, you need to restart udev.</p>

<div class="wp_syntax"><div class="code"><pre class="unix" style="font-family:monospace;">$ sudo /etc/init.d/udev restart</pre></div></div>

<p>Next install libnotify-bin through synaptic. This will make it possible for us to show notifies as if it were GNOME itself <img src='http://ninetynine.be/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Next we&#8217;ll need to hack the script a little bit:</p>
<p><span id="more-17"></span><br />
Place this in &#8220;/usr/local/bin/alt-notify-send&#8221;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">pids</span>=<span style="color: #000000; font-weight: bold;">`</span>pgrep <span style="color: #660033;">-u</span> <span style="color: #007800;">$user</span> gnome-panel<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">title</span>=$<span style="color: #000000;">1</span>
<span style="color: #007800;">text</span>=$<span style="color: #000000;">2</span>
<span style="color: #007800;">timeout</span>=$<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$title</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> You need to give me a title <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$text</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">text</span>=<span style="color: #007800;">$title</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$timeout</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">timeout</span>=<span style="color: #000000;">60000</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> pid <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$pids</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #666666; font-style: italic;"># find DBUS session bus for this session</span>
        <span style="color: #007800;">DBUS_SESSION_BUS_ADDRESS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-z</span> DBUS_SESSION_BUS_ADDRESS \
                <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$pid</span><span style="color: #000000; font-weight: bold;">/</span>environ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/DBUS_SESSION_BUS_ADDRESS=//'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #666666; font-style: italic;"># use it</span>
        <span style="color: #007800;">DBUS_SESSION_BUS_ADDRESS</span>=<span style="color: #007800;">$DBUS_SESSION_BUS_ADDRESS</span> \
        notify-send <span style="color: #660033;">-u</span> low <span style="color: #660033;">-t</span> <span style="color: #007800;">$timeout</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$title</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$text</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>This is because</p>
<blockquote><p>The reason why notify-send was not working was because notify-send uses the DBUS_SESSION_BUS_ADDRESS environment variable and that variable was not set in the shell that runs your script. This environment variable is set when you start a gnome session, but is not set when root runs a udev rule.</p>
<p>Moreover, one user can not send messages to another user using notify-send. So we use &#8220;su&#8221; to change root to your normal user, and we use the alt-notify-send script to find and set the DBUS_SESSION_BUS_ADDRESS before launching notify-send.</p></blockquote>
<p>(<a href="http://ubuntuforums.org/showthread.php?t=1094342&#038;page=2">unutbu</a>)</p>
<p>Then I created a file /usr/bin/usb_backup.sh.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">mount_point</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">grep</span> freecomHD <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mtab<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">attempts</span>=<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mount_point</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$attempts</span>&quot;</span> <span style="color: #660033;">-le</span> <span style="color: #000000;">50</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #666666; font-style: italic;"># $mount_point has not been found</span>
    <span style="color: #666666; font-style: italic;"># quit if this fails more than 50 times. </span>
    <span style="color: #666666; font-style: italic;"># This should not be necessary, but it better to be safe</span>
    <span style="color: #666666; font-style: italic;"># than have the script trapped in this loop forever for</span>
    <span style="color: #666666; font-style: italic;"># some unforeseen reason.</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
    <span style="color: #007800;">mount_point</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">grep</span> freecomHD <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mtab<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">attempts</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$attempts</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$mount_point</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #c20cb9; font-weight: bold;">su</span> ruben alt-notify-send <span style="color: #ff0000;">&quot;Backup Message&quot;</span> <span style="color: #ff0000;">&quot;USB Backup device detected&quot;</span> <span style="color: #000000;">0</span>
&nbsp;
    rsync <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>ruben<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>FREECOM\ HDD<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">su</span> ruben alt-notify-send <span style="color: #ff0000;">&quot;Backup Message&quot;</span> <span style="color: #ff0000;">&quot;Your USB Backup has completed&quot;</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">&amp;</span></pre></td></tr></table></div>

<p>Note that my user is named &#8220;ruben&#8221; and that you should replace it by your own. Also replace the the name in mount_point to the name you have given in your udev-rules. </p>
<p>Also note that the whole process is run in a new process (due to the &#8220;&#038;&#8221; character). Otherwise ubuntu will try to do the backup before the mount. But it needs to be mounted before backup. This requires the little hack on top of the script <img src='http://ninetynine.be/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Don&#8217;t forget to make the scripts executable!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="unix" style="font-family:monospace;">$ sudo chmod 755 /usr/bin/usb_backup.sh
$ sudo chmod 755 /usr/local/bin/alt-notify-send</pre></td></tr></table></div>

<p>It may be a good thing to tweak your rsync a little bit, so you don&#8217;t lose too much time every time you plug in.</p>
<p>And that&#8217;s it! This was a little harder than I thought. But then again, it shows that you&#8217;re absolutely free to do whatever you want on ubuntu. This is why we all love our tux.</p>
<p>Hope this helped somebody. And stick around to read more about all sorts of stuff!</p>
<p>Happy coding!</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/03/ubuntu-backup-to-usb-drive-on-mount/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

