2009-01-20

How to Install JDK under Linux







How to Install JDK under Linux




The following instruction shows the steps to install JDK1.5 64bit on CentOS 4/5:



- Get the package


  Download JDK1.5 linux 64bit binary package (jdk-1_5_0_16-linux-amd64.bin) from Sun website.  

- Install


  1. Log in as root;

2. Copy the jdk-1_5_0_16-linux-amd64.bin to /usr/local/lib64;

3. Add execute permit on it and run it to extract:

# chmod +x jdk-1_5_0_16-linux-amd64.bin
# ./jdk-1_5_0_16-linux-amd64.bin

The binary code license is displayed. Enter "yes" to continue.

The JDK files are installed in /usr/local/lib64/jdk1.5.0_16

4. Delete the binary package to release disk space:

# rm jdk-1_5_0_16-linux-amd64.bin

- Set envirenment


  1. Log in as root;

2. Edit /etc/user.bashrc to add following lines:

# JDK path
if [ -d /usr/local/lib64/jdk1.5.0_16 ]
then
export JAVA_HOME=/usr/local/lib64/jdk1.5.0_16
fi

- Test installation


  1. Log in as normal user;

2. Run the following command:
$ java -version

Java version information should be displayed.


2008-12-19

useradd: unable to lock password file






Useradd: unable to lock password file


Problem description:

Under Red Hat Linux release 9, use root to add a user, get error message as below:

    useradd: unable to lock password file


Solution:


Needed to remove a lock file

Under the /etc directory, there are some lock files as:
    group.lock
    gshadow.lock
    passwd.lock
   shadow.lock

or
   .pwck.lock
   .pwd.lock

Remove them.







2008-12-16

How to install vista fonts on CentOS

Microsoft’s new ClearType fonts for Vista are great. The fonts include Constantia, Corbel, Calibri, Cambria, Candara and Consolas.


To install the Vista ClearType fonts in CentOS, you need to install cabextract first. You can use yum to install it:

$ yum install Cabextract

Then, use following script to install the Vista fonts:
( http://plasmasturm.org/code/vistafonts-installer/vistafonts-installer )

#!/bin/sh
# Copyright (c) 2007 Aristotle Pagaltzis
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

set -e

exists() { which "$1" &> /dev/null ; }

if ! [ -d ~/.fonts ] ; then
exec 2>&1
echo 'There is no .fonts directory in your home.'
echo 'Is fontconfig set up for privately installed fonts?'
exit 1
fi

# split up to keep the download command short
DL_HOST=download.microsoft.com
DL_PATH=download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26
ARCHIVE=PowerPointViewer.exe
URL="http://$DL_HOST/$DL_PATH/$ARCHIVE"

if ! [ -e "$ARCHIVE" ] ; then
if exists curl ; then curl -O "$URL"
elif exists wget ; then wget "$URL"
elif exists fetch ; then fetch "$URL"
fi
fi

TMPDIR=`mktemp -d`
trap 'rm -rf "$TMPDIR"' EXIT INT QUIT TERM

cabextract -L -F ppviewer.cab -d "$TMPDIR" "$ARCHIVE"

cabextract -L -F '*.TT[FC]' -d ~/.fonts "$TMPDIR/ppviewer.cab"

( cd ~/.fonts && mv cambria.ttc cambria.ttf && chmod 600 \
calibri{,b,i,z}.ttf cambria{,b,i,z}.ttf candara{,b,i,z}.ttf \
consola{,b,i,z}.ttf constan{,b,i,z}.ttf corbel{,b,i,z}.ttf )

fc-cache -fv ~/.fonts


Then open up a text editor and copy and paste the script into that file.
Then run the script using:

$ sh vista-fonts-installer.sh

The script downloads the Powerpoint Viewer
installer from microsoft.com, and then extracts the Vista cleartype
fonts using cabextract. These fonts are then installed in the ~/.fonts
directory.

Please remember that the ClearType Vista fonts are not free. You’ll be installing them at your own risk!

2008-11-19

Mono Installation Steps on CentOS

Mono provides the necessary software to develop and run .NET client
and server applications on Linux, Solaris, Mac OS X, Windows, and Unix.

To run the ASP.NET applications with Mono, there are three components of mono we need install:
  • Mono is the core module.
  • XSP is a simple way to get started, a lightweight and simple webserver written in C#.
  • Mod_Mono is an Apache 1.3/2.0/2.2 module that provides ASP.NET support for the web's favorite server.

There are three basic steps of mono installation:
  • Install the mono software;
  • Configure the mono service together with Apache;
  • Restart Apache.

The details of installation are discussed below:


1. Install the mono

The prefered method for installing Mono on RedHat/CentOS is to use yum.

Log onto your server;

Use vi to create a file named mono.repo and save it in /etc/yum.repos.d will allow you to install mono and related packages.

    [mono]
name=Mono for rhel-4-i386 (stable)
baseurl=http://ftp.novell.com/pub/mono/download-stable/rhel-4-i386/
enabled=1
gpgcheck=0

Then, use yum to install mono and xsp package:

    #sudo yum install mono
#sudo yum install xsp
#sudo yum install mod_mono

Note:

Currently, the packed mod_mono is not running smooth on x86-64. So we install it from source, instead of installation by yum.

Download the source code (mod_mono-1.9.tar.bz2) from http://go-mono.com/sources-stable/

Place the download file to /tmp and unpack it to /usr/local (or other directory you like):


    #cd /usr/local
#tar jxvf /tmp/mod_mono-1.9.tar.bz2

Compile the source code:


    #cd /usr/local/mod_mono-1.9
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install

2. Configure the mono together with Apache


To run ASP.NET applications within the Apache, we need apache, the web server, installed. So, we can publish the mono service on web site though Apache.

After install the mono, you can find a default configure file name mod_mono.conf in mono's directory(In this instance, it is /etc/mono/conf.d/mod_mono.conf). mod_mono.conf loads the mod_mono module, associates ASP.NET file extensions with the ASP.NET MIME type and adds index.aspx, Default.aspx, and default.aspx as automatic directory index pages.

To load the mod_mono, add 1 line in the Apache configuration file like this:

    Include /etc/mono/conf.d/mod_mono.conf

Now, we need edit the mod_mono.conf file to meet our special needs. As example, we publish the mono's build in test files, add these lines at the end of mod_mono.conf:

    #This is the mono's examples
Alias /mono_test "/usr/lib/xsp/test"
MonoApplications "/mono_test:/usr/lib/xsp/test"
MonoServerPath "/usr/bin/mod-mono-server2"
<Location /mono_test>
SetHandler mono
</Location>

#This is the controller of mono
<Location /mono>
SetHandler mono-ctrl
Order deny,allow
Deny from all
Allow from 192.168.1.0/24
</Location>

Run the following command to check the configurations:

    #httpd -t

Syntax OK

3. Restart Apache

Restart Apache to start mono web service by the following command:

    #service httpd restart

Stopping httpd: [ OK ]
Starting httpd: [ OK ]

Now, the mono project it is available on web with this address:

    http://localhost/mono_test

If you are new to mono, get start with the The sample of writing code using mono on Linux, and have a look at the examples.


Further information about mono can be found at mono's website: http://www.mono-project.com/Mod_mono




2008-11-17

Examples of Perl : envdump.pl

Examples of Perl Program: envdump.pl



This is simple code to get environment settings.

#!/usr/bin/perl
# envdump.pl
#####################################################
# Get environment settings
foreach $key (keys %ENV) {
print "$key --> $ENV{$key} \n" ;
}

This is CGI, show a html page of all environment settings.

#!/usr/bin/perl
# envdump.pl
# Show a html page of all environment settings
#####################################################
use strict;
use warnings;

print "Content-type: text/html\n\n";

print "<html><head><title>Environment Dumper</title></head><body>";
print "<center><table border=1>";

print "<tr><td>"."Your Operating System is:"."</td><td>";
foreach ($^O) {
print "$_";
}
print "</td></tr>";

foreach (sort keys %ENV) {
print "<tr><td>$_</td><td>$ENV{$_}</td></tr>"
}
print "</table></center>";


print "</body></html>";

2008-11-10

Examples of Perl: use File::Find

Examples of Perl Program: use File::Find


File::Find is used for searching through directory trees doing work
on each file found similar to the Unix find command. Find has two arguments. It accepts a code reference to your own code as the first argument and the directories as the second argument as below: find ( \&wanted, @directories ); This is my example to search the files by specified pattern (.txt files) in a directory (my backup) in a defined period (1 month).

Here is the main to set up test data and call find:

#!/usr/bin/perl -w
#############################################################
# Example
#############################################################
use strict;
use File::Find;

# We have to do it this way passing parameters
# because the wanted function takes no arguments
# and the return value is ignored.
our ( $search_path, $search_filepattern, $search_destdir, %search_timepattern, $search_maxdepth, $search_action, @filelist );

# Following sector is testing data
# Get processing period of epoch time
my %search_timepattern = CalPeriod( "2008", "03" );
# Define which directory to be searched
my $search_path = "/home/backup/";
# Set max search depth as no sub directories
my $search_maxdepth = 3 ;
# search pattern: all .txt file
my $search_filepattern = ".txt\$";
# The destination directory to move files
my $search_destdir = "/tmp/";
# The array to return matched files
my @filelist;

# The folowing action when a matched file is found
# We use "copy" for testing.
my $search_action = "copy";

# Now, search and take action on matched files
@filelist = find(\&wanted, $search_path);


This part is the wanted function:

sub wanted {
# DESCRIPTION: search for files with given pattern in a directory hierarchy
# This subroution is File::Find wanted function. Do not use it directly.
#
# PARAMETERS:
# our ($search_path, $search_filepattern, $search_destdir, %search_timepattern, $search_maxdepth, $search_action, @filelist);
# The wanted function takes no arguments and the return value is ignored.
#
# $search_path: searching path
# $search_filepattern: string of a pattern to match file name.
# eg. search .txt file, $sesarch_filepattern = ".txt\$"
# %search_timepattern('begin','end'): the time range to match file modification time
# $search_maxdepth: the max depth of recursive subdirectory search.
# 2 is "/*/*/", 3 is "/*/*/*/", so on
# $search_action: following action on matched file: copy, move, print
# $search_destdir: the destination directory if following action is copy/move
# @filelist: RETURN an array of matched files
#############################################################
use File::Spec; use File::Copy;
use File::stat;

# to limit recursive subdirectory search by defined max_depth
my $depth = $File::Find::dir =~ tr[/][];
return if $depth > $search_maxdepth;

# get the original file time stamp
my $atime = stat($File::Find::name)->atime;
my $mtime = stat($File::Find::name)->mtime;

# get the destination file name if move/copy found file
my $dest_file = $search_destdir.$_;
my @dest_file = $dest_file;
if ( ( -f $File::Find::name ) # matches file only
&& ( $File::Find::name =~ /$search_filepattern/ ) # matches defined pattern
&& ( ($mtime ge $search_timepattern{begin})
&& ($mtime le $search_timepattern{end}) ) # matches file time stamp ) {
# Take actions on matched file
# copy
if ( $search_action eq "copy" ) {
printf("Copying...%s to %s \tatime: %s, mtime: %s\n",$File::Find::name,$dest_file,$atime,$mtime);
copy($File::Find::name, $dest_file) or die "Copy failed: $!";
utime $atime, $mtime, @dest_file; # keep original time stamp
}
# move
if ( $search_action eq "move" ) {
printf("Moving...%s to %s\n",$File::Find::name,$dest_file);
move($File::Find::name, $dest_file) or die "Move failed: $!";
utime $atime, $mtime, @dest_file; # keep original time stamp
}
# print file name
if ( $search_action eq "print" ) {
printf("%s\n",$File::Find::name);
}
# return file list
push(@filelist, $File::Find::name);
}
}


Here is some subroutines to process time. It is not necessary to use File::Find.

sub CalPeriod {
# DESCRIPTION: Get one month's start time and end time of epoch
# PARAMETERS: string of year no, string of month no,
# RETURN: hash of period
# $period{begin} The epoch time of first second in a month.
# $period{end} The epoch time of last second in a month.
# (leap second doesn't count).
# USAGE: %period = CalPeriod($YYYY,$MM);
#############################################################
use Time::Local;
my $year = shift(@_);
my $month = shift(@_);
my $days = DayInMonth($month,$year);
my %t1 = (
'year' =$year,
'mmon' = $month - 1, # month number start from 0
'day' = '01',
'hour' = '00',
'min' = '00',
'sec' = '00'
);
my %t2 = (
'year' = $year,
'mmon' = $month - 1, # month number start from 0
'day' = $days,
'hour' = '23',
'min' = '59',
'sec' = '59'
);
my $time_begin = timelocal($t1{sec},$t1{min},$t1{hour},$t1{day},$t1{mmon},$t1{year});
my $time_end = timelocal($t2{sec},$t2{min},$t2{hour},$t2{day},$t2{mmon},$t2{year});
my %period = ( 'begin' = $time_begin, 'end' = $time_end );
return %period ;
}

sub DayInMonth {
# DESCRIPTION: get the days in a month (leap year is calculated)
# PARAMETERS: string of month no, string of year no
# RETURN: string of days
# USAGE: $days = DayInMonth($month,$year);
#############################################################
my $month = shift(@_);
my $year = shift(@_);
my $days = 31;
if ( $month =~ /^(4|04|6|06|9|09|11)$/ ) {
$days = $days - 1;
} elsif ( $month =~ /^(2|02)$/ ) {
$days = 29;
if ((($year%4)!=0) || (($year%100)==0)) {
$days = $days - 1;
}
}
return $days;
}

sub PreMonth {
# DESCRIPTION: get the no of last month
# PARAMETERS: string of month no
# RETURN: string of last month no
# USAGE: $lastmonth = PreMonth($month);
#############################################################
my $mon = shift(@_);
my $m = $mon - 1;
if ( $m < 1 ) { $m = 12; }
$m =~ s/^\d$/0$&/ ;
return $m;
}

2008-11-07

Aegis Command Quick Reference


Aegis Command Reference



Developer Command Summary


Change Directories

    $ aecd -p proj_name -c change_num

Begin Development:

    $ aedb

Undo Begin Development:

    $ aedbu

Copy files

    $ aecp

Administrator Commands


Change Administration


Creating a new change:

    $ aenc -p proj_name

Amending a change:

    $ aeca -p proj_name -c change_num

Viewing outstanding changes

    $ ael oc -p proj_name

Other viewing options:

    !!!!! List Administrators|Developers|Reviewers|Integrators for a particular project
]$ ael [a|d|r|i] -p proj_name
!!!!! Show project files
]$ ael pf -p proj_name

Project Administration:


Creating a new project

    $ aenpr proj_name -DIR /home/aegis/proj_name -version -

Creating project administrators:

    $ aena &username -p proj_name

Creating project developers:

    $ aend username -p proj_name

Creating project reviewers:

    $ aenrv username -p proj_name

Creating project integrators:

    $ aeni username -p proj_name

Removing a project:

    $ aermpr <proj_name>

Edit project attributes:

    $ aepa -p <proj_name>

New Change Example: creation, build, test and integration into baseline


Create our new change change:

    $ aenc -p project1

(change 9999 created)

Begin development on the change:

    $ aedb -p project1 -c 9999

Copy and edit some files for the change:

    $ aecd -p project1 -c 9999
$ aecp readme.txt
$ emacs readme.txt

Modification complete, so check for differences, conflicts:

    $ aed -p project1 -c 9999
$ cs

Okay.. Now make the build:

    $ aeb -p project1 -c 9999

Run the regression tests:

    $ aet -reg -p project1 -c 9999

If the tests pass, pass the integration:

    $ cd /home/aegis/project1 (get out of change directory)
$ aeipass -p project1 -c 9999

End development of the change:

    $ aede -p project1 -c 99999

Ask someone to review your change (or 'su' to someone else)

    $ emacs readme.txt,D

If happy with the change, pass the review:

    $ aerpass -p project1 -c 9999

Crap.. is this correct? I know something else happens now...