[HOWTO] Install Firefox 4 in Ubuntu 10.04 Lucid Lynx and 10.10 Maverick Meerkat

Firefox 4 has been released recently and it is not available via update manager in Ubuntu 10.04 Lucid Lynx and 10.10 Maverick Meerkat. The Ubuntu Mozilla Daily Build PPA provides it but it always the latest daily build and not the stable version.

For stable version, you can use Firefox Stable PPA. To install the PPA in Lucid or Maverick, just launch Synaptic (System>Administration>Synaptic Package Manager) and then go to Settings>Repositories>Other Software. Now click Add and paste in the following:

ppa:mozillateam/firefox-stable

Close the Repositories window and then click reload. When it is done, search for firefox-4.0-gnome-support and mark it for installation. It should mark other required packages. Apply and wait for installation to finish.

[HOWTO] Run apache server with www directory in a different server

This is an experiment in which I wanted to see if it is possible to run apache on one server and have www directory in a different server (physical or virtual). I don’t know the possible benefits of such a system or a scenario where this could be helpful, neither am I aware of different ways to achieve the same. But I tried it and am posting the results anyways. 😀

The Problem

I am assuming a hypothetical problem where a user wants to run apache server in one machine and have the www directory in a different system. Let’s call the machine with apache2 installed as Web Server (WS) and for the system with www directory, lets use the name File Server (FS).

The Plan

The plan is to mount the www directory of FS to a directory of WS with sshfs and configure apache in WS to use that sshfs directory.

Working Environment

I am using my Debian Testing system as FS and Ubuntu 10.10 Maverick Meerkat inside VirtualBox virtual machine (using Bridged connection) as WS which has apache installed. I have openssh server installed in FS and openssh client and sshfs installed in WS.

Plan Execution

Apache Configuration
First, lets login to WS and configure apache to use a directory in normal user’s home directory (/home/ws_username/www) by editing /etc/apache2/sites/available/default. The DocumentRoot is set to /home/ws_username/www and a Directory is set to /home/ws_username/www/ (no virtual hosts, however, using virtual hosts should not be much different either).
Stop apache server for now:

sudo service apache2 stop

Testing SSH connection from WS to FS
Now, connect from WS to FS using:

ssh fs_username@fs_ip_or_domain_name

and verify connection is OK. Add to known hosts (if connecting for the first time). Then type

exit

to disconnect.
Setting up SSH connection without password
If not already created, create a ssh key pair using the command in WS:

ssh-keygen

That should ask you where to store the rsa public key (it is stored by default in /home/ws_username/.ssh/id_rsa/ as /home/ws_username/.ssh/id_rsa/id_rsa.pub). Use a blank password. If you use a password, you may have to use ssh-agent for authentication later (not covered in this article). Now, transfer the pub key to FS using scp.

scp ~/.ssh/id_rsa/id_rsa.pub fs_username@fs_ip_or_domain_name:

Then, ssh to FS:

ssh fs_username@fs_ip_or_domain_name

Now, add the rsa keys copied from WS earlier to authorized_keys file in FS:

cat id_rsa.pub >>~/.ssh/authroized_keys
rm id_rsa.pub

Exit to disconnect and drop to WS shell.
Testing SSH connection from WS to FS without password
If you followed the instructions correctly, you will be able to connect to FS from WS without password when you use SSH.

ssh fs_username@fs_ip_or_domain_name

Exit to disconnect:

exit

Manually mount the www directory in FS to WS using sshfs
Now, test if sshfs is able to mount the directory from FS to WS. Let us assume the www directory is in /home/fs_username/webprojects and is properly readable/writable (as required) by fs_username.
First, allow the user to mount by adding the ws_username to fuse group by running the following command:

sudo gpasswd -a ws_username fuse

Mount the directory to /home/ws_username/www using sshfs:

sshfs -o idmap=ws_username fs_username@fs_ip_or_domain_name:/home/fs_username/webprojects  /home/ws_user/www

Confirm successful mounting by listing the contents:

ls /home/ws_username/www

Unmount when done testing:

fusermount -u /home/ws_username/www

Setup /etc/fstab to be able to mount and unmount using mount and unmount instead
Open up /etc/fstab and add the following line:

sshfs#fs_username@fs_ip_or_domain_name:/home/fs_username/webprojects /home/ws_username/www fuse fsname=sshfs#fs_username@fs_ip_or_domain_name:/home/fs_username/webprojects,users,allow_other,uid=1000,gid=104,comment=sshfs,exec,reconnect,transform_symlinks,BatchMode=yes,noauto 0 0

Don’t use uid and gid values as they appear above. Instead, get those values by running the following command in terminal:

id

Make sure to use the uid and gid (of fuse group) from the output of the above command. Save the file.
Then open up /etc/fuse.conf and add or uncomment the line:

user_allow_other

Try mounting and unmounting using mount and unmount

mount /home/ws_username/www
ls /home/ws_username/www
umount /home/ws_username/www

Setup auto-mount on connection (ifup) and auto-unmount on disconnect (ifdown)
Create a file /etc/network/if-up.d/mountsshfs with the following contents:

#!/bin/sh

## http://ubuntuforums.org/showthread.php?t=430312
## The script will attempt to mount any fstab entry with an option
## "...,comment=$SELECTED_STRING,..."
## Use this to select specific sshfs mounts rather than all of them.
SELECTED_STRING="sshfs"

# Not for loopback
[ "$IFACE" != "lo" ] || exit 0

## define a number of useful functions

## returns true if input contains nothing but the digits 0-9, false otherwise
## so realy, more like isa_positive_integer 
isa_number () {
    ! echo $1 | egrep -q '[^0-9]'
    return $?
}

## returns true if the given uid or username is that of the current user
am_i () {
	[ "$1" = "`id -u`" ] || [ "$1" = "`id -un`" ]
}

## takes a username or uid and finds it in /etc/passwd
## echoes the name and returns true on success
## echoes nothing and returns false on failure 
user_from_uid () {
    if isa_number "$1"
    then
		# look for the corresponding name in /etc/passwd
    	local IFS=":"
    	while read name x uid the_rest
    	do
        	if [ "$1" = "$uid" ]
			then 
				echo "$name"
				return 0
			fi
    	done </etc/passwd
    else
    	# look for the username in /etc/passwd
    	if grep -q "^${1}:" /etc/passwd
    	then
    		echo "$1"
    		return 0
    	fi
    fi
    # if nothing was found, return false
   	return 1
}

## Parses a string of comma-separated fstab options and finds out the 
## username/uid assigned within them. 
## echoes the found username/uid and returns true if found
## echoes "root" and returns false if none found
uid_from_fs_opts () {
	local uid=`echo $1 | egrep -o 'uid=[^,]+'`
	if [ -z "$uid" ]; then
		# no uid was specified, so default is root
		echo "root"
		return 1
	else
		# delete the "uid=" at the beginning
		uid_length=`expr length $uid - 3`
		uid=`expr substr $uid 5 $uid_length`
		echo $uid
		return 0
	fi
}

# unmount all shares first
sh "/etc/network/if-down.d/umountsshfs"

while read fs mp type opts dump pass extra
do
    # check validity of line
    if [ -z "$pass" -o -n "$extra" -o "`expr substr ${fs}x 1 1`" = "#" ]; 
    then
        # line is invalid or a comment, so skip it
        continue
    
    # check if the line is a selected line
    elif echo $opts | grep -q "comment=$SELECTED_STRING"; then
    	
    	# get the uid of the mount
        mp_uid=`uid_from_fs_opts $opts`
        
        if am_i "$mp_uid"; then
			# current user owns the mount, so mount it normally
			{ sh -c "mount $mp" && 
				echo "$mp mounted as current user (`id -un`)" || 
				echo "$mp failed to mount as current user (`id -un`)"; 
			} &
		elif am_i root; then
			# running as root, so sudo mount as user
			if isa_number "$mp_uid"; then
				# sudo wants a "#" sign icon front of a numeric uid
				mp_uid="#$mp_uid"
			fi 
			{ sudo -u "$mp_uid" sh -c "mount $mp" && 
				echo "$mp mounted as $mp_uid" || 
				echo "$mp failed to mount as $mp_uid"; 
			} &
		else
			# otherwise, don't try to mount another user's mount point
			echo "Not attempting to mount $mp as other user $mp_uid"
		fi
    fi
    # if not an sshfs line, do nothing
done </etc/fstab

wait

Create another file /etc/network/if-down.d/umountsshfs with the following contents:

#!/bin/bash

# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0

# comment this for testing
exec 1>/dev/null # squelch output for non-interactive

# umount all sshfs mounts
mounted=`grep 'fuse.sshfs\|sshfs#' /etc/mtab | awk '{ print $2 }'`
[ -n "$mounted" ] && { for mount in $mounted; do umount -l $mount; done; }

Make both files executable and owned by root:

sudo chmod 755 /etc/network/if-up.d/mountsshfs /etc/network/if-down.d/umountsshfs
sudo chown root:root /etc/network/if-up.d/mountsshfs /etc/network/if-down.d/umountsshfs

Test the working of scripts
Enter the commands (assuming the ethernet interface as eth0):

sudo ifdown eth0   #disconnect
sudo ifup eth0   #connect

Test if the directory is mounted:

ls /home/ws_user/www #should list files

Disconnect:

sudo ifdown eth0

Test if the directory is unmounted:

ls /home/ws_user/www #should not list files

Connect back:

sudo ifup eth0   #connect

You can also reboot the system to test if the directory properly mounts at startup.

Start Apache and Test

sudo service apache2 restart

Test using a web browser.

References

http://ubuntuforums.org/showthread.php?t=430312
https://bugs.launchpad.net/ubuntu/+source/sshfs-fuse/+bug/243298
http://linux.dsplabs.com.au/sshfs-read-connection-reset-by-peer-p73/
http://www.debian-administration.org/articles/152
https://help.ubuntu.com/community/SSHFS

[HOWTO] Setup a Minimal Ubuntu LAMP server (with ssh server)

In this article, I will describe how I went about to install the bare minimum LAMP server using Ubuntu Minimal installation iso. I downloaded Maverick Meerkat version of Minimal CD image from the Minimal CD Image Download Page. You can use the server ISO but you may end up with unwanted packages and you will need to download the whole ~700 MB ISO to start, while Minimal CD is just ~13MB. Also, since the Minimal CD downloads the latest packages from the repos during installation, you need not update immediately further saving data volume.

I am installing inside VirtualBox 4.0 Beta. However, these instructions should apply to other Virtualization solutions or even a physical machine.

Boot into the computer with the CD Image (either burn it to business card CD-ROM or normal CD-ROM if using Physical Machine otherwise just mount inside VirtualBox) and follow the on-screen instructions and select appropriate settings that apply to you. At the last stages of the installation, you will be asked to select packages, select none. It will complete installing the basic packages and install Grub and reboot.

After reboot, you will be able to login. After logging in, enter the following command:

sudo apt-get install mysql-server phpmyadmin ssh

The above command should install the following components:
openssh-server
apache2
mysql-server
mysql-client
php
phpmyadmin

At the end of the installation, just select appropriate settings and setup passwords.

Now, when you launch a browser in another machine, you can open http://IP.OF.THE.MACHINE and you will see that system is ready, if everything went right. The installed size is less than 1GB (excluding swap).

Hope this helps.

plymouth-preview, a tool to preview your plymouth theme

I have written a small shell script to preview plymouth themes. I have successfully tested it in Ubuntu 10.10 Maverick Meerkat and Debian Squeeze Testing. It should also work with other Linux distros. Please make sure you have installed the package plymouth-x11 (or equivalent) before using this script.

In Debian, you can install plymouth-x11 by executing the following command as root:

apt-get install plymouth-x11

For Ubuntu, use sudo in the beginning of the command.

Here is the script:

#!/bin/bash

## Preview Plymouth Splash ##
##      by _khAttAm_       ##
##    www.khattam.info     ##
##    License: GPL v3      ##

chk_root () {

  if [ ! $( id -u ) -eq 0 ]; then
    echo Must be run as root
    exit
  fi

}

chk_root

DURATION=$1

if [ $# -ne 1 ]; then
	DURATION=5
fi

plymouthd; plymouth --show-splash ; for ((I=0; I<$DURATION; I++)); do plymouth --update=test$I ; sleep 1; done; plymouth quit

Save the above script somewhere and run as root.

It accepts one command line argument, which specifies the number of seconds you wish to display the splash. The default value is 5, but you can change the script to alter the default value.

References:
http://brej.org/blog/?p=158

[HOWTO] Add Launchpad Ubuntu PPA in Debian Squeeze Testing

I have installed Debian Squeeze Testing replacing Ubuntu 10.10 Maverick Meerkat and miss some applications only available via Launchpad PPAs. Not that they can’t be compiled from their sources or installed by downloading debs, but it would be great if updates were available from update manager like in Ubuntu. So I decided to add some Ubuntu PPAs and they are working fine. So, I decided to share here with the hope that it would be helpful to my readers.

If you want to install a PPA in Squeeze Testing, make sure that the PPA has an entry for Ubuntu 10.04 Lucid Lynx. Not that it will never work with Maverick PPAs, but Lucid is a better choice as Debian Squeeze has package versions more similar to Lucid than Maverick or Natty. Thus, it is a better choice to use Lucid PPAs. Instead of using just the PPA name (for example ppa:tiheum/equinox for Equinox theme PPA) use the deb line for Lucid (eg. deb http://ppa.launchpad.net/tiheum/equinox/ubuntu lucid main ) and add it to /etc/apt/sources.list or Software Sources (or Synaptic>Settings>Repositories>Third Party Source). After adding that, copy the PPA signature (available in “Signing Key” section in PPA page), eg. 1024R/4631BBEA for Equinox Theme PPA. Just use the part after “/” (i.e. 4631BBEA for this example) and use the following command in the terminal to get GPG keys for the PPA:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4631BBEA

Note: If you are not able to sudo, you may either enable it or use su followed by commands instead.
After that, reload the package list and install the package.

This may not work for every program that there is but it works for many. Hope this helps.

[HOWTO] Install pastie in Debian Squeeze/Testing

Pastie is a clipboard manager for gnome with best feature set. It is available in Launchpad PPA for Ubuntu Lucid Lynx and Maverick Meerkat. However, it can be installed in Debian Squeeze/Testing from the same PPA.

To install, just open up Synaptic>Settings>Repositories>Third Party Software and click Add. Add the following line (yes Lucid, not Maverick):

deb http://ppa.launchpad.net/hel-sheep/pastie/ubuntu lucid main

When added, close the Repositories dialog and close Synaptic. Now, open up the terminal and execute the following commands:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DE4CA452
sudo apt-get update
sudo apt-get install pastie python-gnome2

Note: If you are not able to sudo, use su followed by commands without “sudo” and it will work.

This should install pastie in your Debian. Have fun.

[HOWTO] Install all the packages installed in one Ubuntu Installation to another

A recent Web Upd8 article featured a tool called Meta Backup, which unfortunately fails to work as expected unless all the repositories are already configured and there are no orphan packages (not sure of the term, but I’m referring to those that are listed in Synaptic>Origin>Local) .

I created a simple script which can help achieve what Meta Backup wishes to achieve, which is to install the same set of packages in another computer running same version of Ubuntu. Please keep backup of your /etc/apt in both computers. I am not responsible for any harm done to you or your PC by using this script. Having said that, here it is:

pkgbkp-0.04.tar.gz

Extract it and run “packagebkp” from the terminal as root.

[HOWTO] Install the latest version of Shutter screenshot tool in Ubuntu

I am using Shutter screenshot tool as default screenshot tool. I installed it in my Ubuntu 10.10 Maverick Meerkat from the Shutter Team official PPA. The latest available version in that PPA is 0.86~ppa4. The PPA has not been updated for quite some time now. I wanted some bugs to be fixed and when I saw bug pages, they had already been fixed in latest revision. So, I decided to install it.

To do so, I went through the following process.
Install Dependencies

sudo apt-get install bzr libgtk2-unique-perl libimage-info-perl libimage-exiftool-perl

Get latest Shutter

bzr branch lp:shutter

Install

cd shutter
sudo cp bin/* /usr/bin/
sudo cp -R share/* /usr/share/

Now quit Shutter if you have it opened and launch it again.

[HOWTO] Change Ubuntu Pink/Purple Plymouth Boot screen to any color you like

I am using Ubuntu 10.10 Maverick Meerkat and have been using the default theme for quite some time. I was bored with the default boot screen and decided to change it. If you don’t like the purple color of Ubuntu, you can easily change the Desktop theme and wallpaper, but the Pink/Purple Ubuntu Plymouth boot splash is a little difficult to get rid of. You can install other available boot splash by installing other packages, but I like the default boot screen, and just wanted to change its color. To do that, I just cloned the boot screen and made some changes so that it looks like the following.

Here is how I did it. Fire up the terminal and get ready.

Make a copy of the plymouth theme:

sudo cp -R /lib/plymouth/themes/ubuntu-logo /lib/plymouth/themes/ubuntu-logo-nonpink

Edit the name and location information:

sudo gedit /lib/plymouth/themes/ubuntu-logo-nonpink/ubuntu-logo.plymouth

I changed the name to “Ubuntu Logo NonPink” and changed the location of ImageDir and ScriptFile so that it looks like the following:

[Plymouth Theme]
Name=Ubuntu Logo NonPink
Description=A theme that features a blank background with a logo.
ModuleName=script

[script]

ImageDir=/lib/plymouth/themes/ubuntu-logo-nonpink ScriptFile=/lib/plymouth/themes/ubuntu-logo-nonpink/ubuntu-logo.script

Save the file and exit.

Edit the color in script:

sudo gedit /lib/plymouth/themes/ubuntu-logo-nonpink/ubuntu-logo.script

Search for “Window.SetBackgroundTopColor” (without quotes) and change the 2 lines so that they look like the following:

Window.SetBackgroundTopColor (0.85, 0.85, 0.85);     # Nice colour on top of the screen fading to
Window.SetBackgroundBottomColor (0.75, 0.75, 0.75);  # an equally nice colour on the bottom

I have chosen these colors: #DADADA RGB: 217, 217, 217 and #C0C0C0 RGB: 192,192,192
You can choose any color you like. Find the RGB using gcolor2 (install this if you don’t have it installed) of the desired color and divide the RGB values with 256 to get the values to use.
Save the file and exit.

Edit the Ubuntu Logo and other images:
Install Gimp if you haven’t already done so and run the following:

 sudo gimp /lib/plymouth/themes/ubuntu-logo-nonpink/ubuntu_logo.png

The white logo may not look good with the background above. You may change the color however you like. For my selection of background color, black would look great, so I just inverted colors (Colors>Invert).
Once done editing the image, save the file and quit Gimp.
Now, change the progress dots:

sudo gimp /lib/plymouth/themes/ubuntu-logo-nonpink/progress_dot_on.png
sudo gimp /lib/plymouth/themes/ubuntu-logo-nonpink/progress_dot_off.png

I just changed the mode to RGB (Image>Mode>RGB) and desaturated the image (Colors>Desaturate) and got nice gray dot for progress_dot_on. I made no changes to progress_dot_off.

Install the theme:
The theme is ready and can be installed using the following command:

sudo update-alternatives --install /lib/plymouth/themes/default.plymouth default.plymouth /lib/plymouth/themes/ubuntu-logo-nonpink/ubuntu-logo.plymouth 100

Set the theme as default:
Once installed, it can be set as default using the command:

sudo update-alternatives --config default.plymouth

The above command lists all the installed themes as shown:

There are 2 choices for the alternative default.plymouth (providing /lib/plymouth/themes/default.plymouth).

  Selection    Path                                                            Priority   Status
------------------------------------------------------------
  0            /lib/plymouth/themes/ubuntu-logo-nonpink/ubuntu-logo.plymouth    100       manual mode
* 1            /lib/plymouth/themes/ubuntu-logo/ubuntu-logo.plymouth            100       manual mode

Press enter to keep the current choice[*], or type selection number:

Enter the number corresponding to the theme you want to use. In my case, it is “0”. So I entered 0 and pressed ENTER. In your case, it may be different.

Update Initial Boot Image
Now, you will need to run one more command to update the boot images and you are done.

sudo update-initramfs -u

Reboot and see the changed boot screen.

[SOLVED] vnstat: “Zero database found, exiting”

I am using Ubuntu 10.10 Maverick Meerkat and I installed vnstat v1.10-1 from the terminal using apt-get:

sudo apt-get install vnstat

The installation ended with an error:

* Starting vnStat daemon vnstatd Zero database found, exiting.
[fail]

When I tried to monitor my traffic using the following command:

vnstat -m -i eth0

I got the following error:

Error: Unable to read database “/var/lib/vnstat/eth0”.

Then I ran vnstat from the command line and got the following:

No database found, nothing to do. Use –help for help.
A new database can be created with the following command:

vnstat -u -i eth0
Replace ‘eth0’ with the interface that should be monitored.
The following interfaces are currently available:

lo eth0 vboxnet0

Since my computer is using eth0, I created a database for eth0 using the following command:

sudo vnstat -u -i eth0

I got the following output:

Error: Unable to read database “/var/lib/vnstat/eth0”.

Info: -> A new database has been created.

Now, I am able to monitor my Internet traffic using vnstat.