<?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>Lennart&#039;s weblog</title>
	<atom:link href="http://blog.karssen.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.karssen.org</link>
	<description>Open source, computers, Africa and other more (or less) interesting stuff.</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:15:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Paper on using org-mode for reproducible research</title>
		<link>http://blog.karssen.org/2012/02/02/paper-on-using-org-mode-for-reproducible-research/</link>
		<comments>http://blog.karssen.org/2012/02/02/paper-on-using-org-mode-for-reproducible-research/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 19:15:46 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[Emacs]]></category>
		<category><![CDATA[org-mode]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=233</guid>
		<description><![CDATA[I&#8217;m an avid user of Emacs and have been using org-mode for a couple of years now to write notes, keep a ToDo list and a few other things. A couple of days ago I came across an article in the Journal of Statistical Software that describes how to use org-mode for reproducible research. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m an avid user of <a href="http://www.gnu.org/software/emacs/">Emacs</a> and have been using <a href="http://orgmode.org">org-mode</a> for a couple of years now to write notes, keep a ToDo list and a few other things.</p>
<p>A couple of days ago I came across <a href="http://www.jstatsoft.org/v46/i03">an article in the Journal of Statistical Software</a> that describes how to use org-mode for reproducible research. It&#8217;s a great read and the source code of the complete article can be downloaded as well!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2012/02/02/paper-on-using-org-mode-for-reproducible-research/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Plugwise adapters with Linux</title>
		<link>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/</link>
		<comments>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 20:53:08 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=214</guid>
		<description><![CDATA[Yesterday I received a small package I had ordered: the Plugwise Home Start kit. According to the box it is an energy management and control system. The idea is that you insert a sort of adaptor between a power socket and a device and using the Plugwise Source software you can monitor the power usage [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I received a small package I had ordered: the <a href="http://www.plugwise.com">Plugwise</a> <a href="http://www.plugwise.com/idplugtype-f/home-start">Home Start</a> kit. According to the box it is an energy management and control system. The idea is that you insert a sort of adaptor between a power socket and a device and using the Plugwise Source software you can monitor the power usage of the device. Furthermore, you can use the software to create schedule to turn the device on and off at a specific time.</p>
<p>The package contains the following:</p>
<ul>
<li>a USB adapter (called the Stick)</li>
<li>a Circle+, the master adaptor that keeps track of the other devices in the network
<li>a Circle, the regular members of the Plugwise network
</ul>
<p>The Circles communicate to each other using the ZigBee protocol in the 2.4GHz range. According to the documentation, the range of each Circle is about 5m.</p>
<p>Unfortunately the Source software only runs on windows. Luckily some people have already analysed the protocol and written some software to control the Plugwise devices (see links below).</p>
<h2>First steps</h2>
<p>  Plugging the USB dongle in gives the following output in <code>/var/log/syslog</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">Nov 19 12:20:37 barabas kernel: [  182.855742] usb 1-1.6.1.1.3: new full speed USB device number 14 using ehci_hcd
Nov 19 12:20:37 barabas mtp-probe: checking bus 1, device 14: &quot;/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6/1-1.6.1/1-1.6.1.1/1-1.6.1.1.3&quot;
Nov 19 12:20:37 barabas mtp-probe: bus: 1, device: 14 was not an MTP device
Nov 19 12:20:37 barabas kernel: [  183.169370] usbcore: registered new interface driver usbserial
Nov 19 12:20:37 barabas kernel: [  183.169389] USB Serial support registered for generic
Nov 19 12:20:37 barabas kernel: [  183.169431] usbcore: registered new interface driver usbserial_generic
Nov 19 12:20:37 barabas kernel: [  183.169434] usbserial: USB Serial Driver core
Nov 19 12:20:37 barabas kernel: [  183.171310] USB Serial support registered for FTDI USB Serial Device
Nov 19 12:20:37 barabas kernel: [  183.171552] ftdi_sio 1-1.6.1.1.3:1.0: FTDI USB Serial Device converter detected
Nov 19 12:20:37 barabas kernel: [  183.171588] usb 1-1.6.1.1.3: Detected FT232RL
Nov 19 12:20:37 barabas kernel: [  183.171591] usb 1-1.6.1.1.3: Number of endpoints 2
Nov 19 12:20:37 barabas kernel: [  183.171595] usb 1-1.6.1.1.3: Endpoint 1 MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171598] usb 1-1.6.1.1.3: Endpoint 2 MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171602] usb 1-1.6.1.1.3: Setting MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171975] usb 1-1.6.1.1.3: FTDI USB Serial Device converter now attached to ttyUSB0
Nov 19 12:20:37 barabas kernel: [  183.171998] usbcore: registered new interface driver ftdi_sio
Nov 19 12:20:37 barabas kernel: [  183.172002] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
Nov 19 12:20:37 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) opening serial port...
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) closing serial port...
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) serial port closed
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) opening serial port...
Nov 19 12:20:55 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) closing serial port...
Nov 19 12:20:55 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) serial port closed</pre></div></div>

<p><code>lsusb</code> gives:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">Bus 001 Device 014: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC</pre></div></div>

<p>I couldn&#8217;t get the pairing to work under Linux (with the PlugwiseOnLinux scripts), Even though I corrected the MAC address in the python code. I then tried it in Windows where I failed at first also. After resetting the Circle+ and the Circle (removing/inserting them into the power outlet with 3 second intervals, as mentioned in the FAW on the plugwise website) I managed to pair the Circles. Looking back, I think I didn&#8217;t wait long enough for the pairing to work under Linux. During the trials in Windows I noticed that the pairing can take up to about 5 minutes&#8230;</p>
<p>Back in Linux I used python-plugwise (see links below) to turn the Circles on and off, e.g. this is how I turn my Circle+ off (note that I am a member of the dialout group, which is needed to communicate with <code>/dev/ttyUSB0</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ plugwise_util <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 <span style="color: #660033;">-m</span> 000D6F0000B1C117 <span style="color: #660033;">-s</span> off</pre></div></div>

<p>This is what I want! The only minor downside of python-plugwise is that it depends on the crcmod python library, which apparently is not package for Debian/Ubuntu. So installing using the python-setup framework as mentioned in the README is necessary.</p>
<p>Reading out the current power usage of my Circle works also:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ plugwise_util <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 <span style="color: #660033;">-m</span> 000D6F0000B85134 <span style="color: #660033;">-p</span>
power usage: 2.27W</pre></div></div>

<p>So, no that it works, what am I going to do with the Plugwise modules? I&#8217;m going to use them in my backup scripts to switch the power to my external hard drives.</p>
<h2> Making a .deb</h2>
<p>I used <code>checkinstall</code> to make a package of python-plugwise. In a working directory, first check out the source code of python-plugwise using mercurial, as mentioned on the web site:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ hg clone https:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>hadara<span style="color: #000000; font-weight: bold;">/</span>python-plugwise</pre></div></div>

<p>Then run <code>checkinstall</code> and don&#8217;t forget to fill in the details correctly. For example, the package name is &#8216;python&#8217; by default, which you definitely don&#8217;t want, since that would overwrite Ubuntu&#8217;s default &#8216;python&#8217; package. Also make sure that you remove the crcmod python library if you installed python-plugwise before, otherwise it won&#8217;t get packaged. The output below shows the final values, after I changed them.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> checkinstall <span style="color: #660033;">-D</span> python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
&nbsp;
checkinstall 1.6.2, Copyright <span style="color: #000000;">2009</span> Felipe Eduardo Sanchez Diaz Duran
	      This software is released under the GNU GPL.
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">*****************************************</span>
<span style="color: #000000; font-weight: bold;">****</span> Debian package creation selected <span style="color: #000000; font-weight: bold;">***</span>
<span style="color: #000000; font-weight: bold;">*****************************************</span>
&nbsp;
This package will be built according to these values:
&nbsp;
<span style="color: #000000;">0</span> -  Maintainer: <span style="color: #7a0874; font-weight: bold;">&#91;</span> lennart<span style="color: #000000; font-weight: bold;">@</span>karssen.org <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">1</span> -  Summary: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise is used to control the Plugwise power switches <span style="color: #c20cb9; font-weight: bold;">as</span> well <span style="color: #c20cb9; font-weight: bold;">as</span> <span style="color: #c20cb9; font-weight: bold;">read</span> out information on power usage. <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">2</span> -  Name:    <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">3</span> -  Version: <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">0.2</span>-hg-<span style="color: #000000;">20111120</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">4</span> -  Release: <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">5</span> -  License: <span style="color: #7a0874; font-weight: bold;">&#91;</span> GPL <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">6</span> -  Group:   <span style="color: #7a0874; font-weight: bold;">&#91;</span> checkinstall <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">7</span> -  Architecture: <span style="color: #7a0874; font-weight: bold;">&#91;</span> amd64 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">8</span> -  Source location: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">9</span> -  Alternate <span style="color: #7a0874; font-weight: bold;">source</span> location: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">10</span> - Requires: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">11</span> - Provides: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">12</span> - Conflicts: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">13</span> - Replaces: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Enter a number to change any of them or press ENTER to <span style="color: #7a0874; font-weight: bold;">continue</span>:</pre></div></div>

<p>You can check the contents of the package to make sure the crcmod<br />
files are included using <code>dpkg</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">--contents</span> python-plugwise_0.2-hg-<span style="color: #000000;">20111120</span>-<span style="color: #000000;">1</span>_amd64.deb</pre></div></div>

<p>An idea for later: make an SNMP module that calls <i>plugwise_util</i> to get the power usage so that I can monitor the power usage of a device using Cacti.</p>
<h2>Links</h2>
<ul>
<li>The software I use: <a href="https://bitbucket.org/hadara/python-plugwise/overview">python-plugwise</a></li>
<li><a href="http://www.maartendamen.com/tag/plugwise/">The blog of Maarten Damen</a>, the guy that seems to have been the first one to analyse the plugwise protocol</li>
<li><a href="http://roheve.wordpress.com/tag/plugwise/">Another blog, also with info on the protocol</a></li>
<li><a href="https://github.com/hackstuces/PlugwiseOnLinux.git">PlugwiseOnLinux</a>, a set of python scripts for pairing Plugwise and the Circles. Did not work with me at first, didn&#8217;t retry later</li>
<li><a href="http://wordpress.dirkengels.com/tag/plugweb-2/">PlugWeb</a>, a PHP interface, for those wanting to control their Plugwise network via a web interface</li>
<li>According to its website <a href="http://www.domotiga.nl/">DomotiGa</a> can also control Plugwise devices, but I haven&#8217;t tried it (yet)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BluePad and Ubuntu 10.11</title>
		<link>http://blog.karssen.org/2011/10/30/bluepad-and-ubuntu-10-11/</link>
		<comments>http://blog.karssen.org/2011/10/30/bluepad-and-ubuntu-10-11/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 13:53:48 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=208</guid>
		<description><![CDATA[Over the last few years I&#8217;ve always used BluePad (the author&#8217;s blog, source and packages available at sf.net) when I had to do a presentation. BluePad allows me to use my Nokia 6230i to send PgUp and PgDn signals to my laptop via bluetooth and thus control my presentation without standing next to laptop all [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few years I&#8217;ve always used BluePad (<a href="http://www.valeriovalerio.org/?category_name=bluepad">the author&#8217;s blog</a>, <a href="http://sourceforge.net/projects/bluepad/">source and packages available at sf.net</a>) when I had to do a presentation. BluePad allows me to use my Nokia 6230i to send PgUp and PgDn signals to my laptop via bluetooth and thus control my presentation without standing next to laptop all the time.</p>
<p>Unfortunately the author hasn&#8217;t updates his <code>.deb</code> packages in a long time, so trying to install the BluePad <code>.deb</code> on a recent Debian or Ubuntu machine will fail due to missing dependencies. I work around this issue by installing BluePad only when I need it and removing it afterwards. Here is how to install it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">--force-depends</span> bluepad_0.4_all.deb</pre></div></div>

<p>In older Ubuntu installations this was enough, but with Ubuntu&#8217;s Unity interface replacing Gnome the BluePad icon doesn&#8217;t appear in the top menu bar anymore and as a result it isn&#8217;t possible anymore to interact with it. So you&#8217;ll have no way of connecting the laptop to the phone.</p>
<p>To remedy this use the following command to allow all applications to show up in the system tray:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gsettings <span style="color: #000000; font-weight: bold;">set</span> com.canonical.Unity.Panel systray-whitelist <span style="color: #ff0000;">&quot;['all']&quot;</span></pre></div></div>

<p>Restart Unity or log out and back in to get the changes accepted.</p>
<p>After the presentation is over and the BluePad removed, use this line to reset the system tray settings:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gsettings <span style="color: #000000; font-weight: bold;">set</span> com.canonical.Unity.Panel systray-whitelist <span style="color: #ff0000;">&quot;['']&quot;</span></pre></div></div>

<p>(That&#8217;s two single quotes within the brackets).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/10/30/bluepad-and-ubuntu-10-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It happened today&#8230;</title>
		<link>http://blog.karssen.org/2011/09/22/it-happened-today/</link>
		<comments>http://blog.karssen.org/2011/09/22/it-happened-today/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 23:13:18 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=201</guid>
		<description><![CDATA[It happened today&#8230; It&#8217;s the end of the world as we know it&#8230; I don&#8217;t sleep, I dream&#8230; Shiny happy people?]]></description>
			<content:encoded><![CDATA[<p><a href="http://remhq.com/news_story.php?id=1446">It happened today</a>&#8230;<br />
It&#8217;s the end of the world as we know it&#8230;<br />
I don&#8217;t sleep, I dream&#8230;<br />
Shiny happy people?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/09/22/it-happened-today/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Loggerhead behind Apache on Ubuntu 11.04</title>
		<link>http://blog.karssen.org/2011/08/22/installing-loggerhead-behind-apache-on-ubuntu-11-04/</link>
		<comments>http://blog.karssen.org/2011/08/22/installing-loggerhead-behind-apache-on-ubuntu-11-04/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 22:29:52 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=163</guid>
		<description><![CDATA[Introduction Loggerhead is a webfrontend for Bazaar (usually abbreviated as bzr) repositories. Bazaar is a so-called distributed version control system. So, if you have one or more bzr repositories you can use Loggerhead to look at the files, read the change logs and see the differences between revisions from within your web browser. The main [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://launchpad.net/loggerhead">Loggerhead</a> is a webfrontend for <a href="http://bazaar.canonical.com/">Bazaar</a> (usually abbreviated as bzr) repositories. Bazaar is a so-called distributed version control system. So, if you have one or more bzr repositories you can use Loggerhead to look at the files, read the change logs and see the differences between revisions from within your web browser.</p>
<p>The main purpose of this post is to document the steps needed to configure Loggerhead and Apache to work together to publish your bzr repos on the web. The need for this post arose when I tried to get this setup to work and found that there isn&#8217;t a lot of documentation on how to get this done and most of it is out of date. The folowing steps were performed on a Linux server with Ubuntu 11.04 installed.</p>
<h2>Basic Loggerhead configuration</h2>
<p>First, let&#8217;s install Loggerhead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> loggerhead</pre></div></div>

<p>Although the package is called loggerhead, the actual binary that is run is called serve-branches. The package provides start and stop scripts for the service (<code>/etc/init.d/loggerhead</code>), but to start successfully the file <code>/etc/serve-branches.conf</code> needs to exist. Older documentation I found on the web refers to the file <code>/etc/loggerhead.conf</code>, but that file has become obsolete.</p>
<p>The <code>serve-branches.conf</code> file contains three lines:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">served_branches</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/bzr</span>
<span style="color: #000099;">prefix</span><span style="color: #000066; font-weight:bold;">=</span>
<span style="color: #000099;">port</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">8080</span></pre></div></div>

<p>Here, the line <code>served_branches</code> points to the directory under which you store your bzr repositories. Each repo needs to be stored in its own directory. So in this example all the repos are in subdirectories of <code>/home/bzr/</code>.</p>
<p>You have to make sure that loggerhead can read the files in that directory. Loggerhead runs as the <code>loggerhead</code> user but I made the directories readable and accessible by all users:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> a+rx <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>If you now start Loggerhead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ service start loggerhead</pre></div></div>

<p>you should be able to visit http://localhost:8080 in your browser and see your repositories.</p>
<h2>How to publish your branch to this shared repository?</h2>
<p>Now that our repository browser is set up, how do we publish our branches to it so that there actually is something to browse through? Here is how you publish your branch to the server, assuming that you are in a directory that contains a branch and want to publish it as <code>myTests</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ bzr push <span style="color: #660033;">--create-prefix</span> sftp:<span style="color: #000000; font-weight: bold;">//</span>username<span style="color: #000000; font-weight: bold;">@</span>server.yourdomain.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span>myTests</pre></div></div>

<p>As you probably suspected, the <code>--create-prefix</code> option is only necessary the first time you push your branch. Note that we are using sftp here. Loggerhead itself doesn&#8217;t allow writes to the published repos. So, every user that want to push his/her changes to this repository needs to have sftp access to the <code>/home/bzr</code> directory. I solved that problem by adding all people that need to be able to push changes to a Linux group called <i>vcs</i> (for Version Control Systems) and then set the primary group of <code>/home/bzr/</code> to <i>vcs</i> as well as giving group write permissions to this directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-ld</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span>
drwxrwxr-x <span style="color: #000000;">4</span> root vcs <span style="color: #000000;">4096</span> <span style="color: #000000;">2011</span>-08-<span style="color: #000000;">16</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<h2>Adding Apache to the mix</h2>
<p>In my case I already have a web server (Apache) running on port 80. Since I&#8217;d rather not open yet another port (8080 in this case) on my router, I wanted to use Apache to hand over the requests for bzr page to Loggerhead. For that I needed to install the following packages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-pastedeploy</pre></div></div>

<p>Next, I needed to change the contents of the <code>/etc/serve-branches.conf</code> file to this:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">served_branches</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/bzr</span>
<span style="color: #000099;">prefix</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/bzr</span>
<span style="color: #000099;">port</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">8080</span></pre></div></div>

<p>The prefix indicates the location in the URL where Apache will serve the repos. In this case that will be http://server.yourdomain.com/bzr/.</p>
<p>And finally I needed to configure Apache. First, make sure that the <code>proxy</code> and <code>proxy-http</code> modules are loaded:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ a2enmod proxy proxy_http</pre></div></div>

<p>Next, create a file <code>/etc/apache/conf.d/sites-available/loggerhead</code> with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># Configuration for browsing of Bazaar repos. Make sure loggerhead is running.</span>
&lt;<span style="color: #000000; font-weight:bold;">Location</span> <span style="color: #7f007f;">&quot;/bzr/&quot;</span>&gt;
    <span style="color: #00007f;">ProxyPass</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
    <span style="color: #00007f;">ProxyPassReverse</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
&lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;</pre></div></div>

<p>Note that Loggerhead and Apache run on the same host, that&#8217;s why I set the IP to 127.0.0.1.</p>
<p>Finally it&#8217;s time to enable the site and restart Apache:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ a2ensite loggerhead
$ service apache2 restart</pre></div></div>

<p>Now it should be possible to browse your repos at http://server.yourdomain.com/bzr/. Note the final <code>/</code>, it&#8217;s important.</p>
<h2>Securing access with an LDAP connection</h2>
<p>I have stored all my Unix user and group information in an LDAP server. To make sure that only people in the Unix group <code>vcs</code> are allowed access to the loggerhead pages, change the Apache configuration file <code>loggerhead</code> to the following:</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
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># Configuration for browsing of Bazaar repos. Make sure loggerhead is running.</span>
&lt;<span style="color: #000000; font-weight:bold;">Location</span> <span style="color: #7f007f;">&quot;/bzr/&quot;</span>&gt;
    <span style="color: #00007f;">ProxyPass</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
    <span style="color: #00007f;">ProxyPassReverse</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
&nbsp;
    <span style="color: #adadad; font-style: italic;"># LDAP authentication</span>
    <span style="color: #00007f;">AuthType</span> Basic
    <span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Karssen.org VCS users&quot;</span>
    <span style="color: #00007f;">AuthBasicProvider</span> ldap
    <span style="color: #00007f;">AuthLDAPURL</span> <span style="color: #7f007f;">&quot;ldap://ldap.yourdomain.com/ou=Users,dc=yourdomain,dc=com?uid&quot;</span>
    <span style="color: #00007f;">AuthLDAPGroupAttribute</span> memberUid
    <span style="color: #00007f;">AuthLDAPGroupAttributeIsDN</span> <span style="color: #0000ff;">off</span>
    <span style="color: #00007f;">Order</span> <span style="color: #00007f;">Allow</span>,<span style="color: #00007f;">Deny</span>
    <span style="color: #00007f;">Allow</span> From <span style="color: #0000ff;">All</span>
    <span style="color: #00007f;">Require</span> ldap-<span style="color: #00007f;">group</span> cn=vcs,ou=Groups,dc=yourdomain,dc=com
&lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;</pre></td></tr></table></div>

<p>Lines 11 and 12 are needed because the <code>vcs</code> group is not an LDAP group. I store my Unix (POSIX) groups in a separate OU in the LDAP tree (see line 15).<br />
Don&#8217;t forget to restart Apache after making these changes.</p>
<h2>References</h2>
<ul>
<li><a href="http://doc.bazaar.canonical.com/latest/en/admin-guide/code-browsing.html">Bazaar documentation on Apache integration</a></li>
<li><a href="https://bugs.launchpad.net/ubuntu/+source/loggerhead/+bug/563118">Launchpad bug 563118 describing the unexpected change from <code>loggerhead.conf</code> to <code>serve-branches.conf</code></a></li>
<li><a href="http://blather.michaelwlucas.com/archives/99">Apache, LDAP and groups</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/08/22/installing-loggerhead-behind-apache-on-ubuntu-11-04/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>RefTeX, how could I have missed this?</title>
		<link>http://blog.karssen.org/2011/08/21/reftex-how-could-i-have-missed-this/</link>
		<comments>http://blog.karssen.org/2011/08/21/reftex-how-could-i-have-missed-this/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 20:34:49 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[Emacs]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=176</guid>
		<description><![CDATA[I&#8217;ve been using Emacs and LaTeX for more than ten years now and still I keep learning. For example, last Friday I came across Stephen Eglen&#8217;s ESS (Emacs Speaks Statistics) tutorial. In his slides he mentioned RefTeX. I had heard of it before, but for some reason I thought it was either a set of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://www.gnu.org/software/emacs/">Emacs</a> and <a href="http://www.latex-project.org/">LaTeX</a> for more than ten years now and still I keep learning. For example, last Friday I came across <a href="http://www.damtp.cam.ac.uk/user/sje30/ess11/">Stephen Eglen&#8217;s ESS (Emacs Speaks Statistics) tutorial</a>. In his slides he mentioned <a href="http://www.gnu.org/software/auctex/reftex.html">RefTeX</a>. I had heard of it before, but for some reason I thought it was either a set of LaTeX styles or an <a href="http://www.gnu.org/software/auctex/index.html">AUCTeX</a> replacement and consequently, I never looked into it.</p>
<p>This time, however, I made the small effort of looking up RefTeX&#8217;s website and lo and behold, it&#8217;s neither of the two things I thought it was. Instead, it is an extension to LaTeX that makes inserting citation, references, index entries and labels a breeze. Even if you don&#8217;t (want to) use all its capabilities, <a href="http://www.gnu.org/software/auctex/manual/reftex.html#SEC9">the following keystrokes</a> are worth the effort:</p>
<table width="100%">
<col width="50" valign="top" />
<col valign="top" />
<tr>
<td><code>C-c =</code></td>
<td>Show table of contents of the document (also a great way to walk through your document)
<td></tr>
<tr>
<td><code>C-c (</code></td>
<td>Insert a label at point</td>
</tr>
<tr>
<td><code>C-c )</code></td>
<td>Insert a reference to some label</td>
</tr>
<tr>
<td><code>C-c [</code></td>
<td>Search in your bibliography (either BibTeX or <code>thebibliography</code> environment) to insert citations</td>
</tr>
</table>
<p>To start using RefTeX in a document you are already editing simple run</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">M-x reftex-mode</pre></div></div>

<p>Insert the following in <code>.emacs</code> file if you want to load RefTeX on startup</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; Enable RefTeX</span>
<span style="color: #66cc66;">&#40;</span>add-hook 'LaTeX-mode-hook 'turn-on-reftex<span style="color: #66cc66;">&#41;</span>   <span style="color: #808080; font-style: italic;">; with AUCTeX LaTeX mode</span>
<span style="color: #66cc66;">&#40;</span>add-hook 'latex-mode-hook 'turn-on-reftex<span style="color: #66cc66;">&#41;</span>   <span style="color: #808080; font-style: italic;">; with Emacs latex mode</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/08/21/reftex-how-could-i-have-missed-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overwriting selected text in Emacs</title>
		<link>http://blog.karssen.org/2011/08/04/159/</link>
		<comments>http://blog.karssen.org/2011/08/04/159/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 07:29:09 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Emacs]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=159</guid>
		<description><![CDATA[I learned something new in Emacs (my favourite text editor) today. Normally in Emacs, if you start typing while having some text selected will not overwrite this text. This is contrary to what most people are used to in other editors. It turns out that Emacs has a minor mode that fixes this: delete-selection-mode. Add [...]]]></description>
			<content:encoded><![CDATA[<p>I learned something new in Emacs (my favourite text editor) today. Normally in Emacs, if you start typing while having some text selected will not overwrite this text. This is contrary to what most people are used to in other editors. It turns out that Emacs has a minor mode that fixes this: <code>delete-selection-mode</code>. Add the following to your <code>.emacs</code> file to have it loaded by default:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>delete-selection-mode t<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Since <code>delete-selection-mode</code> enables <code>transient-mark-mode</code> I commented the line</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> transient-mark-mode t<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>in my <code>.emacs</code></p>
<p>References:</p>
<ul>
<li><a href="http://emacs-fan.blogspot.com/2011/08/delete-selection-mode-for-when-you-just.html">The blog of an Emacs fan</a></li>
<li><a href="http://www.emacswiki.org/emacs/DeleteSelectionMode">The Emacs Wiki</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/08/04/159/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Embedding album art in FLAC files</title>
		<link>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/</link>
		<comments>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 18:44:53 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=149</guid>
		<description><![CDATA[I recently wanted to add cover art to my collection of FLAC-encoded audio files. I wrote the following simple script to help me automate the process. Running this script in a given directory (I group my music in directories per artist, followed by a subdirectory for each album) with the name of the album art [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to add cover art to my collection of FLAC-encoded audio files. I wrote the following simple script to help me automate the process. Running this script in a given directory (I group my music in directories per artist, followed by a subdirectory for each album) with the name of the album art image file name as argument then automatically embeds the image in the FLAC/Vorbis tag.</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;">#</span>
<span style="color: #666666; font-style: italic;"># This script embeds a given image (usually .jpg) as album art in the</span>
<span style="color: #666666; font-style: italic;"># FLAC files in the present directory (and its subdirectories).</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Time-stamp: &lt;2011-07-31 20:43:23 (lennart)&gt;</span>
&nbsp;
<span style="color: #007800;">coverart</span>=<span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.flac&quot;</span> <span style="color: #660033;">-print0</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> metaflac <span style="color: #660033;">--import-picture-from</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$coverart</span>&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing and configuring Puppet</title>
		<link>http://blog.karssen.org/2011/07/29/installing-and-configuring-puppet/</link>
		<comments>http://blog.karssen.org/2011/07/29/installing-and-configuring-puppet/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 16:26:08 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[Puppet]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=135</guid>
		<description><![CDATA[Puppet is a configuration management system. In short this means that by setting up a server (the Puppet master) you can manage many other machines (nodes) with this server by specifying which packages should be installed, files that need to be present, their permissions, etc. The nodes poll the server every 30 minutes (by default) [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.puppetlabs.com/puppet/introduction/">Puppet</a> is a configuration management system. In short this means that by setting up a server (the Puppet master) you can manage many other machines (nodes) with this server by specifying which packages should be installed, files that need to be present, their permissions, etc. The nodes poll the server every 30 minutes (by default) to see if they should apply any changes to their configuration. Other packages that implement a similar idea are CfEnfine and Chef.</p>
<p>Note that all these instructions were performed as root.</p>
<h2>The puppet master</h2>
<p>Gaffel will be puppet master. I&#8217;ve added a DNS entry for <i>puppet.karssen.org</i> that points to <i>gaffel</i>. This installs the client and the Puppet master:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> puppet puppetmaster</pre></div></div>

<p>The main configuration of server and client can be found in <i>/etc/puppet/puppet.conf</i>. We&#8217;ll leave it at the default for now. The file <i>/etc/puppet/manifests/sites.pp</i> contains options that apply to the whole site. Let&#8217;s make it and add the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">import <span style="color: #933;">&quot;nodes&quot;</span>
&nbsp;
# The filebucket is for backups. Originals of files that Puppet modifies
# get stored here.
filebucket <span style="">&#123;</span> main: server <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; 'puppet.karssen.org' <span style="">&#125;</span></span>
File  <span style="">&#123;</span> backup <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; main<span style="">&#125;</span></span>
&nbsp;
# Set the default $PATH$ for executing commands on node systems.
Exec <span style="">&#123;</span> path <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/usr/bin:/usr/sbin:/bin:/sbin:&quot;</span> <span style="">&#125;</span></pre></div></div>

<p>The file <i>/etc/puppet/manifests/nodes.pp</i> defines the nodes/clients that will be managed by puppet as well as what configuration will be applied to them, so-called roles. For now, let&#8217;s make a quick example:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">node common <span style="">&#123;</span>
	include packages
<span style="">&#125;</span>
&nbsp;
node lambik inherits common <span style="">&#123;</span>
	include ntp::client
<span style="">&#125;</span></pre></div></div>

<p>Both the &#8216;packages&#8217; and the &#8216;ntp&#8217; modules still need to be defined. Let&#8217;s do that now.</p>
<p>Modules are collections of puppet code (known as manifests) and related files that are used for client configuration. Modules are stored in <i>/etc/puppet/modules/</i>.<br />
Let&#8217;s start with the ntp example. First make the necessary directory structure:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>ntp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>manifests,files,templates<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Every modules needs a file <i>init.pp</i> that declares the class. It can also include other files. The <i>files</i> and <i>templates</i> directories are used to store files that need to be copied to the node or templates to make such files, respectively. We&#8217;ll come across some examples of both. This is the <i>init.pp</i> file for the ntp role (<i>/etc/puppet/modules/ntp/manifests/init.pp</i>):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class ntp::client <span style="">&#123;</span>
	 package <span style="">&#123;</span> <span style="color: #933;">&quot;ntp&quot;</span>:
    		 <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; installed,</span>
	 <span style="">&#125;</span>
&nbsp;
	 service <span style="">&#123;</span> <span style="color: #933;">&quot;ntp_client&quot;</span>:
		 <span style="color: #000099;">name</span>       <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;ntp&quot;</span>
    		 <span style="color: #000099;">ensure</span>     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; running,</span>
#		 hasstatus  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
		 <span style="color: #000099;">hasrestart</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
		 <span style="color: #000099;">require</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>Here we indicate that the NTP service must be running and that it&#8217;s init script (in <i>/etc/init.d</i>) accepts the <i>status</i> and <i>restart</i> options. Lastly in the <i>require</i> line we note that before this manifest can be applied we must make sure that the package <i>ntp</i> has been installed. This is necessary, because the order in which the two directives are executed is not necessarily the order in<br />
which they appear in the manifest.</p>
<p>The <i>#</i> in from of the <i>hasstatus</i> attribute is because of a bug inthe puppet version (2.6.4) shipped with Ubuntu 11.04. See http://projects.puppetlabs.com/issues/5610 for the bug report. In version 2.6.7 it is supposedly fixed.</p>
<p>In our <i>nodes.pp</i> file we also mentioned a <i>packages</i> class. In this class we list all the packages that we want to have installed on the node. Let&#8217;s make the <i>packages</i> module. First create the necessary directories:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>packages<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>manifests,files,templates<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Add the file <i>/etc/puppet/modules/packages/manifests/init.pp</i>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class packages <span style="">&#123;</span>
	 $base_packages <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#91;</span></span>
	 <span style="color: #933;">&quot;openssh-server&quot;</span>,
	 <span style="color: #933;">&quot;nfs-common&quot;</span>,
	 <span style="color: #933;">&quot;etckeeper&quot;</span>,
	 <span style="color: #933;">&quot;htop&quot;</span>,
	 <span style="color: #933;">&quot;iotop&quot;</span>,
	 <span style="color: #933;">&quot;iftop&quot;</span>,
	 <span style="">&#93;</span>
&nbsp;
	 $editor_packages <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#91;</span></span>
	 <span style="color: #933;">&quot;emacs&quot;</span>,
	 <span style="color: #933;">&quot;emacs-goodies-el&quot;</span>,
	 <span style="color: #933;">&quot;elscreen&quot;</span>,
	 <span style="">&#93;</span>
&nbsp;
	 $all_packages <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#91;</span></span>
	 $base_packages,
	 $editor_packages,
	 <span style="">&#93;</span>
&nbsp;
	 package <span style="">&#123;</span> $all_packages:
	      <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; installed,</span>
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>Here I&#8217;ve defined three variables (beginning with a <i>$</i> sign), one for base packages, one for editor-related packages and one called <i>$all_packages</i> that incorporates them both. Finally, I tell puppet to ensure they are all installed.</p>
<h2>Setting up a client</h2>
<p>As a test client I&#8217;m using <i>lambik</i>, one of my MythTV frontends.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> puppet</pre></div></div>

<p>To make sure that puppet starts by default on system startup edit the file <i>/etc/default/puppet</i> and set <i>START</i> to <i>yes</i>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Defaults for puppet - sourced by /etc/init.d/puppet
&nbsp;
# Start puppet on boot?
<span style="color: #000099;">START</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
&nbsp;
# Startup options
<span style="color: #000099;">DAEMON_OPTS</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;&quot;</span></pre></div></div>

<p>Now edit <i>/etc/puppet/puppet.conf</i> (on the client) and add the FQDN of the puppet master server to the <i>[main]</i> section:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>main<span style="">&#93;</span></span>
<span style="color: #000099;">logdir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/log/puppet</span>
<span style="color: #000099;">vardir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/lib/puppet</span>
<span style="color: #000099;">ssldir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/lib/puppet/ssl</span>
<span style="color: #000099;">rundir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/run/puppet</span>
<span style="color: #000099;">factpath</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">$vardir/lib/facter</span>
<span style="color: #000099;">templatedir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">$confdir/templates</span>
<span style="color: #000099;">prerun_command</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/etc/puppet/etckeeper-commit-pre</span>
<span style="color: #000099;">postrun_command</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/etc/puppet/etckeeper-commit-post</span>
<span style="color: #000099;">server</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> puppet.karssen.org</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>master<span style="">&#93;</span></span>
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
<span style="color: #000099;">ssl_client_header</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> SSL_CLIENT_S_DN</span>
<span style="color: #000099;">ssl_client_verify_header</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> SSL_CLIENT_VERIFY</span></pre></div></div>

<h2>Setting up secure communication between master and nodes and first test run</h2>
<p>Puppet uses SSL certificates to set up a secure connection between master and nodes. Before you can apply any changes to the client, certificates need to be exchanged and signed. First, tell the client to connect to the puppet master:</p>
<pre lang="">
$ puppetd --test
info: Creating a new SSL key for lambik.karssen.org
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for ca
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
info: Creating a new SSL certificate request for lambik.karssen.org
info: Certificate Request fingerprint (md5): 1D:A3:3A:4A:A6:DA:D6:C8:96:F4:D4:7E:52:F4:12:1D
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
Exiting; no certificate found and waitforcert is disabled
</pre>
<p>On the puppet master we can now sign the certificate:</p>
<pre lang="">
$ puppetca -l
lambik.karssen.org
$ puppetca -s lambik.karssen.org
notice: Signed certificate request for lambik.karssen.org
notice: Removing file Puppet::SSL::CertificateRequest lambik.karssen.org at '/var/lib/puppet/ssl/ca/requests/lambik.karssen.org.pem'
</pre>
<p>On the client we can now rerun <i>puppetd</i>:</p>
<pre lang="">
root@lambik:~# puppetd --test
info: Caching catalog for lambik.karssen.org
info: Applying configuration version '1311930908'
notice: /Stage[main]/Packages/Package[iotop]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Packages/Package[iftop]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Ntp/Package[ntp]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Packages/Package[emacs-goodies-el]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Packages/Package[htop]/ensure: ensure changed 'purged' to 'present'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 78.43 seconds
</pre>
<p>If all went well, we can now start the puppet client daemon to keep our system under puppet control:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ service puppet start</pre></div></div>

<h2>Adding (configuration) files to the roles</h2>
<p>Since I run my own NTP server (<i>ntp.karssen.org</i>, only accessible from inside my LAN), the NTP configuration file (<i>/etc/ntp.conf</i>) must be changed. Of course, we want Puppet to take care of this. The <i>ntp.conf</i> file I want to distribute to all nodes has the following contents (note that the only change is the name of the server and commenting the <i>restrict</i> lines):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># /etc/ntp.conf, configuration for ntpd<span style="color: #666666; font-style: italic;">; see ntp.conf(5) for help</span>
&nbsp;
driftfile /var/lib/ntp/ntp.drift
&nbsp;
&nbsp;
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
&nbsp;
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
&nbsp;
# Specify one or more NTP servers.
&nbsp;
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on <span style="">2011</span>-02-08 <span style="">&#40;</span>LP: #<span style="">104525</span><span style="">&#41;</span>. See http://www.pool.ntp.org/join.html for
# more information.
server ntp.karssen.org
&nbsp;
# Use Ubuntu's ntp server as a fallback.
server ntp.ubuntu.com
&nbsp;
# Access control configuration<span style="color: #666666; font-style: italic;">; see /usr/share/doc/ntp-doc/html/accopt.html for</span>
# details.  The web page &lt;http://support.ntp.org/bin/view/Support/AccessRestrict
ions&gt;
# might also be helpful.
#
# Note that <span style="color: #933;">&quot;restrict&quot;</span> applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
&nbsp;
# By default, exchange time with everybody, but don't allow configuration.
#restrict -<span style="">4</span> default kod notrap nomodify nopeer noquery
#restrict -<span style="">6</span> default kod notrap nomodify nopeer noquery
&nbsp;
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::<span style="">1</span>
&nbsp;
# Clients from this <span style="">&#40;</span>example!<span style="">&#41;</span> subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
&nbsp;
&nbsp;
# If you want to provide time to your local subnet, change the next line.
# <span style="">&#40;</span>Again, the address is an example only.<span style="">&#41;</span>
#broadcast 192.168.123.255
&nbsp;
# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient</pre></div></div>

<p>Save this file in <i>/etc/puppet/modules/ntp/files</i> (on the puppet master). Now edit the manifest for the ntp role (<i>/etc/puppet/modules/ntp/manifest/init.pp</i>) to add the file section and a <i>subscribe</i> command:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class ntp::client <span style="">&#123;</span>
	 package <span style="">&#123;</span> <span style="color: #933;">&quot;ntp&quot;</span>:
		      <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; installed,</span>
	 <span style="">&#125;</span>
&nbsp;
	 service <span style="">&#123;</span> <span style="color: #933;">&quot;ntp_client&quot;</span>:
	      <span style="color: #000099;">name</span>       <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;ntp&quot;</span>,
	      <span style="color: #000099;">ensure</span>     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; running,</span>
#	      hasstatus  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	      <span style="color: #000099;">hasrestart</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	      <span style="color: #000099;">require</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp&quot;</span><span style="">&#93;</span>,
	      <span style="color: #000099;">subscribe</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; File<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp_client_config&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
&nbsp;
	 file <span style="">&#123;</span> <span style="color: #933;">&quot;ntp_client_config&quot;</span>:
		   <span style="color: #000099;">path</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/etc/ntp.conf&quot;</span>,
	   <span style="color: #000099;">owner</span>   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; root,</span>
	   <span style="color: #000099;">group</span>   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; root,</span>
	   <span style="color: #000099;">mode</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; 644,</span>
	   <span style="color: #000099;">source</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;puppet:///ntp/ntp.conf&quot;</span>,
	   <span style="color: #000099;">require</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>The URL specified in the <i>source</i> line automatically looks in the right place (as mentioned just above) for the file. Because we don&#8217;t want to wait for puppet to automatically pass on this configuration, let&#8217;s run it by hand:</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">root@lambik:~# puppetd --test
info: Caching catalog for lambik.karssen.org
info: Applying configuration version '<span style="">1311936811</span>'
<span style="color: #888822;">--- /etc/ntp.conf	2011-06-17 07:59:54.000000000 +0200</span>
<span style="color: #888822;">+++ /tmp/puppet-file20110729-12128-1h3fupz-0	2011-07-29 12:53:33.279622938 +0200</span>
<span style="color: #440088;">@@ -16,16 +16,14 @@</span>
 # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
 # on <span style="">2011</span>-02-08 <span style="">&#40;</span>LP: #<span style="">104525</span><span style="">&#41;</span>. See http://www.pool.ntp.org/join.html for
 # more information.
<span style="color: #991111;">-server 0.ubuntu.pool.ntp.org</span>
<span style="color: #991111;">-server 1.ubuntu.pool.ntp.org</span>
<span style="color: #991111;">-server 2.ubuntu.pool.ntp.org</span>
<span style="color: #991111;">-server 3.ubuntu.pool.ntp.org</span>
<span style="color: #00b000;">+server ntp.karssen.org</span>
&nbsp;
 # Use Ubuntu's ntp server as a fallback.
 server ntp.ubuntu.com
&nbsp;
<span style="color: #440088;">@@ -33,8 +31,8 @@</span>
 # up blocking replies from your own upstream servers.
&nbsp;
 # By default, exchange time with everybody, but don't allow configuration.
<span style="color: #991111;">-restrict -4 default kod notrap nomodify nopeer noquery</span>
<span style="color: #991111;">-restrict -6 default kod notrap nomodify nopeer noquery</span>
<span style="color: #00b000;">+#restrict -4 default kod notrap nomodify nopeer noquery</span>
<span style="color: #00b000;">+#restrict -6 default kod notrap nomodify nopeer noquery</span>
&nbsp;
 # Local users may interrogate the ntp server more closely.
 restrict 127.0.0.1
info: FileBucket adding /etc/ntp.conf as <span style="">&#123;</span>md5<span style="">&#125;</span><span style="color: #440088;">32280703a4</span>ba7aa<span style="color: #440088;">1148c48895097</span>ed07
info: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/File<span style="">&#91;</span>ntp_client_config<span style="">&#93;</span>: Filebucketed /etc/ntp.conf to main with sum <span style="color: #440088;">32280703a4</span>ba7aa<span style="color: #440088;">1148c48895097</span>ed07
notice: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/File<span style="">&#91;</span>ntp_client_config<span style="">&#93;</span>/content: content changed '<span style="">&#123;</span>md5<span style="">&#125;</span><span style="color: #440088;">32280703a4</span>ba7aa<span style="color: #440088;">1148c48895097</span>ed07' to '<span style="">&#123;</span>md5<span style="">&#125;</span><span style="color: #440088;">0d1</span>b<span style="color: #440088;">81c95</span>bab1f6b08eb27dfaeb18bb5'
info: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/File<span style="">&#91;</span>ntp_client_config<span style="">&#93;</span>: Scheduling refresh of Service<span style="">&#91;</span>ntp_client<span style="">&#93;</span>
notice: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/Service<span style="">&#91;</span>ntp_client<span style="">&#93;</span>: Triggered 'refresh' from <span style="">1</span> events
notice: Finished catalog run in <span style="">3.06</span> seconds</pre></div></div>

<h2>Setting NFS mounts in <i>/etc/fstab</i></h2>
<p>On my clients I want to mount several NFS shares. Let&#8217;s create the directories for the <i>nfs_mounts</i> module (on the puppet master of course):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>nfs_mounts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>manifests,files,templates<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Next, let&#8217;s edit the manifest (<i>/etc/puppet/modules/nfs_mounts/manifests/init.pp</i>):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class nfs_mounts <span style="">&#123;</span>
	 # Create the shared folder unless it already exists
	 exec <span style="">&#123;</span> <span style="color: #933;">&quot;/bin/mkdir -p /var/sharedtmp/&quot;</span>:
		   <span style="color: #000099;">unless</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/usr/bin/test -d /var/sharedtmp/&quot;</span>,
	 <span style="">&#125;</span>
&nbsp;
	 mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/sharedtmp/&quot;</span>:
	    <span style="color: #000099;">atboot</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	    <span style="color: #000099;">ensure</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; mounted,</span>
	    <span style="color: #000099;">device</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;nfs.karssen.org:/var/sharedtmp&quot;</span>,
	    <span style="color: #000099;">fstype</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;nfs&quot;</span>,
	    <span style="color: #000099;">options</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;vers=3&quot;</span>,
	    <span style="color: #000099;">require</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;nfs-common&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>This should make the <i>/var/sharedtmp</i> directory and mount it. Note that I mention the <i>nfs_common</i> package in a <i>require</i> line. This package was defined in the <i>packages</i> module (in the <i>$base_packages</i> variable. Now let&#8217;s add this module to the <i>nodes.pp</i> file:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">node common <span style="">&#123;</span>
  include packages
<span style="">&#125;</span>
&nbsp;
node lambik inherits common <span style="">&#123;</span>
	include ntp::client
	include nfs_mounts
<span style="">&#125;</span></pre></div></div>

<p>Since I&#8217;ve got more than a single NFS mount, let&#8217;s extend the previous example and use a defined resource. Change the file <i>/etc/puppet/modules/nfs_mounts/manifests/init.pp</i> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">define nfs_mount<span style="">&#40;</span>
	  $location,
	  $server  <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;nfs.karssen.org&quot;</span>,
	  $options <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;vers=3&quot;</span>,
	  $fstype  <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;nfs&quot;</span>
<span style="">&#41;</span> <span style="">&#123;</span>
  file <span style="">&#123;</span><span style="color: #933;">&quot;$location&quot;</span>:
	  <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; directory,</span>
  <span style="">&#125;</span>
&nbsp;
  mount <span style="">&#123;</span> <span style="color: #933;">&quot;$location&quot;</span>:
  	<span style="color: #000099;">atboot</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	<span style="color: #000099;">ensure</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; mounted,</span>
	<span style="color: #000099;">device</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;${server}:${location}&quot;</span>,
	<span style="color: #000099;">fstype</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;$fstype&quot;</span>,
	<span style="color: #000099;">options</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;$options&quot;</span>,
	<span style="color: #000099;">require</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; <span style="">&#91;</span> Package<span style="">&#91;</span></span><span style="color: #933;">&quot;nfs-common&quot;</span><span style="">&#93;</span>, File<span style="">&#91;</span><span style="color: #933;">&quot;$location&quot;</span><span style="">&#93;</span> <span style="">&#93;</span>,
  <span style="">&#125;</span>
<span style="">&#125;</span>
&nbsp;
class nfs_mounts <span style="">&#123;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/home&quot;</span>:
		 	   <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/home&quot;</span>,
		 <span style="">&#125;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/sharedtmp&quot;</span>:
		 	    <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/var/sharedtmp&quot;</span>,
 		 <span style="">&#125;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/video&quot;</span>:
	 	    	    <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/var/video&quot;</span>,
 		 <span style="">&#125;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/music&quot;</span>:
	 	    	    <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/var/music&quot;</span>,
 		 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>Here we first define a resource called <i>nfs_mount</i>, which can accept various parameters, all of which have a default value, except <i>$location</i>. Secondly we ensure that this location is a directory and then we define how it should be mounted. In the subsequent class definition we use this <i>nfs_mount</i> resource several times to mount the various NFS shares.<br />
Note that it would have been easier if the definition of <i>nfs_mount</i> would have started with</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">define nfs_mount <span style="">&#40;</span>
	  $location <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> $name,</span></pre></div></div>

<p>because then the invocations of <i>nfs_mount</i> in the class would not<br />
need the <i>location =></i> line. Unfortunately this doesn&#8217;t work. It&#8217;s<br />
a known bug that has been fixed in version 2.6.5<br />
(http://projects.puppetlabs.com/issues/5061).</p>
<h2>Links</h2>
<ul>
<li>Article by Jes Fraser in the July 2011 edition of Linux Journal. A lot of this info was taken from this article.</li>
<li><a href="http://blog.fandotech.com/archives/938">A blog</a></li>
<li><a href="http://docs.puppetlabs.com/">The Puppet documentation</a></li>
<li><a href="http://docs.puppetlabs.com/guides/language_guide.html">The Puppet language guide</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/07/29/installing-and-configuring-puppet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making a .deb package for software that doesn&#8217;t accept the DESTDIR variable in its Makefile</title>
		<link>http://blog.karssen.org/2011/04/06/making-a-deb-package-for-software-that-doesnt-accept-the-destdir-variable-in-its-makefile/</link>
		<comments>http://blog.karssen.org/2011/04/06/making-a-deb-package-for-software-that-doesnt-accept-the-destdir-variable-in-its-makefile/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 22:07:13 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=116</guid>
		<description><![CDATA[Because I&#8217;ll be deploying a new server in the near future and I want to keep it as clean as possible I decided (again) to try to find out how to create a .deb package (as used for example by Debian and Ubuntu Linux) for some software that doesn&#8217;t follow the autotools way of doing [...]]]></description>
			<content:encoded><![CDATA[<p>Because I&#8217;ll be deploying a new server in the near future and I want to keep it as clean as possible I decided (again) to try to find out how to create a .deb package (as used for example by <a href="http://www.debian.org">Debian</a> and <a href-"http://www.ubuntu.com">Ubuntu</a> Linux) for some software that doesn&#8217;t follow the autotools way of doing things. This time I found a/the way. But first some background info.</p>
<p>In the Unix/Linux world many programs are compiled from source in three steps:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Usually the necessary files for this have been created using the <a href="http://www.gnu.org/software/hello/manual/automake/Autotools-Introduction.html#Autotools-Introduction">autotools</a>. The goal of the first step is to create a so-called <code>Makefile</code> that contains instructions on how to compile and install the files (as done in the two subsequent <code>make</code> steps.</p>
<p>Some software packages, however, include a ready-made <code>Makefile</code> that, in addition, doesn&#8217;t accept the environment variable <code>DESTDIR</code>. This last point is what makes packaging the application into a .deb file a bit tricky. The reason for this is that the package build scripts want to install the files of your application in a temporary directory and not into system-wide directories like <code>/usr/bin/</code> etc. during the packing process. As such, packaging does not require root privileges.</p>
<p>At work we use many programs and tool sets developed by ourselves and other scientists. I know from my own experience that setting up autotools for your program is not trivial. Actually, for lack of time I&#8217;ve never successfully done it and for most of the rather simple programs that I&#8217;ve written setting up a complete autoconf/automake environment seems a bit overkill. I usually ended up writing a simple <code>Makefile</code> that compiles to code and installs it (usually in <code>/usr/local/bin</code>).</p>
<p><a href="http://www.sph.umich.edu/csg/abecasis/merlin/index.html">Merlin</a> by Abecasis <i>et al</i>. is a great piece of software developed at the University of Michigan. However, as you may have expected by now, its <code>Makefile</code> does not accept the <code>DESTDIR</code> variable, instead running <code>make</code> tells you that in order to install in a different directory you&#8217;ll have to run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">INSTALLDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>some<span style="color: #000000; font-weight: bold;">/</span>other<span style="color: #000000; font-weight: bold;">/</span>directory</pre></div></div>

<p>Therefore, all quick and dirty .deb recipes one finds on the Internet do not work without some adaptations. So here is what I did to make a .deb of it. It won&#8217;t be a full tutorial on how to do packaging, see the references at the end of this post for that. I&#8217;ll assume here that you have your build environment set up (e.g. the <code>build-essential</code> and <code>fakeroot</code> packages, as well as some others).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> merlin-1.1.2.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> merlin-1.1.2
dh_make <span style="color: #660033;">--single</span> <span style="color: #660033;">--email</span> youremail<span style="color: #000000; font-weight: bold;">@</span>address <span style="color: #660033;">--file</span> ..<span style="color: #000000; font-weight: bold;">/</span>merlin-1.1.2.tar.gz</pre></div></div>

<p>Now the basic files are ready. Apart from the untarred source files the files needed for Debian packaging have also been created (in <code>merlin-1.1.2/debian</code>).</p>
<p>Time to make the necessary changes. First, since the Makefile included with merlin does not accept the <code>DESTDIR</code> variable that the Debian packaging system uses we&#8217;ll patch the Makefile in such a way that it works (I tried to fix this in the <code>debian/control</code> file, but in the end adapting the <code>Makefile</code> was much easier). I do this by changing the line</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">INSTALLDIR<span style="color: #004400;">=/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span>bin</pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;"><span style="color: #339900; font-style: italic;"># default installation directory</span>
<span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #004400;">&#40;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">DESTDIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,</span><span style="color: #CC2200;">&quot;&quot;</span><span style="color: #004400;">&#41;</span>
    INSTALLDIR<span style="color: #004400;">=/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>
<span style="color: #666622; font-weight: bold;">else</span>
    INSTALLDIR<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">DESTDIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>
<span style="color: #666622; font-weight: bold;">endif</span></pre></div></div>

<p>Let&#8217;s do some polishing of the package. I don&#8217;t want to make the perfect package, but adding a bit of text to the <code>debian/control</code> file make a lot of difference. This is what it looked like after my edits:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Source: merlin
Section: science
Priority: extra
Maintainer: Lennart C. Karssen &lt;youremail@address&gt;
Build-Depends: debhelper (&gt;= 7)
Standards-Version: 3.8.3
Homepage: http://www.sph.umich.edu/csg/abecasis/merlin/index.html
&nbsp;
Package: merlin
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Package for fast pedigree analysis
 MERLIN uses sparse trees to represent gene flow in pedigrees
 and is one of the fastest pedigree analysis packages around
 (Abecasis et al, 2002).</pre></div></div>

<p>Also editing the file <code>debian/changelog</code> is a good idea, especially since I changed the source code (remember the <code>Makefile</code>?). This is what I wrote:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">merlin (1.1.2-1) unstable; urgency=low
&nbsp;
  * Initial release
  * Adjusted Makefile to make DESTDIR work.
&nbsp;
 -- Lennart C. Karssen &lt;youremail@address&gt;  Tue, 05 Apr 2011 12:04:21 +0200</pre></div></div>

<p>Officially you should edit the <code>debian/copyright</code> file as well, but since the merlin licence doesn&#8217;t allow distribution of the source or the binaries I didn&#8217;t bother.</p>
<p>To finally build the package run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dpkg-buildpackage <span style="color: #660033;">-rfakeroot</span> <span style="color: #660033;">-us</span> <span style="color: #660033;">-uc</span></pre></div></div>

<p>This creates a <code>.deb</code> file in the directory where you started. As a final touch you can check your package for errors with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lintian ..<span style="color: #000000; font-weight: bold;">/</span>merlin_1.1.2-<span style="color: #000000;">1</span>_amd64.deb</pre></div></div>

<p>References:</p>
<ul>
<li>
<a href="http://www.debian.org/doc/maint-guide">http://www.debian.org/doc/maint-guide</a>
</li>
<li>
<a href="http://www.debian-administration.org/articles/337">http://www.debian-administration.org/articles/337</a>
</li>
<li>
<a href="http://www.webupd8.org/2010/01/how-to-create-deb-package-ubuntu-debian.html">http://www.webupd8.org/2010/01/how-to-create-deb-package-ubuntu-debian.html</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/04/06/making-a-deb-package-for-software-that-doesnt-accept-the-destdir-variable-in-its-makefile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

