Posts Tagged ‘Ubuntu’

Configuring Ubuntu Themes in Linuxmint 17

August 12th, 2014 1 comment

Finally switched from Ubuntu to Linuxmint after the 14.04 release. The distribution installed so many packages that I would never use, and the Unity desktop rendered slow on my old thinkpad πŸ™

After trying Linuxmint 17 in VirtualBox, I found the color of its default theme is not so good. The mixture of grey and light green, sometimes made it a bit hard to detect borders. It also made me feel comfortless when using eclipse:


So I managed to reuse the default theme of Ubuntu within the cinnamon desktop from Linuxmint:


Here’s what I did:

# sudo apt-get install light-themes

This installs the Ubuntu themes. Now edit the theme to add support for Nemo:

# cd /usr/share/themes/Ambiance/gtk-3.0/
# sudo vi gtk-main.css

Add one line to the end of the file:

@import url("apps/nemo.css");

Create the new nemo.css file:

# sudo cp apps/nautilus.css apps/nemo.css
# sudo vi apps/nemo.css

Replace all “nautilus” with “nemo”, “Nautilus” with “Nemo”:


Updated Aug 14: Alternative color in Nemo is not available. It seems to be a bug(LP#945430) in the ubuntu theme.

Now open your “Themes” configuration, go to “Other settings” tab. Set “Controls” to “Ambiance”, set “Icons” to “ubuntu-mono-dark”, set “Window borders” to “Ambiance”.

Categories: Linux Tags:

Customizing Ubuntu Image with UCK

September 14th, 2012 No comments

UCK stands for Ubuntu Customization Kit:

We can use PPA to install it:

# sudo apt-add-repository ppa:uck-team/uck-stable
# sudo apt-get update
# sudo apt-get install uck

And you’ll find it in under “System Tools” section of your menu. Follow the wizard to create your own Ubuntu image. It will extract your Ubuntu image, and also the squashfs on it. 5G free disk space is required under ~/tmp. The final customized image locates as ~/tmp/remaster-new-files/livecd.iso.

I tried to use a 10.04.4 image as base image. It ends with message:

You asked for a hybrid ISO but isohybrid command was not found.

Don’t worry. The final image is already created. isohybrid is in syslinux package 3.72 and later. But Ubuntu 10.04 has only 3.63.

Now you can use the image like the source image. Either burn it or use it to install from harddisk. I integrated all Chinese supports, codecs and some development tools. See screenshot of my livecd:


Categories: Tools Tags:

iOS 5 Device Support in Ubuntu Lucid 10.04

June 16th, 2012 No comments

Seems it’s quite easy to make my iPod touth 4 (iOS 5.0.1) work. 2 packages need update using PPA here. Or you can simply download them and install:

# wget
# wget
# sudo dpkg -i *.deb

Now your audios/videos in your iOS devices are recognized in Rhythmbox :).

Categories: Tools Tags: ,

Updating 3.0 Kernel and Official Nvidia Driver on Ubuntu Lucid

March 8th, 2012 No comments

Ubuntu Lucid(10.04) originally ships with 2.6.32 kernel. But on my T420 thinkpad, the wireless card is not recognized and graphics card is not functional well. Then I switched to 2.6.38 backport kernel, and installed bumblebee package to utilize the Nvidia Optimus Technology. Now the 3.0.0-16 backport kernel is out, it contains the fix for “rework ASPM disable code”, and it should do a better job in power saving even using the discrete Nvidia card. Moreover, it’s the new LTS kernel, so I decided to update to the 3.0 kernel. Please follow the steps if you are interested:

1. Add X-Updates PPA

# sudo apt-add-repository ppa:ubuntu-x-swat/x-updates
# sudo apt-get update
# sudo apt-get install nvidia-current

These commands install official nvidia driver. Currently, it’s the 295.20 version.

2. Enable Nvidia Driver

# sudo update-alternatives --config gl_conf

This will let you to choose opengl engines. Select nvidia over mesa. This will also enable nvidia Xorg drivers, blacklist nouveau driver and add nvidia-xconfig into /usr/bin. You may find warnings like:

update-alternatives: warning: skip creation of /usr/lib32/vdpau/ because associated file /usr/lib32/nvidia-current/vdpau/ (of link group gl_conf) doesn't exist.
update-alternatives: warning: skip creation of /usr/lib32/ because associated file /usr/lib32/nvidia-current/vdpau/ (of link group gl_conf) doesn't exist.

Just ignore them, seems to be safe.

# sudo nvidia-xconfig

This will generate new /etc/X11/xorg.conf file for your Nvidia card. If you cannot find the command, the original location is: /usr/lib/nvidia-current/bin/nvidia-xconfig

3. Fix ld Bindings

# echo "/usr/lib/nvidia-current/tls" | sudo tee -a /etc/ > /dev/null

This just add an ld path into /etc/, otherwise, glx module cannot be loaded correctly. Here’s the /etc/log/Xorg.0.log segments:

(II) LoadModule: "glx"
(II) Loading /usr/lib/xorg/extra-modules/
dlopen: cannot open shared object file: No such file or directory
(EE) Failed to load /usr/lib/xorg/extra-modules/
(II) UnloadModule: "glx"
(EE) Failed to load module "glx" (loader failed, 7)

Now, update ld runtime bindings and reboot.

# sudo ldconfig
# sudo reboot

4. Verify

# sudo apt-get install mesa-utils
# glxinfo | grep -i opengl

If your installation is successful, the output looks like:

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: NVS 4200M/PCIe/SSE2
OpenGL version string: 4.2.0 NVIDIA 295.20
OpenGL shading language version string: 4.20 NVIDIA via Cg compiler
OpenGL extensions:

After installing the driver, hedgewars shows 120fps. While it used to show 4fps. It’s a great improvement. πŸ™‚


Categories: Linux Tags: ,

Reset GNOME Keyring Password on Ubuntu

February 22nd, 2012 No comments

Just copy the solution here:

Method 1:
It is possible to clobber your keyring passphrase and settings from the Terminal. Open a terminal (Applications > Accessories > Terminal), and run the command:

# rm ~/.gnome2/keyrings/login.keyring

On older systems you may need to try:

# rm ~/.gnome2/keyrings/default.keyring

Method 2:
The second method bypasses the Terminal and uses the graphical interface strictly. To delete your current keyring, follow the steps below:

  1. Navigate to Applications > Accessories > Passwords and Encryption Keys
  2. Select the far-right tab “Passwords”
  3. Select your keyring
  4. Right-click and attempt “Change Password” or, if that doesn’t work, select “Delete”
Categories: Tools Tags:

Lyrics Tool in Linux Recommended

February 20th, 2012 No comments


I used to have lrcshow-x, but it seems to be hard to install and do not cache lyrics locally. From the osdlyrics download file list, use the 0.4.0 version for Ubuntu 10.04 (Lucid). Newer versions are broken in MPRIS2 protocol handling, see here.

Categories: Tools Tags:

Learning Bash Scripts (3)

October 4th, 2011 No comments

This post covers the loop usage of bash shell. NOTE: read inline comments carefully πŸ™‚

1. for loop


# loop list, last value remains
for test in Alabama Alaska Arizona Arkansas California Colorado
    echo The next state is $test
echo "The last state we visited was $test"
echo "Wait, now we're visiting $test"

# using escape or quote
for test in I don\'t know if "this'll" work
    echo "word: $test"

# loop variable & files
states="Alabama Alaska Arizona Arkansas Colorado Connecticut Delaware Florida Georgia"
for state in $states; do
    echo $state >> $statesfile
for state in `cat $statesfile`; do
    echo "Visit beautiful $state"
rm $statesfile

# loop directory
for file in ~/.b*; do
    if [ -d "$file" ]; then
        echo "$file is a directory"
    elif [ -f "$file" ]; then
        echo "$file is a file"
        echo "$file doesn't exist"

# c-style syntax
for (( i = 1; i <= 10; i++ )); do
    echo "The next number is $i"

# IFS (internal field separator) to separator string
for entry in `cat /etc/passwd`; do
    echo "Values in $entry:"
    for value in $entry; do
        echo "  $value"

2. while loop


while [ $var1 -gt 0 ]; do
    echo $var1
    var1=$[ $var1 - 1 ]

3. until loop


until [ $var1 -eq 0 ]; do
    echo $var1
    var1=$[ $var1 - 25 ]

4. break & continue


# break
for (( a = 1; a < 4; a++ )); do
    echo "Outer loop: $a"
    for (( b = 1; b < 100; b++ )); do
        if [ $b -eq 5 ]; then
        echo "Inner loop: $b"

# break outer loop
for (( a = 1; a < 4; a++ )); do
    echo "Outer loop: $a"
    for (( b = 1; b < 100; b++ )); do
        if [ $b -eq 5 ]; then
            break 2
        echo "Inner loop: $b"

# continue outer loop
for (( a = 1; a <= 5; a++ )); do
    echo "Iteration $a:"
    for (( b = 1; b < 3; b++ )); do
        if [ $a -gt 2 ] && [ $a -lt 4 ]; then
            continue 2
        var3=$[ $a * $b ]
        echo "  The result of $a * $b is $var3"

There may be times when you’re in an inner loop but need to stop the outer loop. The break command includes a single command line parameter value: break n where n indicates the level of the loop to break out of. By default, n is 1, indicating to break out of the current loop. If you set n to a value of 2, the break command will stop the next level of the outer loop.

5. redirect & pipe

Finally, you can either pipe or redirect the output of a loop within your shell script.


for (( a = 1; a < 10; a++ )); do
    echo "The number is $a"
done > $testfile
echo "The command is finished."
cat $testfile
rm $testfile
Categories: Linux Tags: , ,

Learning Bash Scripts (2)

October 4th, 2011 No comments


When creating a shell script file, you must specify the shell you are using in the first line of the file. The format for this is:

# This script displays the date and who's logged on

In a normal shell script line, the pound sign(#) is used as a comment line. A comment line in a shell script isn’t processed by the shell. However, the first line of a shell script file is a special case, and the pound sign followed by the exclamation point tells the hell what shell to run the script under (yes, you can be using a bash shell and run your script using another shell).

2. Display

The echo command can display a simple text string if you add the string following the command.

# basic usage
echo This is a test.
echo "Let's see if this'll work"
# environment variables
echo "User info for user: $USER"
echo UID: $UID
echo HOME: $HOME
echo "The cost of the item is \$15"
# user variables
echo "$guest checked in $days days ago"
echo "$guest checked in $days days ago"
# backtip
echo "The date and time are: " $testing

The echo command uses either double or single quotes to delineate text strings. If you use them within your string, you need to use one type of quote within the text and the other type to delineate the string.

Notice that the environment variables in the echo commands are replaced by their current values when the script is run. Also notice that we were able to place the $USER system variable within the double quotation marks in the first string, and the shell script was still able to figure out what we meant.

You may also see variables referenced using the format ${variable}. The extra braces around the variable name are often used to help identify the variable name from the dollar sign.

User variables can be any text string of up to 20 letters, digits, or an underscore character. User variables are case sensitive, so the variable Var1 is different from the variable var1. This little rule often gets novice script programmers in trouble.

Values are assigned to user variables using an equal sign. No spaces can appear between the variable, the equal sign, and the value (another trouble spot for novices). Here are a few examples of assigning values to user variables.

The shell script automatically determines the data type used for the variable value. Variables defined within the shell script maintain their values throughout the life of the shell script but are deleted when the shell script completes.

Just like system variables, user variables can be referenced using the dollar sign. It’s important to remember that when referencing a variable value you use the dollar sign, but when referencing the variable to assign a value to it, you do not use the dollar sign.

The backtick allows you to assign the output of a shell command to a variable.

3. Redirect I/O

>: output redirect
>>: output redirect append data
<: input redirect
<<: inline input redirect

# wc << EOF
> test string 1
> test string 2
> test string 3
    3    9    42

The inline input redirection symbol is the double less-than symbol (<<). Besides this symbol, you must specify a text marker that delineates the beginning and end of the data used for input. You can use any string value for the text marker, but it must be the same at the beginning of the data and the end of the data.

4. Math Expression

var3=`expr $var1 \* $var2`
var4=$[$var1 * $var2]
var5=`expr $var1 / $var2`
var6=$[$var1 / $var2]
var7=`echo "scale=3; $var1 / $var2" | bc`
echo The result is $var3
echo The result is $var4
echo The result is $var5
echo The result is $var6
echo The result is $var7

The expr command allowed the processing of equations from the command line. Note the spaces around operator is necessary. Escape character(backslash) is used to identify any characters that may be misinterpreted by the shell before being passed to the expr command.

Bash also provides a much easier way of performing mathematical equations. In bash, when assigning a mathematical value to a variable, you can enclose the mathematical equation using a dollar sign and square brackets ($[ operation ]).

The bash shell mathematical operators support only integer arithmetic. The most popular solution uses the built-in bash calculator, called bc.

5. Structured Commands

5.1 if/else

The bash shell if statement runs the command defined on the if line. If the exit status of the command is zero (the command completed successfully), the commands listed under the then section are executed. If the exit status of the command is anything else, the then commands aren’t executed, and the bash shell moves on to the next command in the script.

# if-then
if grep $user /etc/passwd; then
    echo "The bash files for user $user are:"
    ls -a /home/$user/.b*
# if-then-else
if grep $user2 /etc/passwd; then
    echo "The bash files for user $user2 are:"
    ls -a /home/$user2/.b*
    echo "The user name $user2 does not exist on this system"
if grep $user3 /etc/passwd; then
    echo "The bash files for user $user3 are:"
    ls -a /home/$user3/.b*
elif grep $user2 /etc/passwd; then
    echo "The bash files for user $user2 are:"
    ls -a /home/$user2/.b*
    echo "The user name $user2 and $user3 does not exist on this system"

5.2 test

The test command provides a way to test different conditions in an if-then statement. If the condition listed in the test command evaluates to true, the test command exits with a zero exit status code, making the if-then statement behave in much the same way that if-then statements work in other programming languages. If the condition is false, the test command exits with a 1, which causes the if-then statement to fail.

*) Numeric Comparisons
Comparison Description
n1 -eq n2 Check if n1 is equal to n2.
n1 -ge n2 Check if n1 is greater than or equal to n2.
n1 -gt n2 Check if n1 is greater than n2.
n1 -le n2 Check if n1 is less than or equal to n2.
n1 -lt n2 Check if n1 is less than n2.
n1 -ne n2 Check if n1 is not equal to n2.
if [ $val1 -gt $val2 ]; then
    echo "$val1 is greater than $val2"
    echo "$val1 is less than $val2"
if (( $val1 > $val2 )); then
    echo "$val1 is greater than $val2"
    echo "$val1 is less than $val2"

However, The test command wasn’t able to handle the floating-point value.
You may also notice usage of double parentheses. It provide advanced mathematical formulas for comparisons, no escape is needed in it:

Symbol Description
val++ Post-increment
val– Post-decrement
++val Pre-increment
–val Pre-decrement
! Logical negation
∼ Bitwise negation
** Exponentiation
<< Left bitwise shift
>> Right bitwise shift
& Bitwise Boolean AND
| Bitwise Boolean OR
** Exponentiation
&& && Logical AND
|| Logical OR
*) String Comparisons
Comparison Description
str1 = str2 Check if str1 is the same as string str2.
str1 != str2 Check if str1 is not the same as str2.
str1 < str2 Check if str1 is less than str2.
str1 > str2 Check if str1 is greater than str2.
-n str1 Check if str1 has a length greater than zero.
-z str1 Check if str1 has a length of zero.

Trying to determine if one string is less than or greater than another is where things start getting tricky. There are two problems that often plague shell programmers when trying to use the greater-than or less-than features of the test command:
– The greater-than and less-than symbols must be escaped, or the shell will use them as redirection symbols, with the string values as filenames.
– The greater-than and less-than order is not the same as that used with the sort command.

if [ $val1 \> $val2 ]; then
    echo "$val1 is greater than $val2"
    echo "$val1 is less than $val2"
if [[ $val1 > $val2 ]]; then
    echo "$val1 is greater than $val2"
    echo "$val1 is less than $val2"

The double bracketed expression uses the standard string comparison used in the test command. However, it provides an additional feature that the test command doesn’t, pattern matching. No escape is needed anymore.

Capitalized letters are treated as less than lowercase letters in the test command. However, when you put the same strings in a file and use the sort command, the lowercase letters appear first. This is due to the ordering technique each command uses. The test command uses standard ASCII ordering, using each character’s ASCII numeric value to determine the sort order. The sort command uses the sorting order defined for the system locale language settings. For the English language, the locale settings specify that lowercase letters appear before uppercase letters in sorted order.

While the BashFAQ said: As of bash 4.1, string comparisons using < or > respect the current locale when done in [[, but not in [ or test. In fact, [ and test have never used locale collating order even though past man pages said they did. Bash versions prior to 4.1 do not use locale collating order for [[ either. So you get opposite result when running on CentOS-5.7(bash-3.2) and Ubuntu-10.04(bash-4.1) with [[ operator. And bash-4.1 is consistent with sort command now.

5.3 case

Well, this is easy, just walk through the snippet:

case $USER in
gonwan | barbara)
    echo "Welcome, $USER"
    echo "Please enjoy your visit"
    echo "Special testing account"
    echo "Do not forget to log off when you're done"
    echo "Sorry, you are not allowed here"

All sample code are tested under CentOS-5.7 and Ubuntu-10.04.

Categories: Linux Tags: , ,

Learning Bash Scripts (1)

August 28th, 2011 No comments

In this first post of the series, some basic concepts are introduced. All information from Linux Command Line and Shell Scripting Bible, Second Edition.

1. Shell Types

There are three ways of starting a bash shell:
– As a default login shell at login time
– As an interactive shell that is not the login shell
– As a non-interactive shell to run a script

Login Shell

When you log in to the Linux system, the bash shell starts as a login shell. The login shell looks for four different startup files to process commands from. The following is the order in which the bash shell processes the files:


Interactive Shell

If you start a bash shell without logging into a system (such as if you just type bash at a CLI prompt), you start what’s called an interactive shell. The interactive shell doesn’t act like the login shell, but it still provides a CLI prompt for you to enter commands.

If bash is started as an interactive shell, it doesn’t process the /etc/profile file. Instead, it checks for the .bashrc file in the user’s HOME directory.

Non-interactive Shell

Finally, the last type of shell is a non-interactive shell. This is the shell that the system starts to execute a shell script. This is different in that there isn’t a CLI prompt to worry about. However, there may still be specific startup commands you want to run each time you start a script on your system.

To accommodate that situation, the bash shell provides the BASH_ENV environment variable. When the shell starts a non-interactive shell process, it checks this environment variable for the name of a startup file to execute. If one is present, the shell executes the commands in the file.

2. Terminfo Database

The terminfo database is a set of files that identify the characteristics of various terminals that can be used on the Linux system. The Linux system stores the terminfo data for each terminal type as a separate file in the terminfo database directory. The location of this directory often varies from distribution to distribution. Some common locations are /usr/share/terminfo, /etc/terminfo, and /lib/terminfo.

Since the terminfo database files are binary, you cannot see the codes within these files. However, you can use the infocmp command to convert the binary entries into text.

The Linux shell uses the TERM environment variable to define which terminal emulation setting in the terminfo database to use for a specific session. When the TERM environment variable is set to vt100, the shell knows to use the control codes associated with the vt100 terminfo database entry for sending control codes to the terminal emulator.

3. Virtual Consoles

With modern Linux systems, when the Linux system starts it automatically creates several virtual consoles. A virtual console is a terminal session that runs in memory on the Linux system. Instead of having several dumb terminals connected to the PC, most Linux distributions start seven (or sometimes even more) virtual consoles that you can access from the single PC keyboard and monitor.

In most Linux distributions, you can access the virtual consoles using a simple keystroke combination. Usually you must hold down the Ctl+Alt key combination, and then press a function key (F1 through F8) for the virtual console you want to use. Function key F1 produces virtual console 1, key F2 produces virtual console 2, and so on.

4. Environment Variables

There are two types of environment variables in the bash shell:
– Global variables
– Local variables

Global environment variables are visible from the shell session, and from any child processes that the shell spawns. Local variables are only available in shell that creates them. This makes global environment variables useful in applications that spawn child processes that require information from the parent process.


To view the global environment variables, use the printenv command.
To display the value of an individual environment variable, use the echo command. When referencing an environment variable, you must place a dollar sign($) before the environment variable name.

Unfortunately there isn’t a command that displays only local environment variables. The set command displays all of the environment variables set for a specific process. However, this also includes the global environment variables.


You can assign either a numeric or a string value to an environment variable by assigning the variable to a value using the equal sign(=). It’s extremely important that there are no spaces between the environment variable name, the equal sign, and the value. If you put any spaces in the assignment, the bash shell interprets the value as a separate command.

The method used to create a global environment variable is to create a local environment variable and then export it to the global environment.

Of course, if you can create a new environment variable, it makes sense that you can also remove an existing environment variable. You can do this with the unset command.When referencing the environment variable in the unset command, remember not to use the dollar sign.

NOTE: When dealing with global environment variables, things get a little tricky. If you’re in a child process and unset a global environment variable, it applies only to the child process. The global environment variable is still available in the parent process.

Categories: Linux Tags: , ,

Encoding MP4 Files for iPod on Ubuntu 10.04

July 26th, 2011 No comments

I used mencoder utility to convert my video files. But it was compiled without libfaac. So if you specify AAC encoding, an error occurs. Details and solutions can be found here. I just added the Medibuntu repository as described:

# sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list$(lsb_release -cs).list
# sudo apt-get --quiet update
# sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring
# sudo apt-get --quiet update

NOTE: ffmpeg utility in Lucid release does not support *.rm/*.rmvb yet.

Then install mencoder and codecs:

# sudo apt-get install mencoder libavcodec-extra-52 libavformat-extra-52

Now you can convert videos. Here’s a sample to convert a *.rmvb(848×480) to a *.mp4(320×240):

# mencoder -oac lavc -ovc lavc -lavcopts acodec=libfaac:abitrate=96:aglobal=1:vcodec=mpeg4:vbitrate=500:vglobal=1 -vf scale=320:180,harddup -vf-add expand=:240 -ofps 24000/1001 -of lavf source.rmvb -o target.mp4

Modify fps/codec/bitrate values as you wish. The aglobal & vglobal options seem to be essential for iPod.

In order to keep video aspect after scaling, the output file should be 360×204. we use the -vf-add filter to add black band to the top and bottom of it. Other command line options, please refer to its manpage.

Lastly, install gtkpod to import your *.mp4 files.

Updated Mar 27, 2012: The above command line is for iPod Nano. For high quality H264 encoding used in iPod Touch or iPhone, run:

# mencoder -oac faac -faacopts raw:object=2:mpeg=4:br=96 -ovc x264 -x264encopts nocabac:global_header:bframes=0:level_idc=30:bitrate=600:threads=auto -vf scale=960:-2,harddup -ofps 24000/1001 -of lavf -lavfopts format=mp4 source.rmvb -o target.mp4
Categories: Tools Tags: , ,