<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Thomas 'Toke' Kerpe</title>
 <link href="http://toke.de/atom.xml" rel="self"/>
 <link href="http://toke.de/"/>
 <updated>2012-05-02T20:22:00+02:00</updated>
 <id>//toke.de/</id>
 <author>
   <name>Thomas Kerpe</name>
   <email>web@toke.de</email>
 </author>

 
 <entry>
   <title>Git Branch in bash prompt</title>
   <link href="http://toke.de/blog/2012/03/27/git-branch-prompt/"/>
   <updated>2012-03-27T00:00:00+02:00</updated>
   <id>/blog/2012/03/27/git-branch-prompt</id>
   <content type="html">&lt;h1 id='gittipp'&gt;Git-Tipp&lt;/h1&gt;

&lt;p&gt;My Bash prompt is something like this &lt;code&gt;archimedes:toke.de(master) toke$&lt;/code&gt;. Where &lt;code&gt;archimedes&lt;/code&gt; is the hostname, &lt;code&gt;toke.de&lt;/code&gt; the directory within an git checkout, &lt;code&gt;master&lt;/code&gt; the actual branch and &lt;code&gt;toke&lt;/code&gt; my username. To get this result set this &lt;code&gt;PS1&lt;/code&gt; in your &lt;code&gt;.bashrc&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;## Add Git-Branch
PS1=&amp;#39;\h:\W$(__git_ps1 &amp;quot;(%s)&amp;quot;) \u\$ &amp;#39;&lt;/code&gt;&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>Unix permission pitfalls #1</title>
   <link href="http://toke.de/blog/2012/03/05/unix-permission-pitfalls-1/"/>
   <updated>2012-03-05T00:00:00+01:00</updated>
   <id>/blog/2012/03/05/unix-permission-pitfalls-1</id>
   <content type="html">&lt;h1 id='unix_permission_pitfalls_1'&gt;Unix permission pitfalls #1&lt;/h1&gt;

&lt;p&gt;Let&amp;#8217;s do an experiment:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mkdir test
$ cd test
$ mkdir abc
$ sudo chown -R root:root abc
$ ls -lsa abc
total 8
4 drwxr-xr-x  2 root   root   4096 2012-03-05 10:03 .
4 drwxr-xr-x 10 user   user   4096 2012-03-05 10:03 ..&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ok, that&amp;#8217;s clear we created an empty directory and changed the ownership to root. Now to something destructive:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rm -rf abc
$ ls abc
ls: cannot access abc: No such file or directory&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hoops? Why could the user delete this directory?&lt;/p&gt;

&lt;h2 id='explanation'&gt;Explanation&lt;/h2&gt;

&lt;p&gt;The reason we can delete root owned files and (empty) directories in our case is because the &lt;em&gt;write&lt;/em&gt; of our delete is done in our freshly created directory &amp;#8220;test&amp;#8221; - which is owned - &lt;strong&gt;by us&lt;/strong&gt;. You can think of an unix directory like an special file which contains the directory information of the containing elements. &lt;strong&gt;If we can write to the containing directory we can delete its contents.&lt;/strong&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Postgre password in psql</title>
   <link href="http://toke.de/blog/db/2012/02/28/pgpass/"/>
   <updated>2012-02-28T00:00:00+01:00</updated>
   <id>/blog/db/2012/02/28/pgpass</id>
   <content type="html">&lt;h1 id='store_a_password_for_use_in_psql'&gt;Store a password for use in psql&lt;/h1&gt;

&lt;p&gt;I was asked today how to use store an password for use with &lt;code&gt;psql&lt;/code&gt;. I&amp;#8217;ve done this before several times but could not remember how. So I tried to look it up with man psql. There was a referer to .pgpass but no syntax. The pgpass is part of libpq. So this is a reminder to myself:&lt;/p&gt;

&lt;h2 id='pgpass_format'&gt;.pgpass format&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;hostname:port:database:username:password&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To quote the &lt;a href='http://www.postgresql.org/docs/8.2/static/libpq-pgpass.html'&gt;Documentation&lt;/a&gt;: &amp;#8220;Each of the first four fields may be a literal value, or *, which matches anything.&amp;#8221;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Evaluating Disqus (updated)</title>
   <link href="http://toke.de/blog/2012/02/21/disqus/"/>
   <updated>2012-02-21T00:00:00+01:00</updated>
   <id>/blog/2012/02/21/disqus</id>
   <content type="html">&lt;h2 id='commenting'&gt;Commenting&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;m not a big fan of external services. Especially since I do not log IP-Adresses and offloading Javascript gives some more problems with privacy. This site is very simple. But I want to add comments to blog posts. My plan was to write a little comment script for embedding via Javascript. Since I don&amp;#8217;t have so much time right now I will look for alternatives. Now I am experimenting with &lt;a href='http://disqus.com'&gt;disqus&lt;/a&gt;. The service looks nice and integrates very well with my site. One downside is the missing SSL support. I will look after this later.&lt;/p&gt;

&lt;p&gt;For the next weeks the disqus service will be available on this site, maybe for a longer time. We&amp;#8217;ll see. Feel free to comment.&lt;/p&gt;

&lt;h2 id='update_22042012'&gt;Update (22.04.2012)&lt;/h2&gt;

&lt;p&gt;Disqus seems to work with SSL now. I&amp;#8217;ve enabled it. Hope this will stay alive.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>How do I Post</title>
   <link href="http://toke.de/blog/perl/2012/02/09/how-i-post/"/>
   <updated>2012-02-09T00:00:00+01:00</updated>
   <id>/blog/perl/2012/02/09/how-i-post</id>
   <content type="html">&lt;h2 id='or_how_this_site_is_updated'&gt;Or how this site is updated&lt;/h2&gt;

&lt;p&gt;This site is build via &lt;a href='http://jekyllrb.com/'&gt;jekyll&lt;/a&gt; and the sources are coming from a git repository on &lt;a href='https://github.com'&gt;github&lt;/a&gt;. I do not write something special about &lt;code&gt;git&lt;/code&gt; or &lt;code&gt;jekyll&lt;/code&gt; here. Just how the &amp;#8220;deployment&amp;#8221; works.&lt;/p&gt;

&lt;h2 id='github_webhook'&gt;Github webhook&lt;/h2&gt;

&lt;p&gt;&lt;img alt='Github Webhook' src='/assets/github-webhook.png' /&gt;&lt;/p&gt;

&lt;p&gt;Github has a nice feature called &amp;#8220;Service hooks&amp;#8221; - especially a &amp;#8220;Post-Receive URLs&amp;#8221; hook. I use this hook to notify my server to do a &lt;code&gt;git pull&lt;/code&gt; on a local repository, then rebuild the site with &lt;code&gt;jekyll&lt;/code&gt; and &lt;code&gt;rsync&lt;/code&gt; changed data to the document root.&lt;/p&gt;

&lt;p&gt;The perl webhook endpoint (Dancer.pm code):&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='perl'&gt;    &lt;span class='nb'&gt;package&lt;/span&gt; &lt;span class='n'&gt;ReceiveHook&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='k'&gt;use&lt;/span&gt; &lt;span class='n'&gt;Dancer&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;:syntax&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    
    &lt;span class='k'&gt;our&lt;/span&gt; &lt;span class='nv'&gt;$VERSION&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;0.3&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    
    &lt;span class='c1'&gt;# Configuration for different projects&lt;/span&gt;
    &lt;span class='k'&gt;my&lt;/span&gt; &lt;span class='nv'&gt;$config&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='s'&gt;&amp;quot;PROJECTNAME&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='n'&gt;run&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;/home/user/bin/updateblog.sh&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='p'&gt;},&lt;/span&gt;
    &lt;span class='p'&gt;};&lt;/span&gt;
    
    &lt;span class='n'&gt;prefix&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;/notify&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    
    &lt;span class='n'&gt;get&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;/*&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;sub &lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;header&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;Allow&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;POST&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='n'&gt;status&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;405&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='s'&gt;&amp;quot;Not for you\n&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;};&lt;/span&gt;
    
    &lt;span class='n'&gt;post&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;/:project&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;sub &lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ow'&gt;not&lt;/span&gt; &lt;span class='nb'&gt;defined&lt;/span&gt; &lt;span class='nv'&gt;$config&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;params&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;project&lt;/span&gt;&lt;span class='p'&gt;}})&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='n'&gt;status&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;not_found&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
            &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;No such project: &amp;quot;&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;params&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;project&lt;/span&gt;&lt;span class='p'&gt;}&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;\n&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
    
        &lt;span class='k'&gt;my&lt;/span&gt; &lt;span class='nv'&gt;$payload&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;params&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;payload&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;};&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ow'&gt;not&lt;/span&gt; &lt;span class='nb'&gt;defined&lt;/span&gt; &lt;span class='nv'&gt;$payload&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='n'&gt;status&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;415&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
            &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;I need a payload\n&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
    
        &lt;span class='c1'&gt;# Read the configuration for that repo&lt;/span&gt;
        &lt;span class='k'&gt;my&lt;/span&gt; &lt;span class='nv'&gt;$repo_config&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nv'&gt;$config&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='nv'&gt;$repo&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt;&lt;span class='p'&gt;}};&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;defined&lt;/span&gt; &lt;span class='nv'&gt;$repo_config&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='nb'&gt;defined&lt;/span&gt; &lt;span class='nv'&gt;$repo_config&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;run&lt;/span&gt;&lt;span class='p'&gt;})&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='nb'&gt;eval&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
                &lt;span class='nb'&gt;system&lt;/span&gt; &lt;span class='nv'&gt;$repo_config&lt;/span&gt;&lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;run&lt;/span&gt;&lt;span class='p'&gt;};&lt;/span&gt;
            &lt;span class='p'&gt;};&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
    
        &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;OK&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;};&lt;/span&gt;
    
    &lt;span class='n'&gt;true&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The update itself is done by this little shellscript:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='sh'&gt;    &lt;span class='c'&gt;#!/bin/sh&lt;/span&gt;

    &lt;span class='nv'&gt;REPPATH&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;/home/user/git/localgitrepository&amp;quot;&lt;/span&gt;
    &lt;span class='nv'&gt;DEPLOYTARGET&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;/var/www/sites/mydomain&amp;quot;&lt;/span&gt;
    &lt;span class='nv'&gt;LIVEURL&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;http://mydeploydomain.tld&amp;quot;&lt;/span&gt;

    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt; -d &lt;span class='k'&gt;${&lt;/span&gt;&lt;span class='nv'&gt;REPPATH&lt;/span&gt;&lt;span class='k'&gt;}&lt;/span&gt; &lt;span class='o'&gt;]&lt;/span&gt; ; &lt;span class='k'&gt;then&lt;/span&gt;
&lt;span class='k'&gt;        &lt;/span&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;${REPPATH}&amp;quot;&lt;/span&gt;
        git pull
        jekyll --url &lt;span class='s2'&gt;&amp;quot;${LIVEURL}&amp;quot;&lt;/span&gt;
        rsync -rXogpEAt _site/ &lt;span class='s2'&gt;&amp;quot;${DEPLOYTARGET}&amp;quot;&lt;/span&gt;
    &lt;span class='k'&gt;fi&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;aside&gt;
&lt;h2&gt;More&lt;/h2&gt;
&lt;p&gt;
That is just the surface what really is possible. I also use this method in
different other setups. Just to mention differnet usecases:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Keep repositories synchronized&lt;/li&gt;
&lt;li&gt;Automatic Builds&lt;/li&gt;
&lt;li&gt;Automatic deployments&lt;/li&gt;
&lt;li&gt;Test framework&lt;/li&gt;
&lt;li&gt;Configuration management&lt;/li&gt;
&lt;li&gt;Even a small distributed site or WiKi is possible&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
With a simple git post-commit-hook such a http Post with `curl` it is
github independent.&lt;/p&gt;
&lt;/aside&gt;
&lt;h2 id='code'&gt;Code&lt;/h2&gt;

&lt;p&gt;&lt;a href='https://github.com/toke/dancing-github-webhooks'&gt;Github repository&lt;/a&gt; feel free to use it as you like.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Hello world</title>
   <link href="http://toke.de/blog/2011/08/17/hello-world/"/>
   <updated>2011-08-17T00:00:00+02:00</updated>
   <id>/blog/2011/08/17/hello-world</id>
   <content type="html">&lt;h1 id='hello_from_jekyll'&gt;Hello from Jekyll&lt;/h1&gt;

&lt;p&gt;First post from jekyll.&lt;/p&gt;</content>
 </entry>
 
 
</feed>

