Script to install a new kernel

#!/bin/sh
#
# (c) Hunterwala

if [ $(/usr/bin/id -u) -ne 0 ]; then
     echo "run this script with sudo"
     exit 2
fi

if [ -z $1 ]; then
     echo "kernel version not found"
     echo "usage: ./install_kernel [kernel_version]"
     exit 2
else
     VERSION=$1
     echo "using $VERSION"
fi

if [ ! -d /lib/modules/$VERSION ]; then
     echo "kernel modules not installed"
     echo "run make install_modules from the kernel directory"
     exit 2
fi

BOOTDIR=/boot

echo "Installing kernel ........................"
cp $PWD/.config $BOOTDIR/config-$VERSION
cp $PWD/System.map $BOOTDIR/System.map-$VERSION
cp $PWD/arch/i386/boot/bzImage $BOOTDIR/vmlinuz-$VERSION
echo "done"

echo "Creating initrd image ...................."
update-initramfs -c -k $VERSION
echo "done"

echo "Updating grub ............................"
update-grub
echo "done"

echo "Linux kernel $VERSION successfully installed"
echo "Please restart and select $VERSION in grub menu"


Kernel module programming

Found a nice article on TLDP on Linux kernel module programming in the 2.6 kernel. (link)

Using VLC player to play Internet Radio

Agent M sent me a link to a very good online western classical radio site. In order to play the radio inside Firefox on Ubuntu the gstreamer plugins are required. The other option is to play it through VLC player.

Install VLC player
%% sudo aptitude install vlc

Open the link in VLC, Media->Open Network, enter the URL and you are good to go.

To avoid this step every time, create a launcher.

1. Right click on the desktop, "Create launcher"
2. Give it a name, "My Radio"
3. In the command use the following /usr/bin/vlc "URL"
4. You can specify a tool-tip comment as well, "ABCD Radio"
5. Click on the icon and select the icon of your choice form /usr/share/icons/hicolor/scalable

Enjoy the music

Battery monitoring from console

If you prefer to work on a console based machine (without gdm\kdm), the following script is useful if you are running your laptop on battery. It shows the current battery charge and can be used for monitoring the battery discharge.

#!/bin/sh
# While working in console mode (without gdm) this script
# tells you the remaining charge of your laptop battery
#
# Run it along with watch on a separate tty
# $ watch -n 10 ./batmon
#
# (c) Hunterwala, 2009
#
# TODO: check for error levels and buzz using pcspkr mod
# when the charge level decreases beyond that level.

PROC_PATH="/proc/acpi/battery/BAT0"

org_cap=`cat $PROC_PATH/info | grep "last full capacity" | sed "s/ //g" | awk -F: '{print($2)}' | sed "s/mAh//g"`
rem_cap=`cat $PROC_PATH/state | grep "remaining capacity" | sed "s/ //g" | awk -F: '{print($2)}'| sed "s/mAh//g"`
message=`cat $PROC_PATH/state | grep "charging state" | sed "s/ //g" | awk -F: '{print($2)}'| sed "s/mAh//g"`

diff=$(echo "($org_cap-$rem_cap)" | bc)
total_per=$(echo "100-($diff*100/$org_cap)" | bc)

echo "Battery is" $message ":" $total_per"%"


Save this script as batmon.sh

Change the permissions chmod a+x batmon.sh

Run it on a separate tty watch -n 10 ./batmon.sh