Working with subversion – II

In previous article, I discuss some basic functions of svn. Now i will discuss some more handful features for svn.

But first one disclaimer I will only show some basic example for svn commands. They are very powerful and can be used with variety of parameter to achieve required results.

First sometimes we need to know about our svn setup. So svn info comes as handy here.

$ svn info
URL: https://svn.yourdomain.com/project123/branches/dev
Repository Root: https://svn.yourdomain.com
Repository UUID: 3aaa9e22-3660-1222-1111-ccca444822
Revision: 10
Node Kind: directory
Schedule: normal
Last Changed Author: User1
Last Changed Rev: 10
Last Changed Date: 2013-03-13 01:23:12 +0530 (Wed, 13 Mar 2013)

As you see it gives information like SVN url total revision last commited revision info etc.
Some times we will need to analyze the changes log. For that svn log command is very handful.
Syntax : svn log <File Path>

$ svn log test.php
------------------------------------------------------------------------
r2 | user2 | 2013-03-13 01:23:12 +0530 (Wed, 13 Mar 2013) | 2 lines
some changes
------------------------------------------------------------------------
r1 | user1 | 2013-03-13 01:14:14 +0530 (Wed, 13 Mar 2013) | 1 line
First code commit

This is helpful to check which user commited which version. You can also track down the previous version file contents through svn cat command
Ex. for check test.php for version 123

Syntax : svn cat -r<revision> <File Path>

Example

$ svn cat -r123 test.php

For save into file to analyze, use bash stdout like that

$ svn cat -r123 test.php > test-prev.php

One more command is very much used for track down changes between versions and that is svn  diff

Syntax : svn diff <File Path>

Example

$ svn diff test.php

Above command returns the difference between latest commited version and uncommited changes for test.php. You also can check difference from any particular revision by pass revision.

Syntax : svn diff -r<revision> <File Path>

Example for Changes in test.php after version 4.

$ svn diff -r4 test.php

Their are times when you need structure without svn footprints (folders/files related to svn ) Example to upload somewhere. You need svn export command.

Syntax : svn export <Folder Path to export structure >

Example

$ svn export /home/user/backups/

It will create project123 folder into /home/user/backups/. Remember it will create folder, you should not create folder at that path with same name.

I hope these cheat sheet for svn is usable for readers

Working with subversion – I

Their are many version control software available in market. Subversion/svn can be said market leader atleast for centralized systems. Today I can discuss some most used svn client commands for better project handling.

First you need to install subversion, So fire apt-get command on your shell window.

$ apt-get install subversion
Now subversion is installed on your system.

First command you need is cloning the repository into your local system. So you need to take svn checkout for that repository.

Ex.
$ svn checkout https://svn.yourdomain.com/project123/branches/dev

you can also use short word co instead of checkout.

After checkout we need some work. So let create a file test.php and put some code into it. Now if we analyze through following command we see output like this

$ svn status
? test.php

? mark says that it is still not part of your svn repository. You need to add it by
$ svn add test.php

You can use bash expression like test.* or folder/*php or similar to add multiple files/folder into svn.

now if you use svn status, output is different then previous

$ svn status
A test.php

This changes is local till now, And we need to commit the changes on server.

$ svn commit test.php -m 'ADD MESSAGE'

If you skip message part through line a default shell editor (like nano/vim) opened to fill message, You entered and save/exit through editor Then file is commited as previous command

$ svn commit test.php

You can also remove the any file in svn by using svn delete command. It works on local copy like svn add does and requires svn commit after it to done actually on server.

$ svn delete test.php
$ svn commit test.php -m 'DELETE MESSAGE'

Now Let if you added a file, remove a file or make changes in any of file, But not commited that file on server. You can revert your changes using revert command.

$ svn revert test.php

Afte verify on svn status you will found that,
This command removed the A flag and Add ? on previously svn added file
This command removed the D flag on previously svn deleted file
This command removed the U flag on previously updated file

NOTE : In any case commited changes can not be reverted through revert command.

For take latest changes from server, we need update command. This is little tricky as It will involve merge your changes with updates comes from server. And most challenging part of svn is to take care of it.

$ svn update
A test.php
D test1.php
U test2.php
G test3.php
C test4.php

These are most common updates return from server.

  • A denotes any newly added file on server added to your local structure.
  • D denotes any any file is deleted on your local structure as that file is rmeoved on svn serve too .
  • U denotes simple update on any file when you have not any local changes.
  • G denotes simple update on any file when you have any local changes but not on same line.
  • C denotes simple update on any file when you have any local changes on same line.

There are chances when update comes on file where you have any local changes on same line. Then their would be a prompt for conflict management with options p – postpone, df – diff, mc – mine-conflict, tc – their conflict. More

  • df option show the diff of both version.
  • mc option merge updations with the case that in case of same line conflict, local changes will be taken.
  • tc option merge updations with the case that in case of same line conflict, remote changes will be taken.
  • p option merge both version with conflict lines/part will be shown as <<< >>> block. That need to resolved first to commit. It also create some more files like test.php.mine, test.php.r101, test.php.r104. Where test.php.mine is local file before potpone merging. test.php.r104 or test.php.r<remote version> file having remote changes. test.php.r101 or test.php.r<remote previous version> file having previous remote commited version  changes.

After using postpone options and creating required changes, You need to resove conflict by

$ svn resolve test.php

There are two options available but not shown in  prompt.

  • mf option discard remote file changes and take local file as verify version.
  • tf option discard local file changes file and take remote file as verify version.

NOTE 1 : You need to commit changes in case of svn update file status G and C.
NOTE 2 : You may need to enter svn username/password in case of svn checkout/update/commit

That all for this article, We will discuss some more interesting features of svn in next article.

Basic Ejabberd install/setup on ubuntu (External Script Authentication)

In first article, I discussed the installation and normal chat with users registered internally. Now i am going to discuss the external authentication through a php script.

If you want to authenticate users via your database. their are two alternatives.
1. Using odbc, It have one restriction as its internal database have and that is password must be stored plain. (Latest version may not have this restriction.)
2. Using external authentication script. In this way you can authenticate user via a custom script. Here one good php script can be found there. https://github.com/deceze/ejabberd-extauth-PHP. Now download an extract in some location of your system (not necesarily on apache document root as it will working as cli script ).

Now first create a php script in same folder. I name it auth.php. This file should have similar code suggested at github page. I am updating it using some real query.



#!/usr/bin/php
require 'ejabberd_external_auth.php';
class Auth extends EjabberdExternalAuth {
    protected function authenticate($user, $server, $password) {
        $stmt = $this->db()->prepare("SELECT user_id FROM user WHERE username = ? AND password = ? ");
        $stmt->execute(array($user, password));
        if($stmt->rowCount() >= 0 )
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    protected function exists($user, $server) {
        $stmt = $this->db()->prepare("SELECT user_id FROM user WHERE username = ? ");
        $stmt->execute(array($user));
        if($stmt->rowCount() >= 0 )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
$pdo = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'user', 'password');
new Auth($pdo, 'auth.log');

I skipped $server argument in query check as If you need only users for one chat server. If you need to handle multiple servers then you may need to change code to reflect server too in query.

Now comment internal auth_method by

%%{auth_method, internal}.

And uncomment, change the line

{auth_method, external}.
{extauth_program, "/path/to/auth.php"}.

gave executing permission to auth.php by chmod 0755 auth.php.

NOTE – As this script executed by ejabberd user created at time of ejabberd installation. So this script need execute permission for ejabberd. You may add ejabberd to your user’s group and gave group to execute permission or gave other to execute permission. In both case it is advisable to check execute file after login through other user.

Add chat users in your user table. You will also need admin user to add into your DB with same password to run admin console.

Now restart ejabberd. and verify by adding user at you jabber client. if it going failed. Then verify log file var/log/ejabberd.log. If file have error to not connecting. check php script again for any error.

Ejabberd default enabled MUC (multi user chat or several other modules ), So you can verify/use also this functionality too.

That’s all for this article, In next article I will discuss message logging.

Basic Ejabberd install/setup on ubuntu

In social web appliactions, Jabber chat comes as popular choice for implementing self chat gateway/servers. While there are several chat server are available in market like ejabberd, jabberd2, openfire.
Ejabberd is chat server built in erlang. It provide various recommended features by core/plugins.

Now I am going to give some information for setup ejabberd chat server onto Ubuntu 12.04.

First you need to install ejabberd package. There are two ways.
1. Through ubunty repository. While this option require less work, But you may not get latest package for ejabberd.
2. Download ejabberd package and compile it. This option require more work, But you can get latest package havig more features.

We going through First easy approach.
Here we install ejabberd via

sudo apt-get install ejabberd ejabberd-tools

After installation completion, we will doing some intial setup and configuration.
We need to configure our first chat domain. Here we have config file names ejabberd.cfg at /etc/ejabberd folder.
Open it into your editor, and go for line look like below.

{hosts, ["localhost"]}.

Then change it to add your domain/ip-address as Chat server host.

{hosts, ["localhost","yourhost.com"]}.

Also setup your admin user via change config.

{acl, admin, {user, "", "localhost"}}.

to

{acl, admin, {user, "administrator", "localhost"}}.

Where administrator is admin-name chosen by you. (Ofcourse you can choose any name as admin.)

After save you should also register your admin via command run on shell.


ejabberdctl register administrator localhost password

Now you should restart ejabberd by executing commands

sudo /etc/init.d/ejabberd restart

Open Admin Console via the url – http;//localhost:5280/admin. It ask you the enter admin credentials. enter administrator name and its password, setup via ejabberctl.
Here you can add users via going to virtual hosts -> localhost[yourhost.com] ->  Users.

After register users at here you can start chat by your jabber client example pidgin or spark.

Ejabberd default using it internal database called mnesia to store all kind of information like users, room, logs etc.

In second article of series, I will discuss the external authentication and logging.

Tata Photon on Ubunu

Well I using Tata plug2surf for my laptop since 2 years. First in mandriva 2007, 2008 and 2009 in my desktop. When I have a laptop then I installed ubuntu jaunty on this and configure tata plug2surf. For Both distribution plug2surf work fine. however it is too slow comparison to new broadband plans in market. But for few reasons I stayed with it till now.

When Tata launch the Photon with speed in Mbs. Its my time to check it. For my goodness One of my friend purchase the stick and installed on his vista machine. But when He tried on his fedora things not going smoother. Then he want assist on this matter. I tried with plug2surf way, But it not worked. Then I go for further assistement first on google then on ILUGD (Indian linux group delhi), And after some wait I got solution which I tried on my Ubuntu.

Now i am going to give the description how I set it all (I am very thankful to Mr. Varad gupta which assist me on ilugd mailing ).

First check whether your system have following package or not.

Modprobe, depmod, modeswitch.

On Ubuntu jaunty first two package is default installed while I have to download and installed third package.

There are a big reason to install this. One of my friend tell me about difference between 2 of Tata’s products plug2surf and photon. Plugsurf default detected as USB modem in linux So there is no need for so much steps for nstall modem. While Photon is not detected as modem, So first we need to taken this step. First There should be modeswitch-usb package should be installed on your linux system. I get deb package from

http://packages.ubuntu.com/karmic/i386/usb-modeswitch/download

i) First, check  data card vendor and product by lsusb command.

@@ Output look like a below lines and first high light word is vendor
and second is product.
# lsusb
Bus 002 Device 002: ID eb1a:5060 eMPIA Technology, Inc.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 148f:2573 Ralink Technology, Corp. RT2501USB Wireless Adapter
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 003 Device 003: ID 1b7d:0700

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

@@
After plugin the device I found one extra entry (second last row in above output)
ii) Now, load usbserial module by the help of below modprobe and depmod
command.

@@ Again replace vendor and product with your vendor and product,,
# sudo modprobe usbserial vendor=0x1b7d product=0x0700
# sudo depmod -a

iii) Now change device mode to USB by usb_modeswitch command

# sudo usb_modeswitch -v 0x1b7d -p 0x0700 -d 1
# sudo usb_modeswitch -v 0x1b7d -p 0x0700 -H 1

iv) Check usb device location by command

# sudo wvdialconf /etc/wvdial.conf

I get ttyACM1 detected as USB device,

Edit, dailer configuration, You only have to change Username and

Password parameters. Replace first XXXXXXXXXX with username and second XXXXXXXXXX with your passowrd ( it also may be same as Username ).
@@
# vim /etc/wvdial.conf
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Stupid Mode = 1
Modem Type = USB Modem
ISDN = 0
Phone = #777
New PPPD = yes
Modem = /dev/ttyACM1
Username = XXXXXXXXXX
Password = XXXXXXXXXX
@@
v) Finally, start dial,,,,
# sudo wvdial

Note : – Because most commands require root user level permission, So i used sudo in commands, You can choose your options depend on your distribution.

Alas ! virtualbox OSE not have USB

I installed virtualbox OSE on my ubuntu zaunty, and then setup two machines fedora & pcbsd. Now yesterday I checked that there are no usb detected in my VM. I yahooed (:)) the net for usb connect and found that there are no support for usb in OSE edition and you have to install non OSE edition for that.

Well I were believing that companies making open source software dont restricted their software for some feature (that is problem for non open source software like shareware/freeware for windows), But is seems Sun (or Oracle may be) not interested in providing full fledge open source virtual server solution. They behave same as their counterparts companies making shareware for windows. After all usb support in VM is basic need for any machine for today’s computers.