Igor Moiseev Applied mathematician, Web Developer

Show git branch in the bash command prompt

When you install git on your computer, you may find new variables available in the environment, it is $(__git_ps1). This variable contains the branch name of the current repository. The only thing you need to edit ~/.bashrc and add $(__git_ps1) to the PS1 definition in this way

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ '
fi

N.B. the $(__git_ps1) is available by default for Ubuntu >= 14.04, you may check if it works by just going to any git repository and run echo $(__git_ps1)

~/Work/moiseevigor.github.io $ echo $(__git_ps1);
(master)

If you see an empty string, so just source it from /etc/bash_completion.d/git, and in this case the ~/.bashrc will look like

source /etc/bash_completion.d/git

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ '
fi

This is it, now you have a gorgeous prompt

:~/moiseevigor.github.io (master)$ 

Have a nice branching!

Remove old kernels in Ubuntu

To remove old linux kernels and leave the current one

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Be aware, the command uses uname -r to get the current kernel.

Clone repository from Subversion to Git

Here we discus how to migrate the Subversion repository into a new Git repository. We’ll do it with a handy git svn utility. We will refer Gitlab/Github as the destination Git server.

Create a new project on Gitlab: http://\<gitlab-address\>/projects/new and clone it into your local machine

git svn clone http://<svn-address>/<projectname>
cd <projectname>
git remote add origin git@gitlab.newentity.it:newentity-sas/<projectname>.git
git push -u origin master

Now backup your SVN project folder

cp -raux <projectname> <projectname>.`date +'%Y%m%d'`

And remove .svn folders

cd <projectname>
rm -rf `find . -type d -name .svn`

Init GIT

git init

Config GIT

git config --global user.name "Full Name"
git config --global user.email "Email@example.com"

Check the remote url

git config remote.origin.url

Change the remote origin

git config remote.origin.url git@<gitlab-url>:<username>/<projectname>.git

Create a .gitignore file

echo "<projectname>.sublime*" > .gitignore

Add files

git add .

Commit il progetto

git commit -m "init <projectname>"
[master 820fe97] init <projectname>

Pull and merge from remote

git pull

Push into remote

git push -u origin master

Apache2: AH01630: client denied by server configuration

The Apache web server of the version 2.4 introduces a new style for <VirtualHost> configuration, in particular the <Directory> syntax is not compatible anymore with the previous one 2.2.

The old styled configuration valid in the Apache <= 2.2 version

<VirtualHost *:80>

    ...

    <Directory "/var/www/html/example.com/public">
        Options MultiViews FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>

    ...

</VirtualHost>

the modification is introduced in the part

Order allow,deny
Allow from all

the new way to describe the access permitions is reduced to just one line

Require all granted

finally the correct <VirtualHost> configuration will look like the following

<VirtualHost *:80>
    ServerName  www.example.com
    ServerAlias example.com

    DirectoryIndex index.html index.php index.htm
    DocumentRoot /var/www/html/example.com/public

    <Directory "/var/www/html/example.com/public">
        Options MultiViews FollowSymLinks
        AllowOverride all
        Require all granted
    </Directory>

    # Logfiles
    ErrorLog  /var/log/apache2/example.com/error.log
    CustomLog /var/log/apache2/example.com/access.log combined
</VirtualHost>

Fail2Ban starting 200/error on Ubuntu 10.04 or older

If you get this sudden error in the fail2ban.log

2015-04-20 11:13:17,722 fail2ban.jail   : INFO   Jail 'apache-honeypot' started
2015-04-20 11:13:17,739 fail2ban.actions.action: ERROR  iptables -N fail2ban-apache-honeypot
iptables -A fail2ban-apache-honeypot -j RETURN
iptables -I INPUT -p tcp -m multiport --dports apache-honeypot -j fail2ban-apache-honeypot returned 200

most likely you have spotted the character length limitation on the chain name.

I’ve discovered that the limit is 16 for the chain name length, but Fail2Ban prefixes it with fail2ban- string which eats so precious 9 characters so the only 7 remaining.

To solve this issue you need to rename the iptables action to something like name=HONEY

$ cat /etc/fail2ban/jail.conf

[apache-honeypot]
enabled  = enable
filter   = apache-honeypot
action   = iptables-allports[name=HONEY, protocol=all]
logpath  = /var/log/asterisk/full
maxretry = 3
bantime  = 600

Thas it! The issue is observed on Fail2Ban ver. 0.8 or older.