Category Archives: Linux

urxvt clickable links with ctrl-click

Today some friends and I messed around with urxvt and we wondered how we could make urxvt launch URLs with not only a simple mouse click, but with ctrl-click. Well, I had to dig around in the source code for this:

sub on_start {
   my ($self) = @_;

   $self->{launcher} = $self->my_resource ("launcher") || $self->x_resource("url-launcher") || "sensible-browser";

   $self->{urls} = [];
   $self->{showing} = 0;
   $self->{button}  = 2;
   $self->{state}   = 0;
   if($self->{argv}[0] || $self->my_resource ("button")) {
      my @mods = split '', $self->{argv}[0] || $self->my_resource ("button");
      for my $mod (@mods) {
         if($mod =~ /^d+$/) {
            $self->{button} = $mod;
         } elsif($mod eq "C") {
            $self->{state} |= urxvt::ControlMask;
         } elsif($mod eq "S") {
            $self->{state} |= urxvt::ShiftMask;
         } elsif($mod eq "M") {
            $self->{state} |= $self->ModMetaMask;
         } elsif($mod ne "-" && $mod ne " ") {
            warn("$mod is invalid in $self->{_name}<$self->{argv}[0]>n");
         }
      }
   }

(from http://cvs.schmorp.de/rxvt-unicode/src/perl/matcher?revision=1.13&view=markup#l188)

Basically it would split the input from URxvt.matcher.button and set different settings. So to enable ctrl-click you have to pre- or postpend a capital C, S for shift and M for the meta-key. My config now looks like this:

! ~.Xresources
URxvt.perl-ext-common:  default,matcher
URxvt.url-launcher:     /opt/google/chrome/google-chrome
URxvt.matcher.button:   C1

/bin/sh under Mac OS X is not the same as under linux

I just encountered a rather interesting issue while doing some shell scripting under Mac OS X 10.6 Snow Leopard. While this code perfectly runs:

#!/bin/sh

function foo {
  echo "blabla"
}

foo

It won’t under linux

/path/foo.sh: 3: function: not found
blabla
/path/foo.sh: 5: Syntax error: "}" unexpected

The solution is to change “#!/bin/sh” to “#!/bin/bash”. And then it works under both systems.

Redmine does not give read-only access to the git-repo

The problem

I wrote how to install redmine on a debian server with mysql and everything went fine so far, until one day somebody wanted to clone a repo.

fatal: http://domain.tld/git/example.git/info/refs not found:
did you run git update-server-info on the server?

The analysis

So I thought it would solve the problem to run the command in the according git-repo. Nope, it didn’t. But accessing it via gitosis@domain.tld/git/example.git did actually work fine. That’s what puzzled me. Long story short: The apache tried to deliver a directory respectively a file that simply didn’t exist in the path. My redmine is located in /var/www/redmine and there is simply no directory git/ in there. But the gitosis@domain.tld/git/example.git was delivered by the gitosis daemon! So one could easily work while the other not.

The solution

So as soon I understood that I struggled with a totally different problem than git told me (the apache simply didn’t find the file), it was quite easy to fix it. Just add the following line to your redmine apache config, restart apache and everything should be fine.

Alias /git /srv/gitosis/repositories

SCM with git, for the graphically minded

SCM means Source Code Management and is not much of a magic when I tell you that basically it’s not much more than using CVS, SVN, git or mercurial for instance. These are very powerful tools indeed and sometimes a CLI just doesn’t feel intuitive in world where we judge the tools by their look&feel and sincerly a visual diff is easier to understand. Also I wanted to make a translation of my post over at G+.

Mac OS X

Free/FOSS

Gity App

It is FOSS (GPLv3) and runs 10.6 and 10.7. Frankly I didn’t run into any limitations but probably because I’m not using all git’s power and complexity. I think this is a good tool for daily use.

Gity App

http://gityapp.com/

Gitx

Also FOSS (GPLv2) but with a very simple interface, in my opinion a bit too simple so I can only recommend it for the very very beginner, though a very good app.

Gitx App

http://gitx.frim.nl/

Gitti

Gitti is free of charge, but I’m not sure how the development is going on. It is noted as ‘Beta’ which could mean that the final version may be shareware. However I found the interface a bit disturbing: I don’t see the changes in the commit area which makes it hard to know what to write in the commit message. On the other hand I found the Configuration area quite interesting.

Gitti App

http://www.gittiapp.com/

SmartGit

SmartGit is also free and provides also clients for Windows and Linux. You may use it free for non-commercial use, but the interface looks more like a tool from a few years ago. Oh, and the log buttons opens a new window. Probably not the worst client for code review but … no, I’m not convinced.

SmartGit

http://www.syntevo.com/smartgit/

Gitbox

Well, it’s not exactly shareware though $39.00 (50% discount for students), it just restricts you to three projects in the sidebar, but if you remove a project from the sidebar and add a other one, it works. Unfortunately it lacks of an integrated diff view.

Gitbox

http://gitboxapp.com/

Shareware

Tower

Unfortunately it is shareware and costs €49.00 but on the other side you can test it for 30 days. You get 50% discount as a student. The earlier beta versions were free of charge, but you were forced to update every 30 days or so.

Tower App (git-tower)

http://git-tower.com

SourceTree

SourceTree (€45.00, 21 days trial) brings the most complicated interface I think but also feels like it uses the whole power git provides. It also supports mercurial, so if you ever happen to use both, you should consider this GUI. Oh, but I don’t like the icons, the look too candy to me.

SourceTree

http://www.sourcetreeapp.com/

Sprout

Sprout is only sold via the Apple App Store for $35.00 but doesn’t make a good figure. The log doesn’t show any changes in the code which disappoints. In my opinion it’s not worth testing, but the low version number indicates there might be some changes in the future.

Sprout
http://gitmacapp.com/sprout

Windows

Since I no longer use Windows I just googled a bit.

Free/FOSS

tortoisegit

When you know tortoisesvn, you’ll know your way around tortoisegit. It’s FOSS and brings a redmine bugtracker plugin.

Linux

Well, I never used any GUI for git under Linux, but I’d like to point out to two good looking: qgit and gitg. You should find them in your distros repo.

Android

FOSS

agit

Yes, there is a git client for android! But it costs you something like CHF 2.20. I didn’t try it out, I followed the instruction to build your own agit and I didn’t managed to get it work. Maybe you are more lucky than I am.

Crash course!

Well, finally we got some tools to work with but the code also should find its way to a centralized place. I suggest to have a look at setting up your own server and then setting tortoisegit if you use windows and github.

There’s also my tutorial for setting up redmine (a bugtracker with git support) on debian or you can take a look at gitorious which provides hosting for code for free. And if you’re still thinking that this is soooo complicated, have a look here.

Finally I’d like to point you to the most valuable document for entry level git user: Everyday GIT With 20 Commands Or So

Final words

If you happen to use a GUI I didn’t mention or found other good or interesting stuff, let me know. I acknowledge that this post is a bit long on Mac OS X apps due I use this daily, I’d be really happy if you write a post about linux GUIs and I’ll link to your post, I promise!

Personally I use Gity and maybe I’ll buy Tower one day, depending how much I’ll use git. I also like to thank my friends over at NGAS for their support!

Installing Redmine and gitosis on a Debian root-server with MySQL

So I wanted a bugtracker with a little of everything and git integration. First of all I must admit that this wasn’t easy and I wasted some time figuring out how to get this stuff working. Since I love to see tutorials and manuals myself, I’ll share my experience.

Be aware though that Ruby on Rails consumes a lot of RAM and will not run on 128MB RAM. I had to upgrade my VPS which now runs fine with 512MB RAM. I installed Redmine 1.0.1-stable on my Debian Squeeze 6 with the MySQL backend, but not without getting serious trouble when enabling the gitosis plugin: Whenever a username in git contained a umlaut, it just threw a server error. Finally I was able to tackle down the problem with a lot of help from friends over at #bsdprojects.

WARNING: This post is not intended to provide a foolproof guide or a newbie tutorial. This is meant for someone being able to handle a full root server.

INSTALLING PACKAGES

Install the needed debian packages:

apt-get install acl apache2 apache2-mpm-prefork apache2-prefork-dev build-essential cron git-core gitosis git-daemon-run libapache-dbi-perl libapache2-mod-passenger libapache2-mod-perl2 libcurl4-openssl-dev libdigest-sha1-perl libgemplugin-ruby libgemplugin-ruby1.8 libmysqlclient15-dev libnet-ssh-ruby1.8 librmagick-ruby1.8 libruby-extras libruby1.8-extras mysql-server python-setuptools rake redmine redmine-mysql ruby ruby1.8-dev rubygems sudo wget

CONFIGURING & SETUP

MySQL

This is where I failed in the first attempt, MySQL obviously has severe problems with the encoding and a configuration change was the solution eventually. Be sure to add the following to  /etc/mysql/my.cnf before you do anything else:

[client]
default-character-set=utf8

[mysqld]
default-character-set = utf8
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8

Now create the DB:

mysql -u root -p

CREATE DATABASE redmine CHARACTER SET utf8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL privileges ON redmine.* TO 'redmine'@'localhost';
quit;

Configure redmine:
vi /etc/redmine/default/database.yml

  production:
    adapter: mysql
    database: redmine
    host: localhost
    username: redmine
    password: my_password
    encoding: utf8

Installing the gems

Now comes the funny part, you need to exactly these versions or you’ll encounter strange errors:
gem install rails -v=2.3.11
gem install rack -v=1.1.0
gem install mysql
gem install -v=0.4.2 i18n
gem install inifile lockfile net-ssh

Get Redmine in place

ln -s /usr/share/redmine /var/www/redmine
chown -R www-data:www-data /var/www/redmine
chmod -R 755 /var/www/redmine
cd /var/www/redmine
rake generate_session_store
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data

Apache

a2enmod passenger
vi /etc/apache2/sites-avaible/redmine

    <VirtualHost *:80>
        ServerName redmine.domain.tld
        DocumentRoot /usr/share/redmine/public
        <Directory /usr/share/redmine/public/>
                Options -MultiViews
        </Directory>
    </VirtualHost>


a2ensite redmine
/etc/init.d/apache2 reload
/etc/init.d/apache2 restart

Now your Apache should be able to handle the redmine bugtracker.

 Integrate gitosis

vi /etc/fstab

    …
    /dev/foo /  ext3  acl,errors=remount-ro 0 1
    …

reboot
sudo -H -u gitosis ssh-keygen -t dsa

Set no password, use standard path/file

sudo -u gitosis cat ~gitosis/.ssh/id_dsa.pub | sudo -H -u gitosis gitosis-init
sed -i.orig 's:/var/cache:/srv/gitosis:g' /etc/sv/git-daemon/run
sv restart git-daemon
setfacl -m user:www-data:r-x,mask:r-x ~gitosis/.ssh
setfacl -m user:www-data:r--,mask:r-- ~gitosis/.ssh/id_dsa
script/plugin install git://github.com/xdissent/redmine_gitosis.git
sudo -u www-data X_DEBIAN_SITEID=default RAILS_ENV=production rake db:migrate:plugins
/etc/init.d/apache2 restart

Point your browser to your installation, log in, go to Administration -> Plugins -> Configure Redmine Gitosis, change ‘localhost’ to your domain, change xdissent.com to your domain.

The repository

Now …

  • create a normal user
  • give him administrator access
  • logout as admin, login as user
  • create new project
  • give yourself at least ‘Developer’ role (Settings -> Members)
  • go to Settings -> Repository, choose git as SCM (this step was actually nowhere mentioned …)
  • now you’ll see a new menu (on the blue background) called ‘Repository’, click on it and follow the instruction written there.

You should be able to push your git repo to the redmine server finally.

SOURCES

MySQL + UTF-8 = Not So Obvious
TUTORIAL: REDMINE WITH GIT AND GITOSIS ON UBUNTU 11.04
GitHub Clone with Redmine