Wednesday, September 30, 2009

[Level 1] Rar tool for Solaris.

Sometimes we will got a rar compressed file from our friends,
but there is no default tool in OpenSolaris to decompress the rar filess.
We can got a Solaris Intel version from rarlab.

The steps as the following:
1. down load the rar tools from rarlab.
http://www.rarlab.com/rar_add.htm
2. uncompressed the source.
# gunzip ./unrar-sol-intel.gz
3. move it to the location you used to.
# mv /unrar-sol-intel.gz /usr/bin/unrar
4. try to decomprss
# unrar x ./test.rar

Wish this helps.

regards,
Stanley Huang

Monday, September 21, 2009

[Level 1] How to install VirtualBox in OpenSolaris.

VirtualBox is a virtual machine which provides you to install multi-OS on it.
LIke OpenSolaris, Solaris 10 x86, Linux (Ubuntu, Fedora...etc) and Windows.

The installation steps as the following:
1. Browering the download page.
  http://www.virtualbox.org/wiki/Downloads
2. Choose the right source for OpenSolaris.
  * VirtualBox 3.0.6 for Solaris and OpenSolaris hosts x86/amd64
3. unzip and untar. 
 # gzip -cd ./VirtualBox-3.0.4-50684-SunOS.tar.gz | tar xvf -
4. install package.
  # pkgadd -d ./VirtualBoxKern-3.0.4-SunOS-r50684.pkg all

 # pkgadd -d ./VirtualBox-3.0.4-SunOS-r50684.pkg all

5. And now, you can start VirtualBox.
 # /bin/VirtualBox

Wish this helps.

regards,
Stanley Huang

Sunday, September 20, 2009

[Level 1] How to solve the timeout problem, when install package?

When installing packages the operation may fail with the error code 28.
You can set the environment variable PKG_CLIENT_TIMEOUT more,
to prevent timeout. The command as the following:

# PKG_CLIENT_TIMEOUT=1200
# export PKG_CLIENT_TIMEOUT
# pkg install <name of packages>

Wish this helps.

regards,
Stanley Huang

[Level 3] How to disable mouse pad?

The mouse pad always make me confuse~
Because whiling typing, I'll touch it, and sometime the mis-operation will just close my working screen. It will make me crazy.
Therefore, I write a script to disable the mouse pad,
at this moment, only the external mouse is active.

But, when I try to enable it, I find out that I cannot enable it, it's that a bug???
Whatever, if you have the same problem, just remove your external mouse,
and the touch pad will be active again.

Just enjoy it~


#!/usr/bin/bash
showUsage() {
  cat <<EOF
Usage:
  $0 (d)isable/(e)nable
Ex.
  $0 (d)isable
  $0 (e)nable
Note.
  for solaris only
EOF
}
disableMousePad() {
  [ ! -z "$modno" ] && pfexec modunload -i $modno
}
enableMousePad() {
  [ ! -z "$modname" ] && pfexec modload /kernel/drv/amd64/$modname
}
showMousePad() {
  echo "Show mod info:"
  pfexec modinfo | grep mouse | grep PS/2
}
################################################## main
export LC_ALL=C
modno=`pfexec modinfo | grep mouse | grep PS/2 | awk '{print($1)}'`
modname=`pfexec modinfo | grep mouse | grep PS/2 | awk '{print($6)}'`
if [ ! -z "$modname" ]
then
  echo "$modname" >> $0.mousepad
elif [ -f $0.mousepad ]
then
  modname=`cat $0.mousepad | head -1`
else
  echo "missing modname info, exit program..."
  exit 1
fi
#set -vx
#sAction=`echo $1 | /usr/bin/tr [A-Z] [a-z]`
sAction=$1
case $sAction in
disable|d|DISABLE|D)
  disableMousePad
  showMousePad
  ;;
enable|e|ENABLE|E)
  enableMousePad
  showMousePad
  ;;

*)
  echo "Error with wrong action($1), exit program..."
  showUsage
  ;;
esac


Wish this helps.

regards,
Stanley Huang

Saturday, September 19, 2009

[Level 2] Xrandr on OpenSolaris in EeePC.

I install OpenSolaris on my EeePC, but I got a problem  about VGA output (for projector).
My OpenSolaris can only support 800x600 resolution, but I think it could be higher.
Then my colleague told me that I modify the file "/etc/X11/xorg.conf".

In normal case, the steps as the following:
1. check your device.
# xrandr
Screen 0: minimum 320 x 200, current 800 x 480, maximum 800 x 800
VGA disconnected (normal left inverted right x axis y axis)
LVDS connected 800x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   800x480        60.0*+
   640x480        85.0     72.8     75.0     59.9 
   720x400        85.0 
   640x400        85.1 
   640x350        85.1 
TV disconnected (normal left inverted right x axis y axis)
#

2. connect your project then try again.
# xrandr
Screen 0: minimum 320 x 200, current 800 x 480, maximum 800 x 800
VGA connected (normal left inverted right x axis y axis)
   800x600        60.3 +   85.0     85.1     72.2     75.0     60.3     56.2 
   640x480        85.0     85.0     75.0     72.8     72.8     75.0     66.7     60.0     59.9 
   720x400        85.0     70.1 
   640x400        85.1 
   640x350        85.1 
LVDS connected 800x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   800x480        60.0*+
   640x480        85.0     72.8     75.0     59.9 
   720x400        85.0 
   640x400        85.1 
   640x350        85.1 
TV disconnected (normal left inverted right x axis y axis)

#

3. use xrandr to auto detection the suitable resolution.
# xrandr --auto
4. assign by manual.
# xrandr --output VGA --mode 800x600
5. close VGA output.
# xrandr --output VGA --off

But in my EeePC, the xrandr only can got 800x600 for VGA output.
It should be higher!
So I have to change xorg.conf. The step as following:
1. check xorg.conf is exist or not.
# ls /etc/X11/xorg.conf
2. If not, create one. (When you want to create a new one, you have down to Single-User-Mode first)
# init s
...

# Xorg -configure
...
Your xorg.conf file is /root/xorg.conf.new


To test the server, run 'X -config /root/xorg.conf.new'
#

3. move the xorg configuration file to /etc/X11
# mv /root/xorg.conf.new /etc/X11/xorg.conf
4. modify xorg.conf, add the red words into the file.
# vi /etc/X11/xorg.conf
...
Section "Monitor"
        Identifier   "Monitor0"
        VendorName   "Monitor Vendor"
        ModelName    "Monitor Model"
        HorizSync       31.5 - 64.3
        VertRefresh     50.0 - 70.0
EndSection
...
Section "Screen"
        Identifier "Screen0"
        Device     "Card0"
        Monitor    "Monitor0"
        SubSection "Display"
                Virtual         1280 1024
                Viewport   0 0
                Depth     24
        EndSubSection
EndSection

...
5. return to milestone all and check again
# exit
# xrandr
Screen 0: minimum 320 x 200, current 640 x 480, maximum 1280 x 1024
VGA connected 640x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   800x600        60.3 +   60.3     56.2 
   1280x1024      60.0 
   1280x960       60.0 
   1280x720       60.0 
   1024x768       70.1     60.0 
   640x480        66.7*    60.0     59.9 
   720x400        70.1 
LVDS connected 640x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   800x480        60.0 +
   640x480        85.0     72.8*    75.0     59.9 
   720x400        85.0 
   640x400        85.1 
   640x350        85.1 
TV disconnected (normal left inverted right x axis y axis)
#

6. Change VGA output with 10

# xrandr --output VGA --mode 1280x1024

OK! I can use 1280x1024 for VGA output now!

Wish this helps.

regards,
Stanley Huang

Sunday, September 13, 2009

[Level 2] How to solve the problem if you forget user password in OpenSolaris?

If you have a user with root role, and forget the user password. How to solve this problem?
Steps as the following:

1. Use CD-ROM to boot.
  You can use CD-ROM to boot server first. If you don't have, please download the iso file and burn a new one for yourself.

2. Import pool and mount Boot Environment.
  Then you can import the "root disk" pool with the command "zpool import". At the same time, you should import the pool ( use option "-R" ) with alternative root. Ex.
# zpool import -R /tmp/rpool rpooliso

  When you try to change directory to the sub folder "etc" of "/tmp/rpool", and you will find out that the folder doesnot exist ( int this case, /tmp/rpool/etc ). Why? because when you import the pool, the Boot Environment will not be mounted, and you have to mount it manually. So you can use command "beadm" with "mount" sub-command then assign the "boot environment" and the "mount point". If you forget the BE, you can use "beadm list" to find it.
# beadm mount opensolaris /opensolaris


3. Modify User password.
  And you can clear the password field in shadow file.
# cd /tmp/rpool/opensolaris/etc
# vi shadow

  After you modify the shadow file, remember to umount the pool and modify the mountpoint by command zfs set.
# beadm umount opensolaris
# zfs set mountpoint=/ rpool/ROOT/opensolaris



4. Reboot and get into Single-User-Mode.
  When you clear the password field, you still cannot login from gnome-desktop. Because the empty password is not allowed. So you have to let your server boot into single-user-mode. But how? When the server show grub menu, press "e" and add "-s" at the last position of command "kernel" and press "b" to boot. In single-user-mode, you can press enter to login the system without password. Ex.
grub> kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS -s
 
5. Change password with command "passwd".
  Last, you can change the password with command "passwd".
# passwd stanley

Wish this helps.

regards,
Stanley Huang

[Level 2] Shell Interactive With Zenity Episode 9 -- text-info (Finished)

If you want to show a multi-line text info, you can use the option "--text-info". Ths Synopsis as below:

SYNOPSIS
     zenity --text-info [--title=title] [--window-icon=path]  [--width=width]   [--height=height]   [--timeout=seconds]   [--filename=path] [--editable]

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one option and click "OK", zenity will response the option and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.

The command that you can try is "zenity --text-info". Ex.
# zenity --text-info
#

In above case, the text column is not editable, and when you click the button "Close" the terminal won't show any response.

If you want the user to modify it, you can use the option "--editable". Ex.
# zenity --text-info --editable
 
Hello world!
#

After you key in "Hello world!" in the column and click the button "Close", the ternimal will respose the the words you type.

If you want the text-info diagram to show the content of file, you have two way to implement it.
Ex 1.
# cat /etc/system | zenity --text-info
Ex 2.
# zenity --text-info --filename=/etc/system

Wish this helps.

regards,
Stanley Huang

[Level 2] Shell Interactive With Zenity Episode 8 -- scale

If you want to let user to set the scale, you can use the option ""--scale" to show a scale diagram. The synopsis as below:

SYNOPSIS
     zenity  --scale  [--title=title]  [--window-icon=path]   [--width=width]   [--height=height]   [--timeout=seconds]   [--text=text]  [--value=number]  [--min-value=number]   [--max-value=number]   [--step=number]  [--print-partial]  [--hide-value]

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one option and click "OK", zenity will response the option and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.
The fist command that you can try is "zenity --scale", When user poll the bar and click button "OK" , then the terminal will return the value that user choose.
# zenity --scale
64
#

If you want the scale diagram has a default value, you can use the option "--value". Ex.
# zenity --scale --value=60
If you want to set the scale diagram max value and min value, you can use the option "--max-value" and "--min-value". Ex.
# zenity --scale --max-value=60 --min-value=30
Value out of range.
#
But maybe you will see the error return like above. Why? That's because the scale default value is "0", and the value "0" is out of your range. So you have to assign the default value between 30 and 60. Ex.
# zenity --scale --max-value=60 --min-value=30 --value=45

 If you want to control the steps when user uses the "left arrow" or "right arrow" key, you can use the option "--step". Ex.
# zenity --scale --step=5
If you want the terminal show every step that user change the value, you can use the option "--print-partial". Ex.
# zenity --scale --print-partial
30

60
60

#
The second "60" shows up, because the user click the button "OK".

If you  don't want to show the "value", while user poll the bar, you can use the option "--hide-value". Ex.
# zenity --scale --hide-value

Wish this helps.

regards,
Stanley Huang

Saturday, September 12, 2009

[Level 2] Shell Interactive With Zenity Episode 7 -- progress

Sometime we want to show a progress bar to let user know the process is still running or how many percentage of task has done. For this purpose, you can use an option "--progress" to fullfill your need.
Ths Synopsis as below:
SYNOPSIS
     zenity --progress [--title=title]  [--window-icon=path]  [--width=width]   [--height=height]   [--timeout=seconds]  [--text=text] [--percentage=number] [--pulsate]  [--auto-close] [--auto-kill]

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one option and click "OK", zenity will response the option and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.



The first command that you can try is "zenity --progress".
# zenity --progress

You will show a pop screen as above, but it just an empty bar, why?
Because the zenity progress bar is waiting your information to display the progress. Try to key some values on the terminal. Like below:
# zenity --progress
10

30

50

100

You will find out, when the number is less than 100, the button "OK" is disabled, that means user just can press "Cancel" buttion. When you give the number 100, the button "OK" is enabled.

If you want to progress show at the specific percentage, you can use the option "--percentage"
# zenity --progress --percentage=30

In some case, your program cannot predict the "percentage" of total task, and you just want to show the user, "The program is still running". So you can use the option "--pulsate" to let the progress "block" moving around.
# zenity --progress --pulsate

But when the command you enter, there still nothing on progress bar. You should press any key on the terminal, then the "block" will show up.
 
 
 
 

Another way to use "--pulsate" like the command below:
# find / -print | zenity --progress --pulsate
The progess bar will rolling until find command is done.

The last two options are "--auto-close" and "--auto-kill".
"--auto-close" means, the progress bar will close automatically after the process is done. And "--auto-kill" means, when the user close the progress bar, will also kill the parent process.

Wish this helps.

regards,
Stanley Huang

Friday, September 11, 2009

[Level 2] Shell Interactive With Zenity Episode 6 -- notification

What option can we use, if we want to let user get something show? You can use the option "--notification", the synoposis as the following:

SYNOPSIS
     zenity --notification [--window-icon=path] [--timeout=seconds] [--text=text] [--listen]

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one option and click "OK", zenity will response the option and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.

When you enter the command ¨zenity --notification¨, you will get a warning sign on the panel. Ex.
# zenity --notification

# zenity --notification --text="Here is the tip"

The notification also support listening, that means the zenity will receive the message from standard input, then display on the notification. If you want to use this function, you can use the option "--listen". This function include "message", "tooltip", "icon" and "visible". The content and the tag are separated by a colon. The sample as the following:

#zenity --notification --listen
tooltip:Here is the tip

message:Here is the message.

icon:/tmp/notification.png

icon: (leave the content empty, for reversing to the original icon)


visible:false

visible:true

Wish this helps.

regards,
Stanley Huang

Sunday, September 6, 2009

[Level 2] Shell Interactive With Zenity Episode 5 -- list

If you want to give a list for user to choose, you can use the option "--list". The command synopsis as below:
SYNOPSIS
     zenity  --list [--title=title] [--window-icon=path] [--width=width]    [--height=height] [--timeout=seconds] [--column=text] [--checklist]       [--radiolist] [--separator=character] [--multiple] [--editable] [--print-column=number] [--hide-column=number]

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one option and click "OK", zenity will response the option and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too. About "--multiple" and "--separator", please refer to tht previous post "[Level 2] Shell Interactive With Zenity Episode 4 -- file-selection".

As the experience before, maybe you cannot wait and use the command, "zenity --list", to show the first screen. Unfortunately, you will get an error response like below:
# zenity --list
No column titles specified for List dialog.
#

That means you have to also define the column. So the first command for list will be:
# zenity --list --column=c1

After above screen show out, you may wonder about "How can we put something in the list?". Do not break the above command. At this comment, the zenity is waiting your input to construct the list. For example, after you key in the "zenity" command, and you put some entry, then the screen will add the entries that you key in. If you put an empty line, the zenity will also create a empty entry.
# zenity --list --column=c1
o1
o2
o3
o4
o5





#

Of course, you cannot ask user to key in the options for you! So how could we pass the "list" to the zenity? According to the above option, you might know the zenity get the option from the stardard input. Therefore, we can use "|" to pass the list. Ex.
# ls /etc | zenity --list --column=filename/foldername

If you want to use another style to show the list, you can use the option "--checklist" or "--radiolist". But with these two options, you should create two column, one for "check box"/"radio box", another is for the content.
# ls /etc | zenity --list --checklist --column=check --column=filename/foldername

# ls /etc | zenity --list --radiolist --column=check --column=filename/foldername

If we have multi columns, how does zenity deal this data? Everytime when zenity get a line, it put it into a column. Ex.
(In this case, <NULL> means empty line)
# zenity --list --column=c1 --column=c2 --column=c3 <<EOF
~> c1-1
~> c2-1
~> c3-1
~> c1-2
~> c2-2
~> c3-2
~> c1-3
~> c2-3
~> <NULL>
~> c1-4
~> <NULL>
~> c3-4
~> EOF

#


If you want to hide some column, you can use the option "--hide-column" and if you want the zenity to response the specific column, you can use the option "--print-column" (The first column is the default column that zenity response). Ex.
# zenity --list --column=c1 --column=c2 --column=c3 --hide-column=2 --print-column=3 <<EOF
~> c1-1
~> c2-1
~> c3-1
~> c1-2
~> c2-2
~> c3-2
~> c1-3
~> c2-3
~> <NULL>
~> c1-4
~> <NULL>
~> c3-4
~> EOF
c1-2

#

If you want to let user to modify the list content, you can use the option "--editable"
# ls /etc | zenity --list --column=filename/foldername --editable

Wish this helps.

regards,
Stanley Huang

Saturday, September 5, 2009

[Level 2] Shell Interactive With Zenity Episode 4 -- file-selection

Does zenity provide the file/directory GUI? Yes, you can use the option "--file-selection". The command synopsis as following:

SYNOPSIS      zenity --file-selection [--title=title] [--window-icon=path]  --width=width]  [--height=height] [--timeout=seconds]  [--filename=path]  [--multiple]  [--directory] [--save] [--separator=character] [--confirm-overwrite]

When you use the option "--file-selection", you will see a pop out screen at the directory that you run this command, like below.
# cd /etc

# zenity --file-selection


Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you select one file and click "OK", zenity will response the filename and return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.

If you want to show a default directory when you run zenity, you can use the option "--filename". When you use "--filename=/etc/security", the start directory will be /etc; "--filename==/etc/security/", the start directory will be "/etc/security". And at this moment, the GUI can only select file, if you click directory, the zneity will enter the directory.

# zenity --file-selection --filename=/etc/security


# zenity --file-selection --filename=/etc/security/

If you want to let user to select only directory (not file), you can use the option "--directory". When you used this option, the color of filename will be grey. That means "disabled".
# zenity --file-selection --directory

if you want to let use can select more than one file, you can use the option "--multiple". After you click the button "OK", all the filenames will be responsed and be separated by the "separator" that you assigned. Ex. If you select two files "/etc/passwd" and "/etc/shadow", the response will be like below:
# zenity --file-selection --multipole -- separator=:
/etc/passwd:/etc/shadow
#


If you want to provide a file saving interface, you can use the option "--save" and "--confirm-overwrite". With option "--save", the screen will have a column for user to key the filename directly. With option "--confirm-overwrite", if user select(key in) the filename that has be already exist, zenity will pop out the confirmation screen to let user to double check again.
# zenity --save --confirm-overwrite
 
 

Wish this helps.

regards,
Stanley Huang

Friday, September 4, 2009

[Level 2] Shell Interactive With Zenity Episode 3 -- error / info / question / warning

If you want to pop out a alter, you can use the option "--error, --info, --question or --warning". The command synopsis as the following:

SYNOPSIS
     zenity  --entry  [--title=title]  [--window-icon=path]   [--width=width]   [--height=height]   [--timeout=seconds]   [--text=text] [--entry-text=text] [--hide-text]

# zenity --error

# zenity --info

# zenity --question

# zenity --warning

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you click "OK", zenity will return the code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.

One thing that confuse me is "--nowrap", every time I use it, the zenity will show the error return as "This option is not available. Please see --help for all possible usages.", and I don't konw. If you know it, please share with me know, thanks.
PS.
  Finally, I know where the problem is. The man page is written with wrong option name. The option should be "--no-wrap", not "--nowarp".

Wish this helps.

regards,
Stanley Huang

[Level 2] Shell Interactive With Zenity Episode 2 -- entry

When shell script needs to communicate with user, we usually use the command "read" to receive your's input. Does zenity has something like this? Yes, you can use the option "--entry". The command synopsis as the following:

SYNOPSIS
     zenity  --entry  [--title=title]  [--window-icon=path]   [--width=width]   [--height=height]   [--timeout=seconds]   [--text=text] [--entry-text=text] [--hide-text]

The first command you can try is "zenity --entry", then you can see a pop out screen like below:
# zenity --entry

Just like "--calendar", if you press "ESC" key or click button "Cancel", the return code will be "1". If you key some text in the column and click "OK", zenity will response the text that you key in and the return code will be "0". And also the same effect about the options "--title", "--timeout"...etc, for saving your time, please refer to the previous post "[Level 2] Shell Interactive With Zenity Episode 1 -- calendar", too.

So all extra options that you should know is, "--entry-text" and "--hide-text".
"--text" option is the default text you want display in the column, like below:
# zenity --entry --entry-text="default text"

And "--hide-text" is for hide the text, zenity will replace the text with "asterisk". It's very useful when the column you want use to key in with his "password", it can prevent the other people to "see" the password while user is typing.
# zenity --entry --text="Please enter your password:" --entry-text="default text" --hide-text
 

Wish this helps.

regards,
Stanley Huang