Thursday, January 18, 2007

Handling archive formats in Linux



In Linux , archives and installation packages come in different formats.During installation steps, often handling these files is a tedious process if we dont know the archive formats.Listed here are some of the common archive formats and how to use them in linux for various operations.



ZIP



ZIP files generally use the file extensions ".zip" or ".ZIP" and the MIME media type application/zip.The specification for ZIP indicates that files can be stored either



uncompressed or using a variety of compression algorithms. However, in practice, ZIP is almost always used with Katz's DEFLATE algorithm, except when files being added



are already compressed or are resistant to compression.



ZIP supports a simple password-based symmetric encryption system which is known to be seriously flawed.The most common archive format is the ZIP (*.zip).This is



handled using the program 'zip'.



zip archive.zip file # Create a zip with name archive.zip from file

unzip archive.zip # Extract contents from archivename

man zip # See other options of zip



Also refer :

http://en.wikipedia.org/wiki/ZIP_file_format



TAR



In computing, the tar (file) format (derived from tape archive) is a type of archive bitstream or file format. The format is traditionally produced by the Unix command, tar, and



was standardized by POSIX.1-1998 and later POSIX.1-2001. Initially used for tape backup, it is now commonly used to collate collections of files into one larger file, for



distribution or archiving, while preserving file system information such as user and group permissions, dates, and directory structures.



A tar file (somefile.tar), when subsequently compressed using a zip utility such as gzip or bzip, produces a zipped tar file with a filename extension (e.g.: somefile.tar.gz,



somefile.tar.bz2). A .tar file containing GNU or other program source code is commonly referred to as a tarball, which may be compressed or not.



tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.

tar -tvf archive.tar # List all files in archive.tar verbosely.

tar -xf archive.tar # Extract all files from archive.tar.

man tar # See options



Some compressed forms with TAR and how to extract



* tar file:

.tar

* gzipped tar file:

.tar.gz - gunzip | tar xvf

.tgz - same as above

.tar.gzip - gunzip | tar xvf

.tar.gz.gpg (an encrypted gzipped tar – should be decrypted with GPG)

.war (Konqueror Web ARchive file)

* bzipped tar file:

.tar.bz2 - bunzip2 | tar xvf

.tar.bzip2 - same as above

.tbz2

.tbz

* tar file compressed with compress

.tar.Z - uncompress | tar xvf

.taz - same as above or zcat *.Z | tar -xvf -





refer :

http://en.wikipedia.org/wiki/Tar_%28file_format%29



GZIP



gzip is short for GNU zip, a GNU free software file compression program. It was created by Jean-loup Gailly and Mark Adler. Version 0.1 was first publicly released on



October 31, 1992. Version 1.0 followed in February 1993.gzip File extensions: .gz, .tgz, .tar.gz



The corresponding program for uncompressing gzip'd files is gunzip. Both commands call the same binary; gunzip has the same effect as gzip -d.gunzip takes a list of files



on its command line and replaces each file whose name ends with .gz, -gz, .z, -z, _z or .Z and which begins with the correct magic number with an uncompressed file



without the original extension. gunzip also recognizes the special extensions .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively.When compressing, gzip uses



the .tgz extension if necessary instead of truncating a file with a .tar extension.



gzip file # Create a gzipped archive from file

gunzip archive.gz # Extract files from archive



refer:

http://en.wikipedia.org/wiki/Gzip



BZIP2



bzip2 is a free software/open source data compression algorithm and program developed by Julian Seward.bzip2 compresses most files more effectively than more traditional gzip or ZIP but is slower.File extension: are .bz2, .tar.bz2, .tbz2, .tb2



bzcat archivefile.tar.bz2 | tar -xvf - # to extract from a bzip2-compressed tar-file:



tar -cvf - filenames | bzip2 > archivefile.tar.bz2 # To create a bzip2-compressed tar-file:



tar -xvjf archivefile.tar.bz2 # To deflate in GNU tar



refer:

http://en.wikipedia.org/wiki/Bzip2



For a full list of archive and package formats, refer :

http://en.wikipedia.org/wiki/List_of_archive_formats



Reference : Wikipedia



Thursday, January 11, 2007

Preparation of essentials for Lab sessions of Principles of Programming course at IIITMK





Principles of Programming is a course being offered at IIITM-K in Kerala, India during the 2nd Semester of the 2006-2007 Academic Year.

The aim of this course is to teach students the fundamental concepts underlying in programming. The course uses the Javascript language (no relation to Java) to introduce concepts essential for understanding programming from a perspective that emphasizes computational ideas (recursion, interaction, persistence) rather than grinding through language syntax. In addition, the course introduces concepts using a hands-on approach in which students will build and test client-side applications on a web Browser.

We had to perform the preparation of "Lab programming environment" in the project lab in one of the machines of Mrs.Smitharani a project Associate working under Edugrid and also one of the Associate instructors of the program.



The agenda of the program and requirements as part of it can be had from the below link:

http://www.iiitmk.ac.in:8090/wiki/index.php/Principles_of_Programming_-_ITM_121_AY_2006-2007_Sem2



NOTE :All these steps have been tried out in Linux or Ubuntu machines running in the Project wing.



Review : A close review of the System revealed that:



Installed : Emacs,Firefox v1.4 without addons,

Not installed : Mozlab and Mozrepl with Emacs,upgraded Firefox version,other addons for Browser



Step 1 : Install firefox 2.0 in Linux or upgrade from 1.x version to 2.x version




For that,first ensure that you are root user in the target machine.Take a backup of the profile of currently running firefox version,bookmarks,etc.



  1. Optional: Empty the browser cache, to reduce the amount of data to backup. Go to Tools > Options... (Edit > Preferences... on Linux), select Privacy and click the Clear button next to the Cache item in the list.
  2. Shut down Firefox completely (File > Exit).
  3. Make a copy of your profile folder to, for example, a CD-RW disc or a separate hard disk for backup purposes.
Find and remove the currently installed firefox folder with the executable(Dont remove library files in /usr/lib).Then,do a check to find some distributed optional files with firefox located elsewhere and perform staring firefox using command.



[root@localhost opt]# firefox



If it still starts up,the executable is still within /usr/bin.Use 'which firefox' command to locate and remove



Get newer version from the given link (Ver.2.0).Extract the archive into /opt/ and:



[root@localhost opt]# tar -zxvf firefox-2.0.0.1.tar

[root@localhost opt]# cd firefox

[root@localhost opt]# chmod a+x firefox run-mozilla.sh firefox-bin

[root@localhost opt]# ./firefox



This should fire up the browser if all libraries are working.But it showed the Glib library should be reinstalled.The following error was shown:



[root@localhost opt]# "libstdc++.so.6: libraries not found.Firefox cannot start"



So i googled and found following post."Firefox libraries are not properly upgraded.Perform the following command



[root@localhost opt]# yum install
libstdc++.so.6



You can check the installation by following command



[root@localhost opt]# rpm -qf libstdc++.so.6



and it should return the following line



compat-libstdc++-33-3.2.3-47.fc4 . Now we can start firefox using abovesaid command.



Now we can add a launcher for it from desktop by right-clicking on desktop > Add launcher > give Name as "Firefox browser" > give Command as "/opt/firefox/firefox".



I got an interesting link connected with it which can give you information on the possible risks associated :



http://listvine.com/2006/10/25/9-reasons-not-to-upgrade-to-firefox-20/



Step 2 : Check and intall subversion clients in machines for accessing repositories at Park Center office



I first checked installed instances of subversion in the machine using 'svn' command.It didnt detect anyone.Then,i issued following command as found in linux forum :



[root@localhost ~]# yum install subversion



It was done in 5 minutes.When we issue 'svn' command, we get the following message:



[root@localhost ~]# svn

Type 'svn help' for usage.



Now,we can use all svn-related operations.



Step 3 : Addons to the firefox browser for lab sessions



The following plug-in are need to install in your Firefox 2.0 browser.By clicking Tools > Add-ons in the Firefox 2.0 browser menu , click on the link in the right bottom "Get Extensions" . The browser will open Firefox add-ons page, you can search for the plug-ins in the provided in the bottom of the page. Search each plug-in and install it in your browser, the plug-ins get installed only when you restart the Firefox browser, ie close all the browser windows and reopen.

You can also directly go to the plug-in download pages given below under the subtitle.

You can check the detailed listing on the needed addons here:



http://www.iiitmk.ac.in:8090/wiki/index.php/Lab_Programming_Environment#Add-ons_to_Browser



Step 4 : Setting up Mozlab and Mozrepl for working with Emacs



Check if Emacs is already installed by issuing :



[root@localhost ~]# emacs



If it is not present,try installing it using yum or from its webpage here



MozRepl is a Firefox addon that provides a Javascript Read-Eval-Print Loop that directly interacts with the browser. It has other nice things as well. Here is a explanation of using MozRepl on a Linux notebook running Fedora Core 3.



http://www.iiitmk.ac.in:8090/wiki/index.php/Mozlab_and_MozRepl





Parts of this manual are reproduced from the IIITMK Wiki featuring "Principles of Programming" course

Saturday, January 06, 2007

Version Control with subversion

Introduction

Version control is the art of managing changes to information. It has long been a critical tool for programmers, who typically spend their time making small changes to software and then undoing those changes the next day. But the usefulness of version control software extends far beyond the bounds of the software development world. Anywhere you can find people using computers to manage information that changes often, there is room for version control. And that's where Subversion comes into play.

About Subversion

Subversion is a free/open-source version control system. That is, Subversion manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to your files and directories. This allows you to recover older versions of your data, or examine the history of how your data changed.

Subversion can access its repository across networks, which allows it to be used by people on different computers. At some level, the ability for various people to modify and manage the same set of data from their respective locations fosters collaboration. Progress can occur more quickly without a single conduit through which all modifications must occur. And because the work is versioned, you need not fear that quality is the trade-off for losing that conduit—if some incorrect change is made to the data, just undo that change.

Installing SVN Client

In Linux

The easiest way to get Subversion is to download a binary package built for your operating system. Subversion's website (http://subversion.tigris.org/project_packages.html) often has these packages available for download. The site usually contains graphical installer packages for users of Microsoft operating systems. If you run a Unix-like operating system, you can use your system's native package distribution system (RPMs, DEBs, the ports tree, etc.) to get Subversion.

In Windows

Download Tortoise-svn from the site http://tortoisesvn.net/downloads and install in your windows machine.This can also be downloaded from IIITM-K sagar machine using "user" and "user" as username and password respectively

SVN Main Concepts

Repositories
Working Copies
Import/Checkout

Update/Commit
branch/Tag
Switch/Merge

Preliminaries:

(This is a typical demonstration of SVN usage cycle reproduced from IIITMK Web Techology class)

Login to the file server using ssh (or any other tool on windows). You must have an account on the machine The machine's IP is

192.168.0.3


1. Accessing the svn repository:

Students repo:

svn list svn://godavari.iiitmk.ac.in/users/students/

You will need a password (which will be given to you in the lab)

svn co svn://202.88.239.61/users/students/

Faculty repo:

svn co svn://godavari.iiitmk.ac.in/users/faculty/ (internal) svn co svn://202.88.239.61/users/faculty/ (external)

Staff repo:

svn co scn://godavari.iiitmk.ac.in/users/staff (internal) svn co svn://202.88.239.61/users/staff (external)

2. Creating a local directory


Create a directory on your machine:

 trunk
-- hw0
-- a.txt
-- b.txt
tags
--
 branches
--
 release
--

3. Importing to SVN


svn import test SVN-LOC

4. Checking out a working copy into new location


svn co SVN-LOC/trunk/hw0

5. Remove old local directory


6. Try out svn commands:


   -- status
-- log
-- revisions

7. Modify your working copy


   -- svn status
-- svn mkdir
-- svn add
-- svn rm
-- svn rmdir
-- svn move
-- svn copy


8. Commit your changes to the repository


   -- svn commit

9. Update your working copy


   -- svn update

10. Reverting


   -- svn revert
-- svn co -r version#


11. Troubleshooting


    -- svn cleanup
-- svn --force ...


Try this in Your Machine

Before we import files into the central repository, we need to create the directory structure in the local folder. The following command illustrate this.

    $mkdir /home/user/repos/trunk
$mkdir /home/user/repos/branches
$mkdir /home/user/repos/tags

then check the directory

    $ ls /home/user/repos/

it will print

    branches tags trunk

The above mentioned directory structure in the local machine can be imported to the central repository as shown in the command below

    $ svn import --message ”to the server repository” repos <>

Files from central repository can be exported to client machines using following command.

    $ mkdir ~/work
$ cd ~/work
$ svn checkout svn://server-hostname/path-to-your-svn-space/trunk

In order to check the working copy,

    $ cd ~/work
$ cd trunk
$ ls -al

You should be seeing a directory .svn.

Let us create a directory under trunk, say homeworks;

    $ cd ~/work
$ cd trunk
$ svn mkdir homeworks
$ cd homeworks
$ svn mkdir hw1
$ cd hw1

Let us create a couple of files in hw1 say test.txt and a.txt

    $ touch test.txt
$ touch a.txt

Checking the status of working copy will yeild following results

    $ svn status
? test.txt
? a.txt

The question mark means that the files are not versioned

Now let us make the files versioned by svn

    $ svn add test.txt

If we check the status

    $ svn status
A test.txt
? a.txt

The A test.txt means that the file is scheduled to be added to the repository.

Let us commit the changes made to the local copy to the repository

    $ cd ~/work/trunk
$ svn commit --message "Added homework directories"

It is always recommended to do the commit from the root directory of working copy here (~/work/trunk).
It is a good practice to give a reasonable message during a commit to help the people working with you to understand what happend.

Now to illustrate commit , merge and conflict resolution let us consider small example code shown below. The code mentioned below is contained in a file called TestDemo.java

   public class TestDemo {
public static void main(String args[]){
System.out.println(“Subversion Test”);
}
}


Put the file TestDemo.java ,just created in your trunk directory in the local machine, and to add this file to your central repository use the command

   svn add TestDemo.java

Now you can use the commit to reflect the changes in server.

   svn commit -m=”added a File” TestDemo.java


Now once again commit your trunk directory as mentioned earlier.

Now the file is stored in the trunk folder in the central repository and can be checkout to the local machine's folder. Suppose you checkout your trunk folder and it already contains the file TestDemo.java , if you made any change to this file ie. alter the code , and if you want to see the difference between your local repository and central repository do the following command.

   $ svn diff TestDemo.java

References

1)SVN Online Book - http://svnbook.red-bean.com
2)SUBVERSION Project - http://subversion.tigris.org



The practical command-set explained here are reproduced from Web-Technology classes from IIITMK,Park Center,Trivandrum