Friday 16 December 2011

Simple RPM creation

To create a rpm the following directory structure is needed,

SRPMS : This directory contains the source code of the application in archive format like "test.tar.gz "

BUILD : The source code is extracted and built here

RPMS   : The final rpm's are placed here

SPECS  : The rpm spec files are placed here, it is the source code to build a rpm I've created a simple rpm which just places a file inside a directory, so i don't use "SRPMS " directory as my file is placed directly inside the "BUILD" directory. Below is the spec file,

[madhu@localhost rpmbuild]$ cat SPECS/madhu-test.spec
%define _topdir /home/madhu/rpmbuild     #names starting with % signs are macros,they are like variables define it  and use it anywhere inside the spec file.

%define _tmppath /home/madhu/rpmbuild/tmp  #define the tmp path this is temporary location where the files will be installed during rpmbuild

%define packager madhusudhanan     #define the packager name with email to contact in-case of support

Name: madhu-test #name of the rpm

Version: 1.0 #version number

Release: 1 #release number,basically we need to find a way to increment it automatically for every build
Summary: test file installation #summary about the package
Source: Hello-world #name of the source file
BuildArch: noarch #mention the architecture for which it is built, noarch is architecture independent, if this variable is not defined the rpm will be created for the arch on which it is built
Group: Applications #this rpm belongs to applications group
License: GPL #define the license of the software
BuildRoot: %{_tmppath}/%{name}-buildroot #BuildRoot is the temporary directory used to compile and install the files
%description
Install the test file to a custom location
%install
rm -rf $RPM_BUILD_ROOT #RPM_BUILD_ROOT is a kind of alias to BuildRoot and i am cleaning the temporary directory
install -d $RPM_BUILD_ROOT/usr/local/madhu-test #this command creates the directory if it doesn't exist
install Hello-world $RPM_BUILD_ROOT/usr/local/madhu-test #copy the file "Hello-world" to the location "/home/madhu/rpmbuild/tmp/madhu-test"
%files #mention the files which needs to be included in the rpm in this section
/usr/local/madhu-test/Hello-world #the file along with the path is picked from the temporary directory

[madhu@localhost rpmbuild]$ rpmbuild -bb SPECS/madhu-test.spec #-bb option is to build binary package

[madhu@localhost rpmbuild SPECS]$ ls ../RPMS/noarch/

madhu-test-1.0-1.noarch.rpm

One more thing i was looking for is to use environment variable in the spec file, and below does satisfy the need.

In the spec file, mention the below line

%define workspace  #workspace is the macro for which i will pass value in the command line

run the below command for building the rpm

export WORKSPACE =  /home/madhu/rpmbuild

rpmbuild --define="workspace $WORKSPACE" -bb madhu-test.spec

$WORKSPACE is the environment variable.

This way I've generic spec file and the values can be passed in the command line rather having multiple spec file for the same rpm. One use case is to have multiple Jenkins jobs for building trunk, branches.

For detailed reference see RPM-GUIDE

Monday 5 December 2011

How to setup a user to login as another user without giving password & root privileges

To login as another user we either need to have root access or need to know his password, but in my case  i don't have both, so i searched for how to set up a non root user to login as another user without knowing their password and below setup solves the purpose,

[madhu@localhost ~]$ su - user1
Password:
su: incorrect password

Ah! i entered my password but su expects user1  password  which i am not aware of, ok let me try another way,
[madhu@localhost ~]$ sudo su - user1
Password:
Sorry, user user1 is not allowed to execute '/bin/su - user1' as root on localhost.

Ah, i don't have root access

Here's is the setup, add the below entry in /etc/sudoers file, obviously you need root access to edit this file

madhu ALL=(user1) ALL

# user madhu can run any command in any terminal as user1

[madhu@localhost ~]$ sudo -u user1 -i     ##execute the command -i (login shell) as user1
Password:     #enter password of user "madhu"
-bash-3.2$ whoami
user1

That's it now you can allow access to other users to login in to your account without revealing the password.

Friday 2 September 2011

Useful commands

Below command ignores the .svn directory and searches the text in all the other directories and files,

grep "google" * -rn |grep -v .svn

Solaris doesn't support recursive grep, so i found the below command from google to be useful,

find . |xargs grep 'recursive'

To find the list of files changed in specific revision in Subversion

svn log -r --verbose REVNO

To find the list of files changed between two revisions in Subversion

svn diff -r 26767:26768 --summarize

List the files installed by a solaris package

pkgchk  -l  <> |grep Pathname

Find the date and time the rpm was modified

sh-3.2$  rpm -qa --queryformat '%{name}-%{version}-%{release} %{installtime:date}\n' |grep libgcc
libgcc-4.1.2-42.el5 Tue 15 Sep 2009 05:45:29 PM GMT


Revert the range of revisions from svn repository

cd working-copy

svn merge -r28431:28245  .

--- Reverse-merging r28431 through r28246

The above command will revert the changes made from revision 28426 to 28431  in your working copy . You need to Commit to update your changes to the server(repository) .

Match characters between two strings

lookbehind (?<=) 

look ahead (?=)
I need to find the Name of a person from the below statement,

Hi, Madhu , How are you

(?<=,)(.*)(?=,) - This will match Madhu in the statement as the pattern looks behind "," and looks ahead ","

Saturday 30 July 2011

Must Features for Collaborative Tools



In my opinion every collaborative tool should have two features in it one is IM instant messaging application  in it or the extrernal chat applications like skype or Google Chat intergrated in it, the second one is instant updates notification from the tool, the user need not refresh the page every time to receive update.  These features may seems trivial but this will add more value for collaboration.  For example you have a project where members of the project are  different team like developers, quality assurance , support, operations, marketing. So in order to communicate with the members we usually update the Artifact/tickets in the Collaboration tool and wait for the reply, but at the other end the member will be notified only if he checks the mail frequently, so its not just the tool makes the collaboration possible it needs the help of other tool i.e mail cients make it work. Instead the tool can have a Instant update notification feature, whenever there is a update for the user, he will be notified with the popup in the tool itself. This eliminates the mail client from the scene but of course we need mail clients for other purposes. But think about a critical project you work where productivity is very important and some studies say that checking mails frequently reduces productivity, so by Instant update notification approach we can overcome this problem as the users gets notification only if he has updates. But there is another problem what if the issue is vey urgent and you need to discuss with the other members of the project immedidately but the members are working from the remote location and is impossible to meet physically, so normally we use another tool called Instant messaging/VOPI based applications to meet with the team, here comes another tool for collaboration. Instead of using a third patry software seperately, we can either develop a chat featurein the tool itself or integrate the external chat application with the tool. So that members of the project can easily communicate using text messaging or voice chat and its also easy to find members of  the project by just a single click on the user who are online i.e signed in user. It would be more effectve if there is a screen/desktop sharing option where the members of the project can share their screens/desktops via the tool and other members can see/debug the problem from the remote. But i think this is difficult to implement, if implemented this will make the Real collaboration of teams.

Friday 10 June 2011

Could not load definitions from resource org/tigris/subversion/svnant/svnantlib.xml. It could not be found

I got in to this problem when i was building an application using ant. I googled for this error and found several solutions/reasons for this problem, but none of it solved the problem for me. Though i was having svnant.jar in the custom ant directory and i have exported ANT_HOME properly, i was getting this error. Then on further debugging i found that the system already had ant installed in it and it's path is taken as the ANT_HOME, exporting the ANT_HOME manually in the shell didn't override it. Then found there is already a FAQ describing this "I installed Ant 1.6.x and now get java.lang.InstantiationException: org.apache.tools.ant.Main"  in http://ant.apache.org/faq.html. Then i used ant --noconfig to stop sourcing of the ant.conf file. This solved the problem. Though the solution is simple, it was difficult to find the cause of the problem, as i used the same custom ant and build scripts in three boxes, whereas in other two boxes it worked fine and failing in one box was a surprise.

Monday 16 May 2011

How to Restore /usr/share/application directory?

Today by mistake i deleted the files inside /usr/share/applications directory, as a result my Fedora 13 application launcher got wiped off. I was thinking
of formating and reinstalling the OS again, but that's going to be a costly operation for me. So did a bit of searching and found the below solution and it worked well.

`rpm -Va | grep missing`  command will give the list of missing files from the packages installed in your Operating System.

missing     /usr/share/applications/evince.desktop
missing     /usr/share/applications/mozilla-thunderbird.desktop
missing     /usr/share/applications/rpmfusion-gnome-mplayer.desktop
missing     /usr/share/applications/vlc.desktop
missing     /usr/share/applications/openoffice.org-calc.desktop
missing     /usr/share/applications/fedora-gnash.desktop
missing     /usr/share/applications/system-config-users.desktop
missing     /usr/share/applications/openoffice.org-base.desktop
missing     /usr/share/mozilla/extensions/

From this list i took the files which has /usr/share/application in its path and then reinstalled them using yum reinstall. This solved the problem.

Tuesday 26 April 2011

Script to find if a number is prime or not

Below script will find if the number entered is prime or not

while True:
    try:
        input = int(input("Enter a number: "))
        break
    except Exception, e:
        print e

a = []
if input == 0:
    print input, "is  not a valid number"
elif input == 1:
    print input, "is not a prime number"
else:
    for i in range(input):
        if i == 0:
            pass
        else:
            a.append(input % i)
    if a.count(0) > 1:
        print input, "is not a prime number"
    else:
        print input, "is a prime number"

Output:
[madhu@localhost tmp]$ python prime.py
Enter a number: 2
2 is a prime number
[madhu@localhost tmp]$ python prime.py
Enter a number: 10
10 is not a prime number

pallindrome script

I wrote the below python script to find if the string is pallindrome or not.

while True:
try:
input_string = str(input("Enter a string: "))
if input_string.isdigit():
pass
else:
break
except Exception, e:
print e
a = []
b = []
for i in input_string:
a.append(i)
a.reverse()

for i in input_string:
b.append(i)
if a == b:
print input_string, "is a pallindrome"
else:
print input_string, "is not a pallindrome"

Output:
[madhu@localhost tmp]$ python pallindrome.py
Enter a string: "elle"
elle is a pallindrome
[madhu@localhost tmp]$ python pallindrome.py
Enter a string: "malayalam"
malayalam is a pallindrome
[madhu@localhost tmp]$ python pallindrome.py
Enter a string: "pallindrome"
pallindrome is not a pallindrome

Tuesday 15 March 2011

20thingsilearned

Recently i read this article http://www.20thingsilearned.com. At the first glance the design of the web page attracted me its built in Html 5 and it is just like reading a book, the pages can be flipped, folded. I absolutely knew nothing about how internet works and this article gives a gist about it and speaks about the importance of using the updated web browsers to enter in to the new web world filled with amazing web applications which can connect to your loved ones and colloborate with your colleagues irrespective of the location. It also discusses the risk of using outdated web browsers which are victims to malware, phishing and how a simple concentration and attention from our side can avoid disaster, below are the check list.

1. Use https site for online transactions.

2. Check the extended validation certificate of the web site to check the credibility of the site.

3. Check the URL if it is valid and it doesn't have any weird domain names.

They also talk about the future of web and how cloud computing helps us to protect the data even if the truck rolls in our laptop and the innovations going in the web technologies like compressing the images by 39% by using a new image format WebP and fast javascript engines to process the complex java scripts faster and DNS pre-resolution where the links in the web page are already coverted in to the IP address,so the moment you click the link the page loads. They also explain the difference between security and privacy. The privacy settings can be personalized using the modern web browsers. There are lot more explained in this book,it is a good to read webpage.

Sunday 20 February 2011

vim Editor's split windows is cool

Most of the time when i want to use existing file as reference to creater a new file. I open two sessions and toggle between them to view and edit the contents and this was hectic. But the split window feature in vim is easy to do this task.

Sunday 30 January 2011

Subversion move + Sparse checkout

Recently i was given the task of moving the tags to another location with in the repository. Without much thought i wrote a shell script to do svn move from URL to URL i.e URL -> URL: complete server-side rename.


The script did the part well, but this resulted in spamming the mailbox. As each move is a server side rename which resulted in a commit and the post commit hook will send mail for each commits. Within 15 minutes i made 320 commits. But this was only the 1/4 of the move there were hundreds of tags to be moved. Then one of the subversion developer after seeing the series of commit mails, gave me a suggestion. First he asked to do the move in the working copy i.e WC -> WC: move and schedule for addition (with history)


this will result in a single commit ,but still this had a problem as i need to checkout the whole repository to make this move in the working copy. My repository is huge in size, so this is gonna take more time, but subversion had a solution for this too called sparse checkout. This option allows to checkout/update according to the depth we desire. So i made a svn co --depth empty, this gave me just the empty directories in no time, then i entered the source directory from where the tags needs to be moved, and then got the list of directories to be moved using svn list command and then did a svn update %DIR% --depth empty and then did a svn move of the source directory to the destination directory. I did this using a shell script. In 30 minutes all my directories were moved and scheduled for addition and removal from the source directory. Then i did a commit where all the move was done in a single commit. I wasn't aware that doing a sparse checkout/update and moving the directory will move all of its contents, even though if it's not available in the working copy. That's a good learning i had, hence sharing with you.