Support Wikipedia

Wednesday, March 11, 2009

Setting up SVN repository Hooks : POST-COMMIT

Recently, I tried to setup the svn hook for shooting out emails on a commit. I had to do alot of googling to really get it working. The SVN book doesnt detail the process nor does any blog/wiki/forum out there. May be - the SVN admins are already geeky enough to figure it out I guess.

Anyways, I am posting my experience here so that it might help someone out there who is a newbie to SVN administration. Here we go...



Setting SVN Hooks

1. Go to the repository hooks directory (on the svn box ofcourse)
* cd /var/svn/repoName/hooks
2. Rename the post-commit.tmpl to post-commit (you can find several hook template scripts in the hooks directory under each repository)
* cp post-commit.tmpl post-commit #copy the tmpl into a normal executable
* chmod +x post-commit #Make it executable
3. Download the commit-email.pl from :
* The SVN tools: http://subversion.tigris.org/tools_contrib.html#commit_email_pl
* OR
* wget -o commit-email.pl http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/commit-email.pl.in
#I chose perl script but you can choose ruby or write your own.

4. Install sendmail on the box (I have Centos so I use yum, if you are on Ubuntu then use aptitude)
1. yum search sendmail #do a search for the packages with sendmail
2. yum install sendmail.i386 sendmail-cf.i386 sendmail-doc.i386 #these were the packages for my Centos system. It may vary based on your OS.
3. chkconfig sendmail on #start sendmail on boot.
5. Edit /etc/mail/sendmail.mc and add the following line
* Ft/etc/mail/trusted-users
6. Edit /etc/mail/submit.mc and add the following line
* Ft/etc/mail/trusted-users
7. Generate the sendmail.cf file from sendmail.mc using the m4 command. The m4 usage is simple, you just specify the name of the macro file as the argument, in this case sendmail.mc, and redirect the output, which would normally go to the screen, to the sendmail.cf file with the ">" redirector symbol.
* m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
8. Generate the submit.cf file from submit.mc using the m4 command.
* m4 /etc/mail/submit.mc > /etc/mail/submit.cf
9. Restart sendmail to update the configuration
* service sendmail start #start sendmail now
10. Edit /etc/mail/trusted-users and add the following line (if the apache user is used by apache)
* apache
11. The apache user bydefault is blocked from loggin in or running scripts. So you have to edit the /etc/passwd and delete the /sbin/nologin at the end of the line and add your fav shell like this
* apache:x:48:48:Apache:/var/www:/bin/bash
12. Change the ownership of the following scripts so that they can be executed by apache user & group
* chown apache.apache /var/svn/repoName/hooks/post-commit
* chown apache.apache /var/svn/repoName/hooks/commit-email.pl
13. Edit commit-email.pl and add the following line
* var/svn/repoName/hooks/commit-email.pl "$REPOS" "$REV" -h yourhost.com --from svn@yourhost.com -l /var/svn/logs/mailLog.log -r devteam@yourhost.com --summary --diff n devteam@yourhost.com
14. This is it. You are set.


Resources:
Sendmail Reference
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch21_:_Configuring_Linux_Mail_Servers

Trusted-Users :
http://www.linuxquestions.org/questions/slackware-14/sendmail-trusted-user-617397/

Commit Email
http://subversion.tigris.org/tools_contrib.html#commit_email_pl
http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/commit-email.pl.in
Support Wikipedia Support Wikipedia Support Wikipedia Support Wikipedia Support Wikipedia Support Wikipedia