Archive for August 26th, 2011

How to add svn hooks with SVNManager in Ubuntu

So, once we set up our svn and SVNManager in Ubuntu, it would probably be nice to get emails every time a user in the repository makes a commit.
Svnmanager supports the post create script, which will be fired every time a new repository gets created. Lets start:

sudo gedit /var/www/svnmanager/config.php

at the end of the config, uncomment and edit the line to:

$post_create_script = "/bin/bash /var/www/newrepo-script";

Now lets create the newrepo-script:


$post_create_script = "/bin/bash /var/www/newrepo-script";

And add these lines:

#!/bin/bash
 
cp -R /var/www/repo-templates/* $1/hooks/

which pretty much just tells to copy the content of the templates folder to the newly created repository’s /hooks/ directory. /hooks directory will execute the hooks that we place there on each event that we create. We will add post-commit hook for this example.


cd /var/www
sudo mkdir repo-templates

now the hook


sudo gedit post-commit

Add these lines and save:

#!/bin/sh
 
REPOS="$1"
REV="$2"

/usr/bin/svnnotify                    \
    --repos-path    "$REPOS"                \
    --revision      "$REV"                  \
    --subject-cx                            \
    --with-diff                             \
    --handler       HTML::ColorDiff         \
    --to            to_email@email.com   \
    --from          root@localhost

Feel free to edit the email addresses. Now we need to make the script executable:


sudo chmod +x post-commit

Make sure that you have svnnotify package. Type:

which svnnotify

and if it shows the path, make sure it is the same as we made in post-commit file, if not, edit post-commit file. If path doesn’t show, chances are you don’t have the package installed. Install it by:


sudo apt-get install libsvn-notify-perl

This should do it. If you want to send the emails to every user in the repository, you may have to edit the hook. I found another good tutorial about it here.

Update: I created the hook the way I wanted it, for complete code visit this page – svn post-commit hook in Ubuntu.

How to install postfix to relay mail through gmail in Ubuntu

Once I got my svnmanager working on Ubuntu, I still had problems sending mail. I pointed the domain mx record to the right direction, but for some reason my port 25 was refusing connections. So I decided to relay the mail through my gmail account.

First, install postfix if you haven’t already:


sudo apt-get install postfix

Now, to set up postfix, make sure that you have these files:

/etc/postfix/main.cf

/etc/postfix/generic

/etc/postfix/generic.db

/etc/postfix/sasl/passwd

/etc/postfix/sasl/passwd.db

which you can create via touch command like:

 

cd /etc/postfix
sudo touch generic

Next, edit /etc/postfix/main.cf (via command: sudo gedit /etc/postfix/main.cf), here is mine

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

#readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#myorigin = /etc/mailname
mydestination = my-ubuntu, localhost.localdomain, localhost
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

##########################################
##### non debconf entries start here #####

##### client TLS parameters #####
smtp_tls_loglevel=1
smtp_tls_security_level=encrypt
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl/passwd
smtp_sasl_security_options = noanonymous

##### map username@localhost to username@gmail.com #####
smtp_generic_maps=hash:/etc/postfix/generic

Next, edit /etc/postfix/generic


sudo gedit /etc/postfix/generic

and have replace user_name and email_address with your credentials, add all users that may send email through gmail:


user_name@localhost email_address@gmail.com
root@localhost email_address@gmail.com
svnmanager@192.168.1.5 email_address@gmail.com

Now lets generate generic.db from this file:


cd /etc/postfix
sudo postmap generic

Next, lets add your gmail credentials to password file:


cd /etc/postfix/sasl
sudo gedit passwd

Copy this, replace email_address with your gmail email username and gmail_password with your gmail password:


[smtp.gmail.com]:587 email_address@gmail.com:gmail_password

Save the file, lets generate passwd.db now:


cd /etc/postfix/sasl
sudo postmap passwd
chown root.root passwd passwd.db
chmod 600 passwd passwd.db

Restast postfix:


/etc/init.d/postfix restart

Test (replace user_name with your user name):


echo 'test email' | mail -s 'just a test' email_address@gmail.com
sudo sendmail -bv user_name
sudo sendmail -bv email_address@gmail.com

You should receive the email now, sent from your localhost.

If there are any problems, check you /var/log/mail.log

How to install svn for apache and svnmanager on Ubuntu

This tutorial will guide through installation of subversion on Ubuntu to work with apache, and then installing svnmanager. Svnmanager is a handy tool that lets you manage the users and repositories through the web interface. Before we begin, make sure you have a lamp server setup on Ubuntu.

First, lets install subversion and apache library:


sudo apt-get install subversion libapache2-svn

Lets create the directories in which svn repositories and configurations will reside and give apache access to them:


cd /srv
sudo mkdir svn
sudo mkdir svnconfig
cd svn
sudo mkdir repos
sudo chown -R www-data.www-data /srv/svnconfig /srv/svn

Next, we need to set up apache and allow access to subversion repository:


sudo gedit /etc/apache2/mods-enabled/dav_svn.conf

Uncomment the lines like below, file names will be created at a later stage by svnmanager:

 

<location /svn>
# Uncomment this to enable the repository
DAV svn

# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /srv/svn/repos

# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /srv/svn/htpasswd

# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
Require valid-user

# To enable authorization via mod_authz_svn
AuthzSVNAccessFile /srv/svn/accessfile

</location>

 

Lets restart Apache:


sudo /etc/init.d/apache2 restart

Now lets create a new user in MySql for svnmanager. Get to mysql client using this command:


sudo mysql -u root -p

Type in your password and execute this mysql command:


CREATE DATABASE svnmanager;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER on svnmanager.* to svnmanager identified by 'password';
FLUSH PRIVILEGES;

Where password should be replaced by your password.

Next, if you followed my tutorial on installing lamp, you may need to add php-pear as it was not added previously. Got to the terminal and type:


sudo apt-get install php-pear

Next, lets install the pear VersionControl_SVN module, type:


sudo pear install -f -o VersionControl_SVN

Now we are ready to install SVNManager. Download the latest package, I’ll get mine from http://svnmanager.org, at the time of writing the latest is 1.08. The file itself is at http://prdownloads.sourceforge.net/svnmanager/svnmanager-1.08.tar.gz I am going to download the tar.gz one in my Apache web directory which is /var/www/ :


cd /var/www/
sudo wget http://prdownloads.sourceforge.net/svnmanager/svnmanager-1.08.tar.gz

Now lets untar (Ubuntu tar tutorial) it:


sudo tar xzf svnmanager-1.08.tar.gz

I will rename the folder for convenience:


sudo mv svnmanager-1.08 svnmanager

Now the fun part, lets copy and open the configuration file:


cd svnmanager
sudo cp config.php.linux config.php
sudo gedit config.php

Here you can start changing the language and htpasswd locations if you need. Since I have default installation and everything seems correct, I move to the next lines for svn locations:


$svn_config_dir = "/srv/svnconfig";
$svn_repos_loc = "/srv/svn/repos";
$svn_passwd_file = "/srv/svn/htpasswd";
$svn_access_file = "/srv/svn/accessfile";
$svn_trash_loc = "/srv/svn/trash";

Now if you have smtp server, you need to specify it in order for email notifications to function, which is a pretty nice feature in svnmanger. To intall smtp server just for the sake of experiment, you can just type ‘sudo apt-get install postfix’ and leave it with no configuration option. You can reconfigure it later with ‘sudo dpkg-reconfigure postfix’.


$smtp_server = "yoursmatpserverurl";

Next, database configuration, replace ‘yourpassword’ with password you made for svnmanager user:


$dsn = "mysqli://svnmanager:yourpassword@localhost/svnmanager";

Now save the file and restart Apache:


sudo /etc/init.d/apache2 restart

Go to http://localhost/svnmanager/ and you should see the message that the tables have been created. Reload the page and login with ‘admin’ ‘admin’, which we left untouched in the configuration file. Don’t worry, once you login and create admin user, config credentials will not work. Go to create your new user, set him as admin and type ‘admin’ in the lowest ‘password’ box, which is your current default password.

You are now set with SVNManager, which, I believe, significantly helps to manage multiple users and repositories.

Phew, took me forever to write this post as I was installing svn and svnmanager at the same time. Please let me know how it works for you. 🙂

Update: once you create a repository, try to access it in browser at http://localhost/svn/your_repository_name/ . If it shows 500 Internal Server Error, you may have to go back and edit /etc/apache2/mods-available/dav_svn.conf and change the line AuthUserFile to:

AuthUserFile /srv/svn/passwdfile

since the file htpasswd may not exist and cause this error to happen. Just checked my apache logs and this was the problem.

 

Another update: I did a postfix install on Ubuntu to send mail and updates to repositories to the needed users (handy feature). However, I had problems with svnmanager sending the mail. I checked my /var/log/mail.log and was getting:

Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: connect from localhost[127.0.0.1]
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: warning: Illegal address syntax from localhost[127.0.0.1] in MAIL command: 
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: lost connection after RSET from localhost[127.0.0.1]
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: disconnect from localhost[127.0.0.1]

The problem seemed to be that my hostname was an ip address, which needs to be in square brackets like svnmanager@[192.168.1.5]. Then I edited the mail functionality:

/var/www/svnmanager/svnmanager/UserModule$ sudo gedit InvitePage.php

where you can edit $mail->From = “svnmanager@[$servername]”; by adding those square brackets. Also, you can edit the $message if needed.
Also, may need to edit InviteManagePage.php in the same folder to suit your needs.

How to install apache, php, mysql and phpmyadmin in Ubuntu

Installing LAMP (Linux, Apache, Mysql, Php) in Ubuntu is pretty easy. Follow the following steps.

 

Open the terminal window and type:


sudo apt-get install apache2

This would install apache, which you could test by typing http://localhost/ in the browser. It will give you a successful message if it works.


sudo apt-get install php5 libapache2-mod-php5

This would install the latest stable version of php5 and apache mod. Now lets create a sample php file to see if it works:


sudo gedit /var/www/phpinfo.php

Once the new gedit window opens, type:


<?php phpinfo(); ?>

Save the file and restart apache for php to kick in:


sudo /etc/init.d/apache2 restart

Now go to http://localhost/phpinfo.php in the browser and it should show all the php settings.

We still need mysql, these commands will install it:


sudo apt-get install mysql-server

Next, we need apache mode, php5-mysql and phpmyadmin (if you want, it gets pretty handy):


sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

Next, enable mysql in for php by editing php.ini file:


sudo gedit /etc/php5/apache2/php.ini

and uncomment the line


;extension=msql.so

by removing ‘;’ symbol in the beginning. Save the file and restart apache again:


sudo /etc/init.d/apache2 restart

Now navigate to http://localhost/phpmyadmin in your browser to start setting up the databases.

That’s it.