Sunday, 6 July 2014

Installing Mercurial on Linux

Background

There are many source code versioning tools. Some of them which I have previously used are perforce(p4), git, svn. There are more like cvs, mercurial and the list goes on.... In this post we will see how to install and configure mercurial.

Mercurial is a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface. (official site)

Mercurial is a cross-platform, distributed revision control tool for software developers. It is mainly implemented using the Python programming language, but includes a binary diff implementation written in C. It is supported on MS Windows and Unix-like systems, such as FreeBSD, Mac OS X and Linux. Mercurial is primarily a command line program but graphical user interface extensions are available. All of Mercurial's operations are invoked as arguments to its driver program hg, a reference to the chemical symbol of the element mercury. (More on Wiki)

Installation

You can easily to the installation using a package manager

sudo apt-get install mercurial

But for me it installed a very old version (2.0.2) which is clearly not the way to go. So you can install the latest version as follows - 


sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install -U mercurial

This installed the latest version for me (3.0.1). You can view the version installed by

hg version


Configuration file for the same can be found in  /etc/mercurial/hgrc. You can edit it to suit your requirements.

I have added external diff program called kdiff3 ( How to Install Kdiff3 on Ubuntu  ). So my hgrc file contents are as follows

# system-wide mercurial configuration file
# See hgrc(5) for more information

[merge-tools]
kdiff3.args=--auto -L1 base --L2 local --L3 other $base $local $other -o $output
kdiff3.regkey=Software\KDiff3
kdiff3.regappend=\kdiff3.exe
kdiff3.fixeol=True
kdiff3.gui=True 

Important Links

How to Install Kdiff3 on Ubuntu

Background

Subversion, Git, Mercurial and others support three-way merges (combining mine, theirs, and the "base" revision) and support graphical tools to resolve conflicts.

Which tool do we use ?  In this post I will show how can we install KDiff3.
 It is an open source cross platform tool.


 

Installation

  1. Download the Kdiff3 tar file from the sourceforge repos, then extract the tar file. The sourceforge link for the Kdiff3 project.
  2. Extract the tar.gz file using tar command

    tar -xzf kdiff3-0.9.98.tar.gz
  3. Make sure you have QT4 installed . If not installed you can install it with following command -

    sudo apt-get install libqt4-dev
  4. After extracting go into the “src-QT4″ directory and compile

    cd kdiff3-0.9.98/src-QT4
    qmake kdiff3.pro
    make
    sudo make install
  5. Now you should be able to launch the program by typing kdiff3 in the console.




Important Links

Saturday, 5 July 2014

Resolving issue with Ubuntu installation getting stuck at VMware tools installation.

Background of the problem

I was installing Ubuntu 12.04 LTS on VMware.
I used the "Easy Mode" option while installation.
When I finish the installation, the VMware automatically tried to install VMware Tools and it was stuck. No graphical interface could be loaded. Restarting the VM and rebooting Ubuntu did not help.

You will get something like following


******************************************************************
******************************************************************
Vmware Easy Install

PLEASE WAIT! VMware Tools is currently being 
installed on your system. Depending on the 
version of Ubuntu you are installing, you may 
log in below and use the system during 
intallation. Otherwise, please wait for the 
graphical environment to launch. Thank you.

******************************************************************
******************************************************************
ubuntu login:_


Some random Screenshot I picked up from the net as I already resolved my issue :) . It looked same as below -



Solution


Follow 3 steps mentioned below

  1. Restore the /etc/issue file:

    Use the command : sudo mv /etc/issue.backup /etc/issue
  2. Restore the /etc/rc.local file:

    Use the command :  sudo mv /etc/rc.local.backup /etc/rc.local
  3. Restore the /etc/init/lightdm.conf file:

    Use the command : sudo mv /opt/vmware-tools-installer/lightdm.conf /etc/init

And then simply reboot your machine. You should see graphical interface coming up now.

But this also leds to another problem. This does not install your vmware tools. On trying you would get the following error.






To fix this delete and re add drives


    1. Power off the virtual machine.
    2. Go to VM > Settings
    3. Select CD/DVD.
    4. Make a note of the current settings for this device, then click Remove.
    5. Click Add.
    6. Select CD/DVD, and click Next.
    7. Select the settings you noted previously (or you can set them later), and click Next > Finish.
    8. Select Floppy.
    9. Make a note of the current settings for this device, then click Remove.
    10. Click Add.
    11. Select Floppy, and click Next.
    12. Select the settings you noted previously (or you can set them later), and click Next > Finish.
    13.Power on the virtual machine and install VMware Tools.

This should install vmware tools.

Note : To install the vmware tools if you get popup saying CD is read only don't worry. Copy the tar.gz file to your home folder. Extract folder contents using tar -xvf filename  and then install it. There is a python script in the extracted folder (ends with extension .py). Simply run it sudo ./filename.py and your vmware tools should get installed.

Friday, 4 July 2014

How to permanently set $PATH on Linux?

Goal

Very basic information that every Linux user needs to know - How to export $PATH . This variable contains all the paths which may have executables that will be recognized throughout the System. For example lets say you installed java. You want to compile a program and so you do javac TestClass.java and you get javac is not a recognized command. One way to resolve this is to do pathtojdk/bin/javac TestClass.java but this is not the best way. You can add path pathtojdk/bin to that $PATH environment variable and then you can access all commands in bin folder from anywhere in your System. So lets see how can we achieve this...

Getting Started...

So lets say I want to add following 3 paths to $PATH env variable
  1. $HOME/mozilla/adt-bundle-linux/sdk/tools
  2. $HOME/mozilla/adt-bundle-linux/sdk/build-tools
  3. $HOME/mozilla/adt-bundle-linux/sdk/platform-tools
You can view your existing $PATH variable by just typing echo $PATH . To add it you can do the following. Execute the following on command line

export PATH=$PATH:$HOME/mozilla/adt-bundle-linux/sdk/tools:$HOME/mozilla/adt-bundle-linux/sdk/build-tools:$HOME/mozilla/adt-bundle-linux/sdk/platform-tools

then again you can check the $PATH variable using echo.



But wait a second. Restart the console and if you notice the exported PATH is gone. Yes it is lasts only for that console session. So lets see how can we export this $PATH permanently.


  1. Edit your ~/.bashrc file and add the export line there.
  2. Save the file.
  3. Lastly execute source ~/.bashrc
Note : source command is basically to make your console aware of the changes that you have made in the file.


and thats it. Those PATHS should be in your $PATH environment variable permanently from there on.

Caution

  • It's often considered a security hole to leave a trailing colon at the end of your bash PATH because it makes it so that bash looks in the current directory if it can't find the executable it's looking for.  
  • Consider the scenario when you unpack a tarball, then cd to the directory you unpacked it in, then run ls---and then realize that the tarball had a malicious program called ls in it.
  • There can be other, more nasty versions. For instance, creating a malicious script called sl and waiting for someone to mistype ls.   

Related Links

Tuesday, 1 July 2014

Getting Started with MongoDB

Introduction

From Wiki

MongoDB (from "humongous") is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster. Released under a combination of the GNU Affero General Public License and the Apache License, MongoDB is free and open-source software.


Getting Started

  1. Download MongoDB from their website and install it. You have installer file for windows or zip file. Either way you should get MongoDB 2.6 Standard  folder installed. My folder location is C:\Program Files\MongoDB 2.6 Standard. You can find a bin file inside this folder. Add it to the %PATH% environment variable (windows) or export it by adding in .bashrc file(Linux).
  2. Next open command prompt and run MongoDB server. To do so execute command

    mongod --dbpath C:\Users\athakur\Softwares\MongoDB

    Replace the path after --dbpath with your path. It basically says where your db files will be stored. If you do not provide db path your server will not start and will show that dbpath was missing.


    After starting the server with --dbpath


    You may be asked to allow network access to mongo db. Provide the required access.

  3. Next start the client by typing

    mongoThat should open the Mongo shell.


    By default, mongo looks for a database server listening on port 27017 on the localhost interface. To connect to a server on a different port or interface, use the --port and --host options.
  4. Lets create a new database. Type the following command

    use mydb

    and then type

    db

    This should show mydb database. Now try doing

    show dbs

    Nothing? Surprised? Don't be. It is the way Mongo DB behaves. MongoDB will not permanently create a database until you insert data into that database.

    Note :
    Unlike MySQL database you do not create tables and then insert data. Infact there is no relational model here. You simply switch db using use dbName syntax and add data. When you actually add the data the database is created.

  5. Lets go ahead and insert some data in our database. First create documents doc1 and doc2 using

    doc1 = {name : "Aniket"}
    doc2 = {org : "openSourceForGeeks"}


    Then add these documents to the collection (lets call it testDataCollection) database using

    db.testDataCollection.insert( doc1 )
    db.testDataCollection.insert( doc2 )


        When you insert the first document, the mongod will create both the mydb database and the testDataCollection collection.

    You can view your collections by

    show collections

    Confirm that your testDataCollection collection is created.

    The mongo shell will return the list of the collections in the current (i.e. mydb) database. At this point, the only collection is testDataCollection . All mongod databases also have a system.indexes collection.

    Also confirm the database is created ( by show dbs).

  6. Data Stored in MongoDB is essentially JSON. If you wish to see the data in the collection you can use command

    db.testDataCollection.find()

  7. That;s all for basics of mongo db. We say how to create database, collections and insert data in it. We also saw how can we retrieve the data.


Important commands

  1. db - shows current db in use
  2. help - show help
  3. cls - clear screen
  4. exit - exit Mongo shell
  5. show dbs - Show list of databases
  6. use mydb - use some other database
  7. show collections - Show all collection for the db. 

Important Links

t> UA-39527780-1 back to top