Anything can go here, in any language... except my native language Sinhala. Be cool... anybody is warmly welcomed! :)

Showing posts with label foss. Show all posts
Showing posts with label foss. Show all posts

K770i, Photography and Sorting Problem


Hi fellas, after few days... I'm back again with some cool cool stuff. My internship is over... and now I look for new career opportunities. Anyhow, I was not so quick to apply for a new job like others did. After completing my internship, I wanted a 'free time' of just one or two weeks to have a tour around Sri Lanka.

So, I just had the tour. Amazingly, it was to Jaffna. I live in  Southern Province and going for a tour in Jaffna is just a daydream for a busy man. However, in any tour I have two main intentions, photography and flirting :P . (however I was not able to photograph her since her mom was there :-O )

I have been using a Sony Ericsson K770i phone for more than one year and that phone has made me a photography freak. But recently, it had encountered a problem with it's memory stick reader compartment. This really made me upset as my phone now can't read memory sticks. However, by deleting some wallpapers, ringtones, themes and midlets I managed to make some free space of 15 MB in the phone's internal memory. This is just enough for 15 photos at maximum possible quality. Sad! :(

Luckily I found another phone (a Chinese phone without a brand) which had a memory stick installed and bluetooth also. So my plan was to transfer photos into the Chinese phone over bluetooth after taking each 15 photographs, and delete originals to make free space on my phone for new photos... just like using a revolver ;) . It worked, but since bluetooth file transfer took longer than expected each time I missed few imoprtant shots as well. :(


Sony Cyber-shot cameras use a specific file naming convention. It's the DSC (Digital Still Camera) prefix before the five-digit file number (i.e. DSC00001.JPG, DSC00002.JPG, ...). Due to my 'revolver methodology' sometimes when I make free space my phone seemed to reset the file number. This resulted duplicate filenames, and upon transfer those duplicates were added a Dup(xx) prefix in their filenames. However, thanks to the Chinese phone, during the three days of tour I have been able to take nearly 300 photos, including few panoramas.

After coming home I wanted to arrange all the photos in the correct timeline. Since file naming has already been messed up it was no use arranging them by name. So the next chance is to arrange them by the modification time (unix mtime). Due to some unknown reason, there were some small misconjusnctions in the series when arranging by mtime. It was like Elephant Pass coming before Kilinochchi when heading to Jaffna. :P

So here comes the sorting problem... it's not the Sorting Problem that we learn at the computer science lecture, although we use the tools built upon those theories. I realized that playing with ctime, mtime and atime is just a waste of time... so I was looking for another solution. Yes!, there is. It's the Exif data stored with each file. I can extract the DateTimeOriginal tag from Exif and arrange the file accordingly. I am a Linux geek, so rather than doing a web search for an automated GUI tool  I wanted to do it by myself.

So my ultimate plan was to write a bash script that will check date-time from each file and rename them in the correct order. Also, I wanted them to follow the same DSC convention. There's a handy command line tool for reading image exif on Linux. It's exifprobe. Just an apt-get install is enough to get it installed on the computer. With exifprobe we have another handy tool called exifgrep. Now let us go ahead.

Here we extract the origianal date-time:
$ exifgrep -n DateTimeOriginal DSC00001.JPG

and the output will look like,
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:10 12:04:16'    # DSC00001.JPG:

What I want to do is to list each file against it's OriginalDateTime and then sort with Unix sort command. So it's just one more simple step, (I wanted the output in a text file too)

$ exifgrep -n DateTimeOriginal *.JPG | sort > sorted.txt

Here's a random portion of the output I got,

JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 12:18:54'    # Dup(01)DSC00046.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 12:20:39'    # DSC00048.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 12:23:13'    # Dup(01)DSC00052.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 13:31:30'    # DSC00001.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 13:31:49'    # DSC00002.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 13:32:38'    # DSC00003.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 13:34:07'    # Dup(01)DSC00004.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 13:48:40'    # DSC00007.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 14:01:13'    # Dup(02)DSC00008.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 14:24:49'    # Dup(01)DSC00014.JPG:
JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2010:09:11 14:25:43'    # Dup(02)DSC00015.JPG:

Now, it's the time to write the actual shell script. It's not a big deal actually, as you can see, so I don't need to explain.
#!/bin/bash

mkdir sorted
lines=`cat sorted.txt | wc -l`
for (( line=1; line<=$lines; line++ ))
do
  src=`cat sorted.txt | head -$line | tail -1 | awk '{ print $6 }' | cut -d: -f1`
  dest="DSC"`printf "%05d\n" $line`".JPG"
  cp $src sorted/$dest -v
done

Finally, after running this script I managed to get all photographs according to the timeline. I'll be writing a note about my Jaffna tour as soon as possible, and will be releasing some photographs under the Creative Commons Attribution-Share Alike 3.0 Unported license.

Few of them (such as File:JaffnaPeninsula.JPG) are already available on Wikipedia! :-)

See also:
Thanks for reading... have a nice day! :) :) :)

Attack and the Defence




Hi dear readers! First of all, I WISH YOU A HAPPY AND PROSPEROUS NEW YEAR WITH LOT OF ACHIEVEMENTS, GLORY AND JOYNESS!! Anyway, 2012 is also approaching.. :D (just kidding)

After a long long time, I've got an interesting problem to solve. I'm not an expert. I'm just writing my own way that I followed in the situation.

This happened during the Christmas days in 2009, and after all, I feel it like a Christmas gift, seriously! :-) I wrote two blog posts in my native language, I you can read, just visit the following links. You'll find it more interesting than this one if you can read. :)
  1. http://blog.shaakunthala.com/2009/12/hacker.html
  2. http://blog.shaakunthala.com/2009/12/bash.html
Alright, then... I'm responsible for the administration of several websites. As I feel, an administrator's job is very much similar to the job of a sea captain. He has to look after the system, like his own... be vigilant of the attacks and other problems,.. and many more work.

Recently, I've been notified that one of my sites is down. An empty page with an error message is displayed when the site is visited, and according to that error message, there's an error on index.php, line 38 and the character < is the cause. This is the way how PHP shows error messages. As my immediate actions, I logged on to the FTP server where our website is hosted and opened the index.php

The website was developed using a CMS. The code looked some kind of strange for me because it had no corresponding ?> tag for its beginning <php tag. An unknown HTML/ Javascript code snippet has appended at the end of the file.

Yes, that's the cause of that error. Somebody has injected a malicious code snippet at the end of the index document, and the PHP engine on the server side has tried to interpret it as PHP. As this has caused a syntax error in PHP, the whole site has gone down as the final result.

Here's the structure of index.php :

<?php
/* PHP
codings of
CMS */

<script> // The foreign Javascript code snippet </script>

What I did is, just copy-pasted the code into a separate text file (for analyzing), and cleaned index.php. Then everything looked normal, but sooner I got to know, actually it is not.

I've never experienced such a situation before. I didn't know where to start, and what to do. But I wanted to find out what the code says. It was some kind of scary and big JavaScript code in a single line. However, it's not so scary!


Okey,... a closer look...


Right... and this is our troublemaker...


Just see carefully,.. you don't need to be a JavaScript guru. :-)


It's not a big deal to identify such big codes. Vigilance is what matters here. They have used the replace () method in JavaScript. See... strategically hiding text by just randomly mixing punctuation, retrieving the original text at run time. Wow!

Finally, it's this:


Looks like it has been created for phishing purposes... but I'm not sure exactly. However, this URL points to an empty page. What I expected was a JavaScript code, but this resulted nothing... I don't know a reason. :-/

Within few hours after fixing the issue, I got to know that our website is down again. The same thing has happened, same style, but the malicious code resulted a different URL. I fixed it again, and started thinking... what on earth could be happened here? :-O

Whoever the attacker has done is injecting some malicious code into the index document, and letting it execute at the client's (browser) end. However, as the code has blindly appended at the end of the file despite the structure of it, I came to a conclusion -- definitely this is done by a bot / script or some other automated mechanism.

So, I did the same operation as before for cure, and then tried to find some solution. Yes, it's gonna be a new experience. To prevent further attacks, I put the following line at the end of the index.php file. It prevented interpreting any code below the line. When I say die!, no further interpretation of code at all. Hence, the site is safe from being down, but the risk is still their till I find where the attack comes from and where the security hole is.

die ();

I tried to find any clue on site logs,.. but no luck. If this attack was carried out through HTTP, site logs (not the CMS logs) should indicate that. What I suspect is, somebody has gained access to the server, and executed a script. By adjusting file permissions on the index document, I found out that the malicious script on the server (or bot) has gained the root access.

Later, I got to know, this has recursed into directory hierarchy through the entire site. And also, I saw that some JavaScript files are also infected. It was shocking! Everything throughout the site can be potentially infected with malicious code and hence unsafe for visitors!! I didn't know how serious the attack was. I have never faced such a situation before, and as the responsible personnel, I have to fix this as soon as possible, with my best efforts.

According to all observations, my conclusion was, this is happened due to the fault of the web hosting provider. I know that CMS' sometimes can contain security holes, but if it was, there should be at least something on the site logs.

All of the above is the summary of my first blog post, mentioned at the top of this post. The next few paragraphs in this post explain how I performed the disinfection.

 ---

The only backup we had was bit old, so I forget the idea of restoring from a bacup archive. The challenge was to find out how serious the attack was, and to disinfect everything.

What I suspect so far:
Every JavaScript file and index document is infected -- but not sure about other text-based file formats.

So I have to check each file for malicious code, and then clean them.

First, I thought of writing a PHP script for the purpose. But, PHP is bit insecure with this work. I know, it's not a big deal to fix the security with PHP, but, I was more interested in bash scripting. As a daily Linux-only computer user, I am very familiar with bash, and feel more reliability with that.

Luckily, the web hosting service provider has offered remote access through ssh. Yes, that's great! I was very keen, the rest's gonna be a party!! ;)


Here's the match highlights... :P

Access through ssh, compress the entire site, and then download it. This is necessary because the safe way is to keep a backup + do a testing when doing something serious. One mistake, could ruin everything!!

Here we go, ssh
$ ssh user@mysite.com

Create an archive, (make it tar.bz2 for higher compression ratio -- easy to download). Then exit ssh.
$ tar cvfj mysite.tar.bz2 mysite/
$ exit

Download the backup, through ssh copy.
$ scp user@mysite.com:/home/user/mysite.tar.bz2 /home/shaakunthala/

Unpack on my computer, to be tested with the script.
$ tar xvjf mysite.tar.bz

Now, next step is to write the script. Fired up my favourite vim editor, and then started thinking. ;) Before writing the script it's necessary to exactly identify the nature of the malicious code. Here's what I've identified:
  • If a file is infected, the malicious code is at the end of the file.
  • The foreign code snippet is different from point to point. But, following text portions can be recognized as a common pattern.
    • GNU GPL
    • window.onload
    • .replace
  • Although it seemed like the infection is only with JavaScript and index documents, I refused to accept that. Also, as we didn't have any gigantic files with our website, I decided the script to test all files throughout the site.
Although it was such an easy task to write a script for malware removal, I had to separate the program into two scripts because find -exec does not recognize functions in bash. So, here's what I wrote:

sitefix.sh
#!/bin/bash
# Author: Sameera Shaakunthala

rm fixlog.txt
rootdir=`pwd`/mysite/
sup=`pwd`"/fixfile.sh"
find $rootdir -exec $sup {} \;
echo "JOB DONE!"

fixfile.sh
#!/bin/bash
# Author: Sameera Shaakunthala

echo "Processing file: "$1
code=`tail --lines=1 $1 | grep "GNU GPL" | grep window.onload | grep .replace`
l=`echo $code | wc -m | awk '{ print $1 }'`

if [ $l -ne 1 ]
then
 lc=`wc -l $1 | awk '{ print $1 }'`
 lc=`expr $lc - 1`
 head $1 -n $lc > tempfile.tmp
 mv tempfile.tmp $1
 echo "File "$1" has been fixed!" | tee -a fixlog.txt
fi

Now, the next task is the test run on my local machine. If this succeeds, it is safe to run the script on the server.

$ chmod +x sitefix.sh fixfile.sh
$ ./sitefix.sh

After execution, I checked the fixlog.txt, which is the output log of the script. OMG! 602 infected files!! :-O I vigorously checked some randomly selected files, they were clean, and as everything seemed to be clean, I uploaded the script to the server, and then executed. :)

$ scp sitefix.sh fixfile.sh user@mysite.com:/home/user
$ ssh user@mysite.com
$ chmod +x sitefix.sh fixfile.sh
$ ./sitefix.sh

Finally, we have set this as a cron job, till we find the actual security hole.

The final result was, the disinfection of the entire website, within few minutes. As I got to know that virus scanners no longer block our website, it was confirmed that the site is clean. Just see the spirit of Linux bash scripting! :)

Hallelujah!

Finally, I put a link to a shocking article that must be read... Just click and see! :(

Finally, captain Shaakunthala saved the day, with the support of other captains and sailors, yeah it's an amazing Christmas gift for a newbie administrator! :D

How I switched to Linux


Hi all, after about a one month of silence, I've thought of a nice story to share with you readers. How I switched to Linux.... well, I feel it interesting.... don't know how you'll feel. Just read... you don't need to be a geek. :-)

I live in Ambalangoda, 86 kilometers away from the capital of Sri Lanka and at that time the Internet and computers were not so popular in our area. Even I got my own personal computer in 2003. (I'm still talking about the situation before 2003) The main source of information were just newspapers, magazines, and library books. Because of my usual habit of reading everything I have, I got to know that there is something called Linux, some call it RedHat, and it is different from our Windows, we have to use it from the command line, no mouse,.. and blah blah..

However, after I got my own computer in 2003 (which had Windows installed by default -- obviously), I wanted to try out Linux. But, I couldn't find any installation media. And also, at that time I was living inside a 'Matrix' made by Windows, and I eventually forgot Linux.

In 2005, while I was studying for my A Level examination, one of my friends, who was spending his first year as an undergraduate at SLIIT, opened the door of open source to me. And that was Ubuntu! He was one of my closest friends, and we usually discuss technology related stuff and share our knowledge whenever we meet. He said that they study C programming language in their first semester, and the course is based on Linux.

Furthermore, as he introduced it to me, Ubuntu is a type of Linux, and it looks the same as Windows, you can install aside Windows, you can use the mouse, grapical user interface, you have nice themes, but can't play videos and music, and can't install any software that works with Windows.

So, it made me an Alice in the Wonderland, and I was very keen to learn more. I asked, "Don't we need to type a single command?" (that's what I've heard before). Then he showed me, "Here it is..." the terminal. For me it was amazing,... totally new and there's a whole World in front of me to explore, but, for most of the same aged individuals, it is not.

"Can I borrow your copy for two days?"

"Hey, it's yours!"

He gave me another copy containing two CDs of Ubuntu 5.10, with their logo originally printed on it. One Live CD - One Installation CD. Wow! it was free!!

Canonical, the maintainer of Ubuntu, was shipping large quantities of installation at that time. My friend has ordered 20 copies for re-distribution. But I'm pretty sure that nobody other than both of us were using it till today.



I installed it on my computer and started using it as my secondary OS, but I still didn't have an Internet connection at home. So, learning was very hard. Several times Windows installer ruined the bootloader and I was helpless. But interestingly, my courage and effort was still there! I still wanted to explore this new world!!

I wanted to join Ubuntu community, but no Internet. Download software for Ubuntu, no Internet. But, although I've felt Ubuntu can do nothing other than consuming three valuable gigabytes of my 20 GB hard drive, the remarkable thing was, I still wanted to use and redistribute!! But again,.. no Internet to make the shipit order. :(

Finally, in 2006, I was lucky to have a dial-up Internet connection at home. I've joined the Ubuntu community, asked lot of questions, answered one or two, and I began learning fast. Still I didn't know what Linux is, haven't even heard the word "kernel", but I was happy with what I have. I also distributed some installation media, about 50 copies were given to various people, but, today, only less that ten of those are still using it.

I was doing Win-Lin dual boot for some time. By reading various stuff, I got to know that there are many distributions. I've used Kubuntu, Edubuntu, Mandriva, Puppy, Knoppix and PCLinuxOS 2007. But none of them were able to suit me like Ubuntu did. I know, it's psychology,... the first impression with the meaning of the word "Ubuntu" -- humanity; it simply didn't let me run away.

In 2007, I entered University of Colombo School of Computing as and internal undergraduate, and UCSC is an excellent playground for wannabe Linux geeks. I was studying, studying and studying,... I got to know about the software market, copyrights, law, the FOSS concept, RMS' four freedoms, software licensing, community, what Linux is, it's evolution, the kenel, and all that. So, finally I decided to completely switch to the open source software, rather than sticking into closed Windows.

"Once I get to know about what the Linux is, I will switch"

So, roughly seven months ago, I have been able to do it! (most of my colleagues have not) I removed all Windows stuff from my hard drive, re-partitioned it, and installed two distros. One is Ubuntu, and the other is Fedora. Ubuntu is for day-to-day usage and Fedora is for learning purposes. As I had a sound understanding of what Linux is, and how it worked, it was very easy for me to adopt to the new environment.

I'm still an undergraduate at UCSC, and spending my final year. I have gained lots of things thought my experience, and thought my studies. I use Linux at my school desk, I use it at home, I use it on the way to home, I listen to rock, watch TV, do my assignments and projects, collaborate with my friends, continuously learn, blog and have fun,... one system - for everything. Thanks to Linus and RMS!! :-)

Finally, today I feel I am one of the happy Linux users of this World but I know still we have very few happy Linux users in the World. And I am proud to be part of that beneficent community.

Thanks for reading!

Ubuntu 9.10, Karmic Koala



Howdy..! At last, I was lucky enough to receive my copy of the latest Ubuntu 9.10 Karmic Koala, from Canonical. I was silent over past few days because severe lightning ruined my laptop's power adapter. :( My laptop runs without a battery, and it's only power source is the AC adapter. However, I managed to make it work somehow, and at this time, things are bit OK.

Mmm... Ubuntu..! It looks like that Canonical has bit changed their usual way of shipping policies. In earlier releases, they shipped big amounts of installation media. Later, they limited. But now, if you has received the earlier version (9.04) via shipit service, they won't ship the latest version. They would deny the request, and ask you to update the existing version instead. :(




At glance, the new Ubuntu is OK and friendlier than previous version. Here, I discuss few things I have specially noticed. Some of them are really good, but few things are not.

GRUB2 (Beta)
The bootloader used in earlier versions of Ubuntu is GRUB. But now it has been replaced by GRUB2 which is still in beta. GRUB2 provides more sophisticated graphical interface than GRUB Legacy. When booting, stage 1.5 is no longer used. Also, GRUB configuration is stored in a file named grub.cfg, rather than menu.lst. Configuration file syntax has become changed, and more advanced  than legacy.

But, a one serious draw back with GRUB2 that I have noticed is, it no longer supports bootloader password. In my point of view, this is a huge disadvantage since any idiot can adjust kernel parameters in order to gain root access very easily. So what I did is, soon after installing Ubuntu, switched back to GRUB Legacy. If you wish to do that, use the following command:

$ sudo apt-get install grub
$ sudo grub

Then overwrite the bootloader as specified in this article. Follow the same procedure for your hard drive.

GRUB Legacy works with Ubuntu 9.10 very well, no issues at all. :-)

In distros like Debian, the user is asked to chose the bootloader (whether GRUB, LILO or GRUB2) during installation. But Ubuntu does not. It asks only for the location where bootloader should install. But according to my views, when distributing beta software as a default package for some appliance, the older (stable) version should be kept aside as an option to let the user decide what to install. Because beta software might sometimes dissatisfy the user.

Encrypted Home Folder
This is actually an option provided by ubiquity, the Ubuntu installer. When you set up your user account during installation, you can either choose to require password to login, or require password to login and decrypt home folder, or automatically login. But, the second option seems like a troublemaker since it makes problems with login if you change your password later.

Just see for yourself. ;-)

New Appearance
New dark splash and login screens feel better than earlier ones, Boot time also seems reduced than 9.04. Console font has also become more readable and because of that, console screen has made more roomy.

Default human theme has also modified to become more darker than the earlier... ;-) However, personally I would prefer the earlier one than that.

Like in 9.04, in this release also Ctrl+Alt+Backspace key sequence is disabled. This is not so good since if your desktop freezes, you might need to restart your computer. If this key sequence has been enabled, you can just restart the current X session (without having to reboot) in a such situation. If you want to re-enable it, just go to System --> Preferences --> Keyboard, and then follow the screenshot below.


Click to zoom

However, in Linux, freezing is not an often thing. :-)

New Wallpapers Collection
New wallpapers collection is really a thing to mention because rather than greenish one or two wallpapers that earlier releases had, the new aesthetically pleasing wallpaper set attracts the user... like Windows Vista did. :P

Audio Volume Increasable up to 150%
The worst problem I ever had with Ubuntu audio is, it does not produce enough sound. I was looking for a solution browsing through various forums and blogs, but had no luck. Finally I decided to use SMPlayer since it provides capability to increase audio volume up to more than 100%.

But now, in new Ubuntu 9.10, it provides a very convenient graphical way to increase audio volume up to 150%. For me this is really a great thing since I'm a huge fan of music. However, if you increase volume level than 100%, changes are not persistent. At next reboot, it will again drop to 100%. :(


Click to zoom

Also, Karmic Koala provides a more comprehensible interface for audio configuration. But older configuration interface is also still available through the command line. Just run alsamixer on command line and see.

iBus Input Method Framework
Since I use two languages, it is often needed to switch between those input methods. So, an input method provider is a must. Earlier it was SCIM, and now it has been replaced by iBus which provides a more user friendly configuration interface, and smoother operation. I really like the new iBus. :-)



UbuntuOne
UbuntuOne is an online file hosting service based on cloud computing technology. It is offered by Canonical and they provide 2 GB of space for free of charge, and it cloud can be upgraded to 50 GB for $10 per month. The service is still in public beta.

More information is available here.

Firefox 3.5 as Web Browser
Although Firefox 3.5 was released before Ubuntu 9.04 Jaunty, they distributed the older version. But, in Ubuntu 9.10 the web browser is Firefox 3.5.3.

Empathy as the Default IM Client
A significant change is that they have replaced the default IM client by Empathy. Earlier it was Pidgin. Unlike Pidgin, Empathy supports audio and visual communication.

Screensavers
The number of screensavers has been reduced, and my favourite screensaver Skyrocket is also missing. :-(

In the screensavers dialog box, screen saver preview area had some issues with compiz fusion, but now that seems fixed.





Overall, I feel that Ubuntu has become more and more like Windows than ever it was. And it no longer looks like a g33k's operating system. In my laptop, Karmic Koala works really faster than Jaunty Jackalope. And also compiz fusion works with no issues. However, most users like it. :-)

So, why waiting? Get it..!

(Till I get my laptop fixed, ciao......!!!)

Invoke Google's Web Search from Bash

Nice ideas come in handy way :) ; invoke Google's web search from your Linux desktop shell! :-O

Here's a small shell script that I wrote couple of minutes ago. Copy-paste it into a new file, save it inside /usr/bin as google. This works in GUI mode with firefox very well, but it doesn't work with lynx. I still could not find any reason,.. may be somebody can come up with an idea.

if [ $# -ne 0 ]
then
  query="http://www.google.lk/#hl=en&q="
  for i in $@
  do
    query=$query$i+
  done
  firefox $query &
else
  echo "Usage: google <your search query>."
fi


Then chmod +x /usr/bin/google as root to make it executable.

Now, enter the following as a command and see: B-)

$ google shaakunthala

Or,

Just press Alt+F2, type google shaakunthala and press Enter.


You can use whatever as your keyword. But, have to follow usual bash (shell) syntax.

For example,
If your query is sameera shaakunthala, your command should be,
$ google sameera shaakunthala

If your query is shaakunthala's portal, your command should be,
$ google shaakunthala\'s portal

If your query is "shaakunthala's portal", your command should be,
$ google "\"shaakunthala\'s portal\""

... and so on.

And use your creativity and combine this with some google search hacks that you know. It can be a powerful web search command from your desktop! :-O

Bye! Ciao! Sweet dreams! :P



*** Update ***

I re-wrote the script for lynx. The problem arises with the hash (#)sign in the URL. So I removed it. The whole thing is more convenient in the command line, than in the GUI mode.

if [ $# -ne 0 ]
then
  query="http://www.google.lk/search?hl=en&q="
  for i in $@
  do
    query=$query$i+
  done
  lynx -accept_all_cookies $query
else
  echo "Usage: google <your search query>."
fi

Here's the code explanation (how it works):
When you execute the script with some arguments, it will concatenate all arguments with plus sign (+) in between. This is necessary to parse the input as web browser URL format. Then it will concatenate it to the Google search URL string to pass it to the server script at Google.

And finally pass the whole thing as an argument to your web browser.

if - then - else - fi : Decision making
$# : Total number of arguements passed to the shell
-ne : not equals
for - do - done : Looping
$@ : all the arguments (except the command itself) passed to the shell

Ciao! :)

MP3 Batch Transcoding with Linux


Well, hello there; after some time... this one is about some small work I've done, that I think usful for other Linux users.

 I'm huge fan of music -- especially hard rock and thrash metal. I feel almost dead if I don't get a chance at least once a day, to listen to them. So I wanted to put my huge collection into my mobile phone's memory chip so I can carry them anywhere I go. But, my poor memory chip is just 1 GB. It's not enough at all! So, the only way to pack as much as I can is, reduce the bitrate of the MP3 files.

The next problem... I don't use Windows, nor Windows based software. But, if occurs a situation where I don't have any chance with Linux, I have installed Windows inside a virtual machine for use. But I rarely use that. Of course I can use JetAudio or any other audio conver to do this easily, but, as a professional and permanent Linux user, that's not my style.

So I asked our smart genie... Google to find out a solution. Here's what I've got:
#!/bin/bash
for file in `ls`
do
file=`echo $file | sed s/\ /_/g`
echo $file
lame --decode $file
lame -b 128 $file.wav
rm $file
rm $file.wav
mv $file.wav.mp3 $file
done

http://www.linuxquestions.org/questions/linux-software-2/reduce-mp3-bitrate-336791/

It's a shell script for batch processing. It will process all the MP3 files inside a given directory. Yes, that's more than what I wanted, but, what would happen if filenames contain whitespaces? The solution is not much practical, because most MP3s we get contains at least one whitespace in filename. I don't have time to rename each and every file. So I wsa thinking about a suitable solution.

It is based on lame encoder, if you don't have it, please install it first.
# apt-get install lame

Yes, the find command! Got that!!! Here's the code I've wrote:
Copy this into a text file (mp3enc.sh).

if [ $# -eq 2 ]
then
mkdir $1/output
cd $1
find . -maxdepth 1 -exec lame -h -b $2 {} ./output/{}  \;
else
echo "Invalid arguements, please refer http://portal.shaakunthala.com/2009/10/mp3-batch-transcoding-with-linux.html"
fi

Then execute,
$ chmod +x mp3enc.sh

Now run it,
$ ./mp3enc.sh <mp3_files_directory> <target_bitrate_kbps>

Eg:
$ ./mp3enc.sh /home/ubuntu/Music/MyMusic 128

It will make a directory called output inside your music directory, and put the encoded files in.

It's simple as that! I think it's easier than JetAudio, isn't it? ;)

How I Prepared My GRUB-Bootable USB Flash Drive


Again... the GNU GRUB. I really can't forget such an interesting software that I can study. Today, I'm going to put the English version of my another Sinhala blog post. It's about how I made my flash drive a bootable one.

Now you might say,.. "That's pretty easy stuff with Windows... Just right click and Format...."; wait.........! I'm not going to talk about the DOS/ Windows bootloader. DOS/ Windows bootloader is nothing compared to the GNU GRUB. What I'm going to put here is how to put the GRUB + kernel into your flash drive.

First, I would like to give a small introduction on the GNU GRUB. Wikipedia got a whole lot of information,.. but I'll also explain. Simply, GRUB is a bootloader. A bootloader is the program loads the operating system when your computer boots. Have you ever seen the "NTLDR is missing" error on a Windows XP installed system? Yes, that NTLDR is the bootloader of Windows NT based operating systems. There are two most used types of bootloaders with Linux. One is LILO (LInux LOader) and the other is GRUB (GRand Unified Bootloader). Due to numerous reasons the most popular bootloader among the two is the GRUB. I'm not going to list them here,.. but believe me.. the GRUB is really a 'thing' to study!

So,.. we are bit off the topic.Let's get back on it. How would it be if I install the GRUB on a USB flash drive? That's what came into my mind when I was reading the posts on UCSC LMS (I'm a student). Yes, it would be great! There are several advantages I can think of.
  • If I boot a Live CD, it takes some time. But, here as it is a bootloader only system, it takes a less time to boot up.
  • I can study further,.. (I'm not a Linux expert)
  • I can hijack Linux systems,... :D
  • I can check the RAM using memtest+86.bin kernel

I have a 4 GB flash drive. So here's how I did with it:

1. Backed up all the data on the flash drive as I'm gonna partition it.

2. Divided the drive into two primary partitions. It doesn't matter whether it is primary or logical, but as I didn't need any more partitions, I set it as this.

# fdisk /dev/sdb

One partition is a FAT-32 one to keep my personal files,which I might need to use with both Windows and Linux. It should be the first partition on the flash drive. Unless, Windows will spoil up everything. I left 50 MB at the end of the partition table as unpartitioned/ free space which I'm going to use for the boot partition.

As I've mentioned earlier, Windows can not identify the partitions other than the physically first partition on the flash drive partition table. That means, even if the partition number is not 1, it should exist first to be identified by Windows.

The second one, is nearly 50 MB, and is ext-2 type. It holds the GRUB's files and the kernel.

Formatted the partitions using the following commands:
# mkdosfs /dev/sdb1 -v -F 32 -n LEONIDAS_4G
# mke2fs /dev/sdb2 -L boot

Now mounted them,
# mkdir /media/data; mount -t vfat /dev/sdb1 /media/data

# mkdir /media/boot; mount /dev/sdb2 /media/boot

3. Well, there could be a systematic way to do this. But, I'm not a Linux expert. So, please don't laugh at me. This is how I did it:

# cd /
# cp -rfv boot /media/boot

Now, the GRUB installation, the thing I recently got to know from our LMS forum.

# grub
grub> find /media/boot/boot/grub/stage1

Now it gives the following output:
(hd1,1)

According to the notation, the second partition on the flash drive is (hd1,1). The next step is;

grub> root (hd1,1)
grub> setup (hd1)
grub> quit

Now, the GRUB has been installed on the flash drive.

4. Now I carefully examined the boot partition on the flash drive. There were two versions of the kernal and related files. This might be probably due to a kernal update on my system. It doesn't matter. I kept the most recent version and deleted the other.

5. Finally I edited the menu.lst, which caontains the initial configuration of the GRUB, when it boots. Here's the entire menu.lst file:

title    Linux kernel 2.6.27-14-generic
root     (hd0,1)
kernel   /boot/vmlinuz-2.6.27-14-generic root=UUID=d1670f8e-eb3f-4dba-bba5-e00f0437e2a2 ro single
initrd   /boot/initrd.img-2.6.27-14-generic

title    memtest86+
root     (hd0,1)
kernel   /boot/memtest86+.bin


There's another few important things to state here. Althoug the flash drive is (hd1) here, it becomes (hd0) when booting. The reason is almost obvious, when you set it as the first boot device on the BIOS, it becomes the first device.

The next thing is the UUID. UUID is sent to the kernel as a parameter. You can find the UUID using this:

# vol_id --uuid /dev/sdb2

6. Okey,.. I'm almost done. The final step is to boot. The GRUB loading can bee seen and then the boot menu. You can either edit the menu and boot the kernel on the hard disk or boot the kernel on the flash drive.

There is no init on the flash drive because I didn't put it on the drive. So when booting, it show an error message, and drops into a BusyBox shell. It works on the RAM (initramfs). In simple terms, there is a shell = we can make use of the kernel. :)

7. Restore the backup (personal data/ files) onto the FAT 32 partition on the flash drive. If you plug the flash drive inta a Windows machine, the whole thing may look like this:



Do not delete any of the partitions using the Windows Disk Management Console. If you want to format your data drive, you can go through My Computer and format. Do not touch the other one as it could ruin the entire filesystem on the flash drive which we have built so far. Also if you want to adjust the partition table, the safe option is to do it with Linux.

Finally, I have to say is I've experimented and learnt something new. And I wanted to share my experience here!

Thanks for reading.

Gentoo Installation Screencast - ep 1


As a FOSS enthusiast and a penguin lover I thought of writing more on Linux. For a Linux beginner I would say just use Ubuntu and have some practice with basic idea. But, if you really want to dig deeper, Ubuntu is not the one. For that purpose, to get our hands dirty, what our lecturers have recommended for us is Gentoo. Yes, most online resources say the same thing. If you just install Gentoo using the command line, you'll get to know a whole lot of things. Gentoo is not easy, and it's a good choice for wannabe GNU/ Linux hackers.

If you need a good guide for installation of Gentoo, just refer one of these links:
http://www.gentoo.org/doc/en/?catid=install
http://www.gentoo.org/doc/en/handbook/
http://gentoo-install.com/install

Actually installing Gentoo is not a big thing, just know what you do. I thought of preparing some kind of video screencast of how I did it, and it's available for download [21.5 MB] at http://www.4shared.com/file/136463718/3a2a3124/bootogv.html Actually this video is just booting, partitioning disks and mounting. The first part of a series of videos. If you have any critiques, feel free to discuss here. Due to limitations with my Internet connectivity I can't upload a bigger video which contains the whole thing. I will put subsequent episodes for download as soon as possible.

I did the recording with recordmydesktop (can be seen on the video) which uses the Theora codec, and VirtualBox for as the hardware emulator.

What did I forget to say..? Mhh... yes, the video is copyleft. Download, use it for any purpose. :)

Thanks for reading!

EDIT (01-Oct-2009)

Now I feel like my attempt is quite unsuccessful. However I would neither delete the video nor this post. Without narration and a properly written guide this is unsuccessful. I have a target of preparing some video tutorials with no involvement of propritary software. Till then I may have to learn more about open source video production.

Disk Maintenance with Ubuntu Live


Well, I thought of writing about some disk management which you can do with just using an Ubuntu Live CD.

First thing is, we don't need the GUI. Forget it. The text mode works considerably faster. After loading the initial screen of the Ubuntu Live CD, select the language, then press F6. You get a line that can be edited, and ends with the following parameters:

initrd=/casper/initrd.gz quiet splash --

Replace quiet splash with this:

ro single

And press Enter. Now the system boots into the single user mode. In other words, you are taken into the text mode. In later versions of Ubuntu, you get a menu. Just select root and you'll become root user! You can backup your disks, partition disks, file system check and many more!

Partitioning disks:
Just use either parted or fdisk. Personally I would prefer fdisk.
# fdisk -l (to list all filesystems)
# fdisk /dev/sda (to partition the first disk which is SCSI)
# parted /dev/sda (to partition the first disk which is SCSI)

Dont panic! Help is provided inside these commands. You just need to know plain English and the way that a partition table is structured (theory). :)

Format disks:
# mke2fs /dev/sda1 (format the partition as ext-2)
# mke2fs -j /dev/sda1 (format the partition as ext-3)
# mkntfs /dev/sda1 (format the partition as ntfs)
# mkdosfs /dev/sda1 (format the partition as FAT12/ FAT16 or FAT32)
# mkswap (format as swap)

Filesystem check:
# fsck /dev/sda1 (check and repair Linux filesystem on the drive, the partition should be unmounted first!!!)
# dosfsck /dev/sda1 (check FAT12/16/32 filesystem)

Tune Filesystem:
# tune2fs /dev/sda1 (tune adjustable parameters on a Linux filesystem)
Linux filesystems are periodically checked for  consistency during boot. You can adjust that time period with this tool.
# tune2fs -c 60 /dev/sda1 (set fsck to be executed on /dev/sda1 once a two months)

Backup your data into another drive:
Just execute the following commands one by one. Please refer this thread for a broader discussion.
# mkdir /source
# mount /dev/sda1 /source; mount /dev/sdb1 /mnt
# cd /mnt
# tar cvpzf backup.tgz --exclude=/source/lost+found --exclude=/mnt /source

To restore later (assume the backup archive is located at /dev/sdb1),
# mkdir /mnt/backup /mnt/restore
# mount /dev/sda1 /mnt/restore; mount /dev/sdb1 /mnt/backup
# cd /backup
# tar xvpfz backup.tgz -C /restore

Repair GRUB bootloader:
I got to know about this from here. Not everybody can access that site, so I'll put the whole thing here. Enter the following commands one by one.
# grub
/find/grub/stage1 (find the corresponding values for x and y for the next step)
root(hdx,y)
setup(hdx)

Execute binaries on an existing Linux installation:
# mount /dev/sda1 /mnt; chroot /mnt
You can change the root password too!!! :-O

Wanna see how NTFS is supported on Ubuntu?
Just type ntfs at the root shell prompt and press the Tab twice. I'm not gonna put it here.

If you think I might have forgotten anything to put here, don't hesitate to share it here... Thanks for reading!

Windows 7 on Jaunty

I'm just about to install Windows 7 inside a virtual machine on Jaunty (Ubuntu 9.04). I allocated 512 MB of RAM for the virtual machine. I don't know whether it would be enough. I'm not sure whether I would be able to do it.

Recently I switched to Ubuntu, but because of in some cases I would still need Windows, I decided to install Windows XP inside a virtual machine managed by VirtualBox. The VM in following screenshots is made for Windows XP, but I'm tring out Windows 7.

However, here are the screenshots...


Windows 7 on Ubuntu 9.04


VM named Windows XP, but actually runs Windows 7

VirtualBox Seamless Mode works Perfect



Finally, I've done it and now it's time for some kinda new desktop experience. :)

Fedora Counters For Your Blog

The upcoming version of Fedora, Fedora 11 (Leonidas ) is to be released on May 26th, 2009 [schedule].

They have prepared a counter badge that anybody interested can put it in his/her own web site. I have also put one in my Sinhala blog. So, dear reader, if you also have a blog/ site, please put a badge on your site and help spread the power of human knowledge (human knowledge - that's how Richard M Stallman defines free software).

But there is a problem with the badge. They provide a script (hosted on their servers) so it may not be available in the size you prefer. In my Sinhala blog, my preferred size is 120 pixels. The code they previde is this:


<script id="fedora-banner" type="text/javascript" src="http://fedoraproject.org/static/js/release-counter-ext.js?lang=en"></script>


So I had to download the script and modify it. So here's the modified code and you can simply copy-paste it into a HTML/Javascript widget in your blog. You can modify the 23rd line (bannerimg.setAttribute("width", "120px");) of this code to adjust the badge size.


<script id="fedora-banner" type="text/javascript" language="javascript">

var available_langs = [ "en", "it" ];


var today = new Date();
var release = new Date("May 26, 2009 14:00:00 UTC");
var millisBetweenDates = release - today;
var days = Math.ceil(millisBetweenDates/1000/60/60/24);

var script = document.getElementById('fedora-banner');
var lang = "en"

var url = "http://fedoraproject.org/wiki/Releases/11/Schedule";

var banner = document.createElement('div');

var bannerlink = document.createElement('a');

var bannerimg = document.createElement("img");
bannerimg.style.border = "none";

bannerimg.setAttribute("width", "120px");

if (days <= 0) {
    // TODO: Get an actual image here!
    bannerimg.setAttribute("src", "http://fedoraproject.org/static/images/banners/f11release.png");
    bannerimg.setAttribute("alt", "Fedora 11 is here!");
    url = "http://fedoraproject.org/get-fedora";
} else {
    bannerimg.setAttribute("src", "http://fedoraproject.org/static/images/counter/" + lang + "/fedora11-countdown-banner-" + days + "." + lang + "." + "png");
    bannerimg.setAttribute("alt", "Fedora 11 Leonidas released in " + days + " days.");
}

bannerlink.setAttribute("href", url);

bannerlink.appendChild(bannerimg);
banner.appendChild(bannerlink);

script.parentNode.insertBefore(banner, script);

</script>


If you are interested, please put a counter on your blog too.

Thank you for reading.

Go beyond Windows

These days I'm planning to completely move to Linux. Earlier I used to use Windows. Then did Lin-Win dual for a long time. And now,.. getting ready to go beyond... a Linux-only box. But,... actually,... the (evil?) spirit of Windows will still remain... whoa! Virtualbox!!

Why?
My studies at school will still need Windows environment.

Then Why linux-only?
Windows is so insecure. I'm gonna format the whole thing in ext-4 and put Linux on. Recently,.. two two laptops belonged to two of my friends were lost with their important and confidential data on hard drives. They both were using Windows. Windows filesystem and password encryption algorithms provide almost no security compared to Fedora. Soon,... as I find a temporary place to back up my data which is about 100 gigabytes,.. I will completely turn my hard drive into an encrypted ext-4 system. Simple, free, open, but secure. :)
Even if my laptop is stolen, nobody will be able to find out what I was up to, unless the thief is also a professional cracker.

What's next?
I need to borrow a portable hard drive, to back up my data. Unless I use a portable hard drive, it may be costly to back up all the things into DVDs. Then reformat my hard drive,... install Fedora 11... the upcoming OS on the newly created encrypted drive. Sometimes I may install Ubuntu aside. Finally get my data back and shred the backed up data to prevent unexpected privacy circumstances. :P Additionally I may set up Virtualbox to install Windows XP on a virtual partition.



Several people in our junior batch have become completely FOSS dudes,... so why can't I? Actually, for people who do Computer Science it is easy to switch to Linux,.. but for ICT people it could be bit hard.

Wish me good luck!

Followers

Subscription Options

 Subscribe in a reader

or

Enter your email address:

and
to inscrease

and make me happy. :)

Other Blogs by the Author

The Author

www.flickr.com
ශාකුන්තල | Shaakunthala's items Go to ශාකුන්තල | Shaakunthala's photostream
free counters
TopOfBlogs
Related Posts with Thumbnails