Techreconn

…technical reconnaissance

Doxygen: Source code to Documentation…


 

doxygen.logo.small

Right from the time we started to code, we were always encouraged to appropriately comment it. I agree it is always a good practice to comment our code so that at least we, in future, recollect what the code is supposed to do, but I’ve often skipped this task for it being very uninteresting and tiresome. Skipping the comments is alright for small programs, but for large programs it is really difficult to keep track without commenting.

Recently I found something that has really encouraged me to document my code. Doxygen by Dimitri van Heesch is a documentation system for C / C++, Java, Objective-C, Python, IDL (Corba and Microsoft flavors), Fortran, VDHL, PHP, C# and to some extent D. By appropriately commenting my code, with Doxygen I am able to generate a neat-and-tidy documentation for both online (HTML) and offline (LaTeX, RTF, (MS-Word), PostScript, hyperlinked PDF, compressed HTML (.chm) and Unix man pages) purpose.

My code for a binary search tree (bst.c), as you will see, has special blocks for comments. When I run doxygen, following the output that I get in HTML.

index.html

bst-functions

bst-functions

bst-file_ref

bst-file_ref

bst-traverse

bst-traverse

The generated PDF file using LaTeX code (generated by Doxygen) is here.

This will give you enough motivation for using Doxygen. The user manual by the original author can be downloaded here.

Here’s the installation procedure for Doxygen. If you have installed TeXLive from an ISO, then please follow the instructions to inform package manager about the TeXLive installation. Use the following command in terminal for Doxygen installation.

sudo apt-get install doxygen doxygen-gui dots

Once you have installed Doxygen, you can start using special comment blocks in your code. In the doxygen user’s manual you will find two types of comments viz. Brief Description and Detailed Description. Whenever you need to have comment a function or a variable before declaring / defining it use the following syntax.

//! Brief descritpion.
/*! Multi-line description or
detailed description.
*/

If you need to comment after the declaration / definition then use the following syntax

//!< Brief descritpion.
/*!< Multi-line description or
detailed description.
*/

This is alright till you need to comment the contents of a file viz. variables, functions, etc. What if you need to comment the file itself? There is nothing like before the file or after the file. In this case you need to use \file like I’ve used in the following example.

//! \file bst.c A simple program to create a Binary Search Tree. This will also make me comfortable with using Doxygen.
/** \file bst.c    
    \mainpage Binary Search Tree Program

    \section intro Introduction

    A simple program to create a Binary Search Tree. This will also make me comfortable with using Doxygen.

    This is really comfortable. I can also generate a custom list as follows.

    I can also add formulae like the following one.
    \f${ \sqrt{ ( x_{2}-x_{1} )^{2} + ( y_{2}-y_{1} )^{2} } }\f$

    I can also insert an image as follows.
    \image html image.jpg
    \image latex image.jpg "image-binary_tree" width=10cm

    And also create external links like
    <a href="http://www.computer.org/portal/web/csdl/doi/10.1109/AMS.2010.69">this</a>.

    \author Milind G. Padalkar

    \date 26-Oct-2010
*/

#include<stdio.h>
#include<stdlib.h>//! An ADT for Binary Search Tree.
/*! This ADT consists of a link to the left subtree, data at the current vertex & a link to the right subtree. */
struct BST {
    struct BST *left; /*!< A pointer to the left subtree. */
    int data; /*!< Data at the current node of the BST. */
    struct BST *right; /*!< A pointer to the right subtree. */
};

Above were the initial few lines of the bst.c file. Now that you have your source code with appropriate comments, open the terminal and type the following command.

doxywizard

You will see something like this.

Doxygen GUI fronted

Doxygen GUI fronted

Fill in the fields appropriately (and use expert tab if required) using the guidelines in the user manual and save this configuration file. I’ve assigned the working directory, source directory and destination directory to the one containing my source code. Here’s my configuration file. You can open it in this wizard and see the various options that I have used. Once you are done with this, press the Run Doxygen button in the Run tab. For my configuration two folders named html and latex were generated. The contents of my folder before running doxygen are here. Do remove the .doc extension and extract (use tar -xzvf Binary-Search-Tree.tar.gz in terminal) it to view the contents.

After running Doxygen, go to html folder and open the index.html file in your web browser. This is all for html. Now for PDF, open the latex folder. Open doxygen.sty file and jump to lines 30 and 32. I replaced the text on these lines from Generated on Tue Jun 7 2011 09:32:31 for Binary Search Tree by Doxygen to Doxygen: Binary Search Tree by Milind Padalkar and saved this file. Now open the terminal (assuming that TeXLive is either installed as dependency or installed using TeXLive ISO), go to the latex folder and type the following command.

make all

You will see refman.pdf generated. Your neat and tidy documentation is ready. Thanks to Dimitri van Heesch, the creator of Doxygen.

Inform Synaptic Package Manager about Locally Compiled Packages


Hi everyone!

Sometimes, you may want to use a specific version of a software. This version may not be available but an older version my be available in the package manager. So even if you install the newer version by compiling it locally, the package manager will not know about it. The real problem arises when this software / program is taken as a dependency by some other software / program. At such a time, even though the newer version is installed, the package manager does not detect it, and hence tries to download and install the older version, unnecessarily wasting space and bandwidth.

Fortunately I found a tool which creates an empty package that fulfils dependencies, making the package system believe that the dependencies are satisfied. The tool is called equivs. I will give you an example of creating such an empty package for an ISO installed TeXLive 2010. Note that the package will be empty and will only inform the package manager about the previously locally build program / software. It will not install any program / software.

Lets start with installing equivs from the terminal.

sudo apt-get install equivs

Now we create a control file for equivs where we fill the package information.

mkdir ~/Desktop/Equivs
cd ~/Desktop/Equivs
equivs-control tl2010

A file with name tl2010 will be created. The contents of this file are as follows.

### Commented entries have reasonable defaults.
### Uncomment to edit them.
Section: misc
Priority: optional
# Homepage: <enter URL here; no default>
Standards-Version: 3.6.2

Package: <package name; defaults to equivs-dummy>
# Version: <enter version here; defaults to 1.0>
# Maintainer: Your Name <yourname@example.com>
# Pre-Depends: <comma-separated list of packages>
# Depends: <comma-separated list of packages>
# Recommends: <comma-separated list of packages>
# Suggests: <comma-separated list of packages>
# Provides: <comma-separated list of packages>
# Replaces: <comma-separated list of packages>
# Architecture: all
# Copyright: <copyright file; defaults to GPL2>
# Changelog: 
# Readme: 
# Extra-Files: additional files for the doc directory>
# Files: <pair of space-separated paths; First is file to include, second is destination>
#  <more pairs, if there's more than one file to include. Notice the starting space>
Description: <short description; defaults to some wise words> 
 long description and info
 .
 second paragraph

I wanted to inform the package manager about the package texlive and the other packages that texlive provides. To achieve this, +I simply opened the terminal and typed sudo apt-get install texlive and pressed tab to find all the packages that it provides. Copied this list and placed it at the appropriate position in the tl2010 control file (at Provides:) with separating each package with a comma and space as follows.

### Commented entries have reasonable defaults.
### Uncomment to edit them.
Section: misc
Priority: optional
Homepage: http://www.tug.org/texlive/acquire-iso.html
Standards-Version: 3.6.2

Package: texlive
Version: 2010
Maintainer: Milind Padalkar 
# Pre-Depends: <comma-separated list of packages>
# Depends: <comma-separated list of packages>
# Recommends: <comma-separated list of packages>
# Suggests: <comma-separated list of packages>
Provides: texlive, texlive-lang-danish, texlive-base, texlive-lang-dutch, texlive-bibtex-extra, texlive-lang-finnish, texlive-binaries, texlive-lang-french, texlive-common, texlive-lang-german, texlive-doc-base, texlive-lang-greek, texlive-doc-bg, texlive-lang-hebrew, texlive-doc-cs+sk, texlive-lang-hungarian, texlive-doc-de, texlive-lang-indic, texlive-doc-en, texlive-lang-italian, texlive-doc-es, ,texlive-lang-latin, texlive-doc-fi, texlive-lang-latvian, texlive-doc-fr, texlive-lang-lithuanian, texlive-doc-it, texlive-lang-mongolian, texlive-doc-ja, texlive-lang-norwegian, texlive-doc-ko, texlive-lang-other, texlive-doc-mn, texlive-lang-polish, texlive-doc-nl, texlive-lang-portuguese, texlive-doc-pl, texlive-lang-spanish, texlive-doc-pt, texlive-lang-swedish, texlive-doc-ru, texlive-lang-tibetan, texlive-doc-si, texlive-lang-ukenglish, texlive-doc-th, texlive-lang-vietnamese, texlive-doc-tr, texlive-latex3, texlive-doc-uk, texlive-latex-base, texlive-doc-vi, texlive-latex-base-doc, texlive-doc-zh, texlive-latex-extra, texlive-extra-utils, texlive-latex-extra-doc, texlive-fonts-extra, texlive-latex-recommended, texlive-fonts-extra-doc, texlive-latex-recommended-doc, texlive-fonts-recommended, texlive-luatex, texlive-fonts-recommended-doc, texlive-math-extra, texlive-font-utils, texlive-metapost, texlive-formats-extra, texlive-metapost-doc, texlive-full, texlive-music, texlive-games, texlive-omega, texlive-generic-extra, texlive-pictures, texlive-generic-recommended, texlive-pictures-doc, texlive-humanities, texlive-plain-extra, texlive-humanities-doc, texlive-pstricks, texlive-lang-african, texlive-pstricks-doc, texlive-lang-all, texlive-publishers, texlive-lang-arabic, texlive-publishers-doc, texlive-lang-armenian, texlive-science, texlive-lang-croatian, texlive-science-doc, texlive-lang-cyrillic, texlive-xetex, texlive-lang-czechslovak
# Replaces: <comma-separated list of packages>
# Architecture: all
# Copyright: <copyright file; defaults to GPL2>
# Changelog: 
# Readme: 
# Extra-Files: additional files for the doc directory>
# Files: <pair of space-separated paths; First is file to include, second is destination>
#  <more pairs, if there's more than one file to include. Notice the starting space>
Description: Dummy for ISO installed TeXLive 2010
 This will inform Synaptic Package Manager that TeXLive 2010 is installed.
 .
 This will not install TeXLive 2010. It will only infrom the about the installation that you did from the ISO.

Now that we have the control file ready, we can create the .deb file with the following command in the terminal.

equivs-build tl2010

On the screen you will see something like what follows

dh_testdir
dh_testroot
dh_clean -k
dh_clean: dh_clean -k is deprecated; use dh_prep instead
dh_clean: Compatibility levels before 5 are deprecated.
dh_testdir
dh_testroot
dh_install
dh_install: Compatibility levels before 5 are deprecated.
dh_installdocs
dh_installdocs: Compatibility levels before 5 are deprecated.
dh_installchangelogs
dh_installchangelogs: Compatibility levels before 5 are deprecated.
dh_compress
dh_compress: Compatibility levels before 5 are deprecated.
dh_fixperms
dh_fixperms: Compatibility levels before 5 are deprecated.
dh_installdeb
dh_installdeb: Compatibility levels before 5 are deprecated.
dh_gencontrol
dh_gencontrol: Compatibility levels before 5 are deprecated.
dh_md5sums
dh_md5sums: Compatibility levels before 5 are deprecated.
dh_builddeb
dh_builddeb: Compatibility levels before 5 are deprecated.
dpkg-deb: building package `texlive' in `../texlive_2010_all.deb'.The package has been created.
Attention, the package has been created in the current directory,
not in ".." as indicated by the message above!

Now you can simply go to the texlive_2010_all.deb file and double click to install it. If you find any error regarding conflicting package then simply remove the package name from the Provides: field in tl2010 file (or mark that package for complete removal and uninstall it completely from the package manager if you feel it is no longer required) and rebuild the tl2010 file using equivs to generate another .deb file. This should now install properly (i.e. inform the package manager about the installed program / software).

This shall now prevent the unnecessary download and install of older program / software. That’s all friends. :-)

Here is my tl2010 file. You will have remove its extension (.doc, used to overcome uploading problem). You may check the syntax with this file.

To rename using the terminal

mv tl2010.doc tl2010

Gedit-latex-plugin for TeXLive2010


For all those who have installed TeXLive from the iso (or followed my post on Installing TeXLive2010) and want to use the gedit-latex-plugin, a bad news is that the plugin seems to use only the base texlive installation from the Ubuntu Repository. If I already have TeXLive installed, why do I need rubber? I spent nearly two days trying to configure the plugin for use with the iso installation of TeXLive 2010 and have now given up. :-( If anyone has a workaround then please respond to this post.

For the time being, I can still use the gedit-latex-plugin without the auto-compilation feature. This is how I managed to do it. Download the 0.2 version of gedit-latex-plugin here. Now rename, extract and move it to gedit’s folder in our home directory.

cd ~/Downloads
mv LaTeXPlugin-0.2.tar.gz.doc LaTeXPlugin-0.2.tar.gz
tar -xzvf LaTeXPlugin-0.2.tar.gz
mkdir ~/.gnome/gedit/plugins
mv GeditLaTeXPlugin* ~/.gnome2/gedit/plugins

Once this is done, we can open gedit and activate the plugin as follows. Open Gedit, go to Edit->Preferences->Plugins Tab and tick the LaTeX Plugin 0.2.

LaTeX Plugin 0.2

\mbox{\LaTeX} Plugin 0.2

Now if you open a .tex file, you will get a screen as follows with the active \mbox{\LaTeX} tool-bar.

LaTeX Tool-bar

\mbox{\LaTeX} Tool-bar

Now a few more useful plugins are to be installed using the terminal.

sudo apt-get install gedit-plugins

As we did earlier, open Gedit and browse to Edit->Preferences->Plugins Tab. Activate Embedded Terminal and Tag List Plugins. Now in Gedit, browse to View and activate the Side Pane and Bottom Pane. This gives you a wonderful lightweight \mbox{\LaTeX} editor. For compilation you can now use the \mbox{\LaTeX} commands that I mentioned in my post on Installing TeXLive2010 in the Embedded Terminal (Bottom Pane).

LaTeX Editor in Gedit

\mbox{\LaTeX} Editor in Gedit

You can use Ctrl+Space for auto-complete feature. If you accidentally open the preview window displaying the message “Preview not available…” use Ctrl+Shift+T to close the preview. In the Side Pane, you can see Documents, File Browser, Tags, Outline and Symbols. The above figure shows Outline in the Side Pane.

A one-shot command for compiling the sample.tex file (find it in my post on Installing TeXLive2010) in the embedded terminal is as given below.

cd /home/milind/Desktop/Sample\ TeX/
latex sample.tex
latex sample.tex
bibtex sample.aux
bibtex sample.aux
latex sample.tex
latex sample.tex
latex sample.tex
latex sample.tex
dvips sample.dvi -o sample.ps
ps2pdf sample.ps
evince sample.pdf

That’s all I could do folks… :-)

Restraining software piracy


Long time back, in my primary school I saw a “Computer” for the first time. My first impression was that the “Monitor” is called a “Computer” and that it can be used only for playing games. Whenever we wanted to play a game, we first used to locate the start button  and then click on the desired game in the games menu. Even though over the years I realised that a computer is not really the monitor but the a set of devices having the CPU as its heart and that it can be used to carry out a lot of productive tasks, I still made the assumption that on starting a computer I should see “Microsoft, and a start button on the bottom left of the screen. We used notepad , MS Word  for typing text, Winamp  & Windows Media Player  for playing media, etc. Life was simple till I got my first personal computer at home. :-) I was very delighted and excited as having a computer at home was a collar-raiser among friends. What followed was a little use of my PC for academics and maximum use for games and media.

Over the years newer games and software came up. Friends exchanged games and software with so called cracks and keygens and we used them seamlessly. With the introduction of Internet we could easily find cracks and keygens online. Name any software and the Internet provided us the software and possibly its crack / keygen. At this time, we were aware of only the “Microsoft” operating system and we became so comfortable with it that we could not imagine a computer without Microsoft. Installation of the then popular operating system Windows XP from an installation disc was not at all tedious and we could use it without any problem without an expiration date. We became so used to Windows XP and other software running on it that any change in the operating system was unacceptable. Even when Windows Vista was introduced, people preferred to use Windows XP.

Slowly the problems of using a pirated software came to light. One fine day I saw the message “You may be a victim of software counterfeiting. This copy of Windows did not pass genuine Windows validation.” on my screen. Few days later my computer started to reboot at various intervals and just a few day before it totally stopped working it used to reboot so frequently that using any application became impossible. Workaround for such problem later became available readily. But what kept troubling were now the viruses and other malicious software. What could be done? Simple, find an Antivirus Software and its crack / keygen? Even these contained malicious code that would adversely affect our machines. Then what? Find free antiviruses…but these may not be as effective as the cracked antivirus software, which had additional functionalities. The process of searching for a solution to an existing problem, and in turn falling into some other problem had become a routine. It took a lot of time for me to realise that I had become a Windows Addict. I am sure many of you are exactly in this situation, where you cannot type a document without Microsoft Word, can’t check your mailbox without Microsoft Outlook, cannot install your favourite software without having to crack it or find a keygen for it…

Don’t you think a change is now necessary to relieve ourselves for such unwanted bothering? Why not go for a genuine, licensed software? Here are a few reasons why I felt the need to use a genuine, licensed software.

1. Think of the creator : If we are benefited by someone’s creation, then ethically the credit should be given to the creator, sometimes in the form of royalties.  Everyone works for some cause. The cause may be one of the following viz. to earn money, popularity, contribute for others to learn, etc. If the creator gets proper returns, it will further motivate them to come up with better and better creations. For so many years Microsoft has been consistently bringing up better and better products for us. Why not appreciate them?

2. Piracy for Addiction: If you think that piracy does not benefit the creator in any way then you are wrong. It does help to popularise the product, and at times to such an extent that we become addicted to the product. When a large population gets such addiction, they won’t even bother to try any other product even if the other product is better and cheap. Example is the Windows XP operating system. According to a survey, the biggest problem to Windows Vista was its own ancestor Windows XP. We don’t tend to accept any changes when everything seems to be working fine, and this exactly is the problem why we get addicted. If majority population is addicted to a particular product, then the creator’s goal to beat the competitor’s product is automatically achieved. Out of this majority, few people with fear of getting caught may buy the required licence. For others, if caught a heavy fine will have to be paid for piracy :-(. In all, the addiction leaves you in either trying to find more and more ways for avoiding piracy detection, or compels you to buy the genuine licensed software!!!

3. Invitation to Trojans and Viruses: If we download software from a non-reliable source, we cannot be sure of its integrity. The software may be tampered to inject malicious script which may badly affect our system. Thus, using a pirated software may invite Trojans and Viruses into our system. For details, you may have a look at this site.

4. Turn to Open Source: Why should we go for costly software if we have an Open Source alternative? For word, spreadsheet, presentation we have LibreOffice  to replace MS Office, Outlook can be replaced by Thunderbird  or Evolution  (Linux) Email Client, CAD users can use DraftSight  instead of AutoCAD, Firefox  or Google Chrome  can replace Internet Explorer. One may check the OSAlt site for a list of Open Source alternatives. Having said that about application software, a list of Open Source Operating Systems can be found here.

What is holding us back from Switching to alternatives? a. Since we are very comfortable with using our current system, we are not sure if everything will work fine when we use the alternative. b. Even if we fell that everything may work fine, we may still not opt the alternative as it may take some time to get used to the new system. c. If these two hurdles are cleared, we may worry about environment around us. Say for example, I am working for an organization which has no issue with me using a Windows operating system or an Open Source Linux system…but a client of my organization when dealing with me may not be comfortable (due to lack of awareness of Linux), with me using an Open Source Linux system…and this may ultimately weaken our relationship with the client. d. Compatibility issues may hold us back.

Conclusion – Say no to Pirated Software: The two ways to get rid of headaches due to pirated software are 1. to buy the costly software from an authentic vendor. 2. to use Open Source Alternatives. I have switched from Windows to  Ubuntu Operating System which comes free of cost. For some software which run only on  Windows, I can run them on  Wine . Initially it took me some time to get used to Ubuntu, but now I can peacefully work without a Windows. For those who use MS Office, I would suggest you to save the Word files with .odt extension instead of .doc or .docx extensions so that they can be seamlessly used in LibreOffice. If you have any trouble with Linux commands then follow Nuwan’s blog.

Decision to pay for costly software or to use Open Source Alternatives is now up to you. Do comment with your queries or suggestions.

Startup Applications in Ubuntu Desktop


Yesterday, I was curious about trying out Gnome3 on my Ubuntu 10.10 Desktop. I followed Aamir Aarfi’s post to install Gnome3 on my machine. The process was successful, but I noticed that every time I logged in, I had to manually start Gnome3 using the command

gnome-shell --replace

I therefore decided to add this command to Startup Applications (System->Preferences->Startup Applications) .

Add Startup Program

Add Startup Program

With this, I logged out and logged in again…guess what…the screen was blank and I couldn’t do anything about it. Also, upon a reboot I would had faced the same problem as the command was bound to run on each login. I wanted to find if I could remove this command from startup in any possible way using the command prompt. My problem was solved by slhck’s answer.

I immediately switched to the terminal by the key combination (Alt+Ctrl+F1) …(F1 to F6, anyone will do). Logged in and deleted the gnome-shell.desktop file. To delete the file type the following once you login to the terminal.

cd ~/.config/autostart/
ls
rm gnome-shell.desktop

Now restarted my machine with the following command.

sudo init 6

Entered the password when prompted and everything was fine on reboot. :-) :-) :-)

Drag and drop not working properly in Ubuntu 11.04?


I’ve been using Ubuntu 11.04 Natty on my laptop for a few days now and I realized that the drag and drop operation is not working at all. Googled for the solution and got it here. Here’s what they suggested.

Open the terminal and type the following.

compiz --replace & exit

And you are done!!! Too simple, isn’t it? But they say that this operation has to be performed every time the system boots up. This is not much of a problem to tackle if you follow my post to create a boot script in Ubuntu. In that case, the contents of the file having the script will simply be the above line i.e. compiz –replace & exit . :-) :-) :-)

Using Remote Desktop in Ubuntu


Hi everyone!!!

You must be familiar with using Remote Desktop in Windows. Just start the service and you are done. Next time you start the machine, you can remotely control your PC. No need to first login into the remote machine before taking its remote-desktop on a network machine. Pretty simple!

When you use remote-desktop service (vncserver) in Ubuntu, you first need to physically go to the remote machine, login into the gnome-session and only then you will be able to take its remote-desktop on a network computer. Tedious, isn’t it? However, the Windows like functionality for remote desktop can be achieved in Ubuntu which I will explain in this post.

In your Ubuntu System, first install vnc4server and openssh-server. Open the terminal and type-in the following.

sudo apt-get install openssh-server vnc4server

Having done that successfully, you can now logout of this machine and move to your network machine from which you wish to take remote desktop of this machine.

Let the conventions be clear.
Remote Machine : Machine whose Remote-Desktop is to be taken.
Network Machine : Machine on which you want to access Remote Machine’s remote-desktop.

Now, on the network machine (I assume it to be a Windows machine) download two packages, the Putty SSH and
VNC Free Edition Viewer for Windows.

Open Putty SSH and connect to the Remote Machine using SSH.

Putty SSH

Putty SSH

On prompting enter your username and password (do not panic, the password may be asked in a few seconds of entering the username) of the Remote Machine. With this you will be able to login into the Pseudo Terminal of the Remote Machine.

Pseudo Terminal

Pseudo Terminal

Now login with the username whose Desktop you need to access remotely. For me, the username is remoteuser.

su - remoteuser

Add this user to list of remote-desktop users as follows.

vnc4passwd

Create a password when prompted. Now start the vnc4server.

vnc4server -geometry 1024x768 -depth 24

This will start the vnc4server for this user. At the same time it will create .Xauthority file and .vnc/xstartup file in the user’s home directory. Open the .vnc/xstartup file and edit the following lines.

cd .vnc
nano xstartup

Comment the line that reads x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
x-window-manager & with a # at the beginning of the line. Now just below this line type the following line.

gnome-session

Save the file and close with Ctrl+o and enter (to save) and Ctrl+x (to exit). Following are the contents of my modified file (xstartup) .

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session
x-window-manager &

Now come to the parent folder and kill the current session of the vnc4server.

cd ..
vnc4server -kill :1

Once that is done, you are ready to use the remote-desktop by restarting the vnc4server on the Pseudo Terminal as follows.

vnc4server

You will see something similar to this on your Pseudo Terminal.

vnc4viewer

vnc4viewer

On the Network Machine now start the downloaded VNC Free Edition Viewer for Windows. In Options choose Full (all available colors). Enter the Remote Machine’s IP Address and the Remote-Terminal Number (as mentioned in the response to starting vnc4server). Ex. if you see New ‘milind-OptiPlex0-755:1 (remoteuser)’ desktop is milind-OptiPlex-755:1 then the port number to be entered is 5901. Similarly if you see New ‘milind-OptiPlex0-755:2 (remoteuser)’ desktop is milind-OptiPlex-755:2 then the port number to be entered is 5902 and so on. So following is what I entered and hit enter OK.

vncviewer

vncviewer

On prompting the password I enter the password that I created for vnc4passwd.

vncviewer-authentication

vncviewer-authentication

BINGO!!! You get your remote desktop!!! :-)

Remote-Desktop

Remote-Desktop

When you are done with your work, simply close the vncviewer’s window and then kill that session in the Pseudo Terminal as follows.

vnc4server -kill :1

Exit from SSH session by typing

exit

You may notice that while in the Remote-Desktop session, every time the d key is pressed, everything minimizes. To solve this open gconf-editor through the terminal as follows.

sudo gconf-editor

This will open the Configuration Editor. Here, go to /->apps->metacity->global_keybindings. In the right pane under Value you will see <Super>d replace this with <Control><Alt>d. Close the configuration editor, and that’s all! This should now allow you to use the d key in the remote session.

Have a good time using Ubuntu Remote Desktop. :-) :-) :-)

Back up an entire Linux System to an installable Live CD/DVD


Hi all! This time I am introducing you all to a tool called Remastersys. With this tool you will be able to backup your entire systems to an installable Live CD/DVD. I am using an Ubuntu machine, but the procedure shall be more or less similar for other Linux distributions. For more information visit Remastersys Homepage.

We shall start with downloading and installing Remastersys with the instructions on this page. Alternatively, if you face any problems with the instructions on that page, we can start with the following procedure.

Download the Remastersys Repository and rename it to remastersysRepo.tar.gz

cd ~/Downloads/
wget http://milindpadalkar.files.wordpress.com/2011/05/remastersysrepo-tar-gz.doc
mv remastersysrepo-tar-gz.doc remastersysRepo.tar.gz

Now extract the files.

mkdir remastersysRepo
tar -xzvf remastersysRepo.tar.gz -C remastersysRepo
cd remastersysRepo

We are now ready to install Remastersys. Install it using the following command.

sudo dpkg -i *.deb

Enter your password when prompted and you are done. This completes the installation of RemasterSys. On my system after installation I had some repository problems. To solve that I had to give the following command. If you face no problems then you may skip this command.

sudo apt-get install -f

Finally we are done with a successful installation without and inconsistencies.

The Remastersys Configuration file is located at /etc/remastersys.conf. The structure of this file is as follows.

#Remastersys Global Configuration File

# This is the temporary working directory and won't be included on the cd/dvd
WORKDIR="/home/remastersys"

# Here you can add any other files or directories to be excluded from the live filesystem
# Separate each entry with a space
EXCLUDES=""

# Here you can change the livecd/dvd username
LIVEUSER="custom"

# Here you can change the name of the livecd/dvd label
LIVECDLABEL="Custom Live CD"

# Here you can change the name of the ISO file that is created
CUSTOMISO="custom$1.iso"

# Here you can change the url for the usb-creator info
LIVECDURL="http://www.geekconnection.org/remastersys"

Make sure that before you set the configuration, take a backup of this file.

sudo cp /etc/remastersys.conf /etc/remastersys.conf.bkp

Now in the configuration file we can set our required parameters using any editor (gedit, nano, vi etc). Following are the contents of my remastersys.conf file.

#Remastersys Global Configuration File

# This is the temporary working directory and won't be included on the cd/dvd
WORKDIR="/home/remastersys"

# Here you can add any other files or directories to be excluded from the live filesystem
# Separate each entry with a space
EXCLUDES=""

# Here you can change the livecd/dvd username
LIVEUSER="liveuser"

# Here you can change the name of the livecd/dvd label
LIVECDLABEL="MGP Ubuntu 11.04 Live CD"

# Here you can change the name of the ISO file that is created
CUSTOMISO="mgp11-04.iso"

# Here you can change the url for the usb-creator info
LIVECDURL="http://www.geekconnection.org/remastersys"

We are now ready to create the ISO. You may check various options by typing the following in the terminal.

man remastersys

And press q to quit the manual. Since I want to create a an installable Live CD/DVD of the entire system without any user files, I give the following command.

sudo remastersys dist

Enter the password on prompting and wait patiently till the ISO file gets created. Following is what you may see on the screen during this process.

Distribution Mode Selected
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  libdcerpc0 libhx509-5-heimdal python-dnspython libgssapi2-heimdal libsamba-util0 libsamdb0 libheimbase1-heimdal
  libsamba-hostconfig0 python-ldb libheimntlm0-heimdal python-talloc ldb-tools python-tdb libkdc2-heimdal libtevent0
  libroken18-heimdal libhdb9-heimdal libkrb5-26-heimdal python-samba libhcrypto4-heimdal libndr-standard0
  samba4-common-bin libldb1 wine1.0-gecko libwind0-heimdal libasn1-8-heimdal libndr0 libregistry0 libgensec0
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  popularity-contest ubuntu-standard
0 upgraded, 0 newly installed, 2 to remove and 4 not upgraded.
After this operation, 258 kB disk space will be freed.
(Reading database ... 182772 files and directories currently installed.)
Removing ubuntu-standard ...
Removing popularity-contest ...
Processing triggers for man-db ...
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  libdcerpc0 libhx509-5-heimdal python-dnspython libgssapi2-heimdal libsamba-util0 libsamdb0 libheimbase1-heimdal
  libsamba-hostconfig0 python-ldb libheimntlm0-heimdal python-talloc ldb-tools python-tdb libkdc2-heimdal libtevent0
  libroken18-heimdal libhdb9-heimdal libkrb5-26-heimdal python-samba libhcrypto4-heimdal libndr-standard0
  samba4-common-bin libldb1 wine1.0-gecko libwind0-heimdal libasn1-8-heimdal libndr0 libregistry0 libgensec0
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  ubiquity-frontend-gtk
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 101 kB of archives.
After this operation, 725 kB of additional disk space will be used.
Get:1 http://ubuntu.c3sl.ufpr.br/ubuntu/ natty/main ubiquity-frontend-gtk i386 2.6.10 [101 kB]
Fetched 101 kB in 4s (23.5 kB/s)
Selecting previously deselected package ubiquity-frontend-gtk.
(Reading database ... 182748 files and directories currently installed.)
Unpacking ubiquity-frontend-gtk (from .../ubiquity-frontend-gtk_2.6.10_i386.deb) ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf.index...
Processing triggers for desktop-file-utils ...
Processing triggers for python-gmenu ...
Rebuilding /usr/share/applications/desktop.en_IN.utf8.cache...
Processing triggers for python-support ...
Setting up ubiquity-frontend-gtk (2.6.10) ...
Processing triggers for python-central ...
Reading package lists...
Building dependency tree...
Reading state information...
Package ubiquity-frontend-kde is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libdcerpc0 libhx509-5-heimdal python-dnspython libgssapi2-heimdal libsamba-util0 libsamdb0 libheimbase1-heimdal
  libsamba-hostconfig0 python-ldb libheimntlm0-heimdal python-talloc ldb-tools python-tdb libkdc2-heimdal libtevent0
  libroken18-heimdal libhdb9-heimdal libkrb5-26-heimdal python-samba libhcrypto4-heimdal libndr-standard0
  samba4-common-bin libldb1 wine1.0-gecko libwind0-heimdal libasn1-8-heimdal libndr0 libregistry0 libgensec0
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Reading package lists...
Building dependency tree...
Reading state information...
metacity is already the newest version.
The following packages were automatically installed and are no longer required:
  libdcerpc0 libhx509-5-heimdal python-dnspython libgssapi2-heimdal libsamba-util0 libsamdb0 libheimbase1-heimdal
  libsamba-hostconfig0 python-ldb libheimntlm0-heimdal python-talloc ldb-tools python-tdb libkdc2-heimdal libtevent0
  libroken18-heimdal libhdb9-heimdal libkrb5-26-heimdal python-samba libhcrypto4-heimdal libndr-standard0
  samba4-common-bin libldb1 wine1.0-gecko libwind0-heimdal libasn1-8-heimdal libndr0 libregistry0 libgensec0
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Checking if the /home/remastersys/remastersys folder has been created
Copying /var and /etc to temp area and excluding extra files
Creating filesystem.manifest and filesystem.manifest-desktop
Setting up casper and ubiquity options for dist mode
Copying your kernel and initrd for the livecd
Creating filesystem.squashfs   ... this will take a while so be patient
Adding stage 1 files/folders that the livecd requires.
Parallel mksquashfs: Using 2 processors
Creating 4.0 filesystem on /home/remastersys/remastersys/ISOTMP/casper/filesystem.squashfs, block size 1048576.
[===================================================================================================-] 10565/10565 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 1048576
    compressed data, compressed metadata, compressed fragments, compressed xattrs
    duplicates are not removed
Filesystem size 81057.71 Kbytes (79.16 Mbytes)
    37.18% of uncompressed filesystem size (218002.97 Kbytes)
Inode table size 139484 bytes (136.21 Kbytes)
    33.40% of uncompressed inode table size (417576 bytes)
Directory table size 127950 bytes (124.95 Kbytes)
    39.90% of uncompressed directory table size (320679 bytes)
No duplicate files removed
Number of inodes 12204
Number of files 10557
Number of fragments 76
Number of symbolic links  860
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 20
Number of directories 767
Number of ids (unique uids + gids) 25
Number of uids 11
    root (0)
    daemon (1)
    lp (7)
    avahi (104)
    milind (1000)
    man (6)
    avahi-autoipd (103)
    gdm (106)
    libuuid (100)
    speech-dispatcher (107)
    messagebus (102)
Number of gids 21
    root (0)
    daemon (1)
    dip (30)
    lp (7)
    fuse (104)
    milind (1000)
    ssl-cert (113)
    admin (120)
    games (60)
    avahi-autoipd (108)
    mlocate (106)
    gdm (114)
    libuuid (101)
    sambashare (122)
    staff (50)
    mail (8)
    avahi (109)
    lpadmin (112)
    crontab (102)
    messagebus (105)
    winbindd_priv (124)
Adding stage 2 files/folders that the livecd requires.
Found a valid exportable SQUASHFS superblock on /home/remastersys/remastersys/ISOTMP/casper/filesystem.squashfs.
    Compression used gzip
    Inodes are compressed
    Data is compressed
    Fragments are compressed
    Xattrs are compressed
    Fragments are present in the filesystem
    Always_use_fragments option is specified
    Duplicates are not removed
    Xattrs are stored
    Filesystem size 81057.71 Kbytes (79.16 Mbytes)
    Block size 1048576
    Number of fragments 76
    Number of inodes 12204
    Number of ids 25

Parallel mksquashfs: Using 2 processors
Scanning existing filesystem...
Read existing filesystem, 12203 inodes scanned
Appending to existing 4.0 filesystem on /home/remastersys/remastersys/ISOTMP/casper/filesystem.squashfs, block size 1048576
All -b, -noI, -noD, -noF, -noX, no-duplicates, no-fragments, -always-use-fragments,
-exportable and -comp options ignored

If appending is not wanted, please re-run with -noappend specified!

No recovery data option specified.
Skipping saving recovery file.

[=================================================================================================|] 117294/117294 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 1048576
    compressed data, compressed metadata, compressed fragments, compressed xattrs
    duplicates are not removed
Filesystem size 1472130.56 Kbytes (1437.63 Mbytes)
    44.56% of uncompressed filesystem size (3303672.65 Kbytes)
Inode table size 2041751 bytes (1993.90 Kbytes)
    25.42% of uncompressed inode table size (8031565 bytes)
Directory table size 1983917 bytes (1937.42 Kbytes)
    40.95% of uncompressed directory table size (4845312 bytes)
No duplicate files removed
Number of inodes 199865
Number of files 131559
Number of fragments 2209
Number of symbolic links  47194
Number of device nodes 3
Number of fifo nodes 0
Number of socket nodes 20
Number of directories 21089
Number of ids (unique uids + gids) 31
Number of uids 11
    root (0)
    daemon (1)
    lp (7)
    avahi (104)
    milind (1000)
    man (6)
    avahi-autoipd (103)
    gdm (106)
    libuuid (100)
    speech-dispatcher (107)
    messagebus (102)
Number of gids 28
    root (0)
    daemon (1)
    dip (30)
    lp (7)
    fuse (104)
    milind (1000)
    ssl-cert (113)
    admin (120)
    games (60)
    avahi-autoipd (108)
    mlocate (106)
    gdm (114)
    libuuid (101)
    sambashare (122)
    staff (50)
    ssh (107)
    mail (8)
    avahi (109)
    lpadmin (112)
    crontab (102)
    messagebus (105)
    winbindd_priv (124)
    shadow (42)
    tty (5)
    nogroup (65534)
    utmp (43)
    utempter (118)
    src (40)
 Calculating the installed filesystem size for the installer
Making disk compatible with Ubuntu Startup Disk Creator.
Creating md5sum.txt for the livecd/dvd
Creating mgp11-04.iso in /home/remastersys/remastersys
Creating mgp11-04.iso.md5 in /home/remastersys/remastersys
/home/remastersys/remastersys/mgp11-04.iso is ready to be burned or tested in a virtual machine.

Check the size and if it is larger than 700MB you will need to burn it to a dvd

1.5G /home/remastersys/remastersys/mgp11-04.iso

It is recommended to run 'sudo remastersys clean' once you have burned and tested the mgp11-04.iso

You will find the generated ISO in /home/remastersys/remastersys/ folder. You may test the ISO in your Virtual Machine (VirtualBox, VMware etc). Following is what you may see in your virtual machine.

Note : If the contents of the ISO are growing more than the capacity of a DVD then the complete process may fail.

VM screenshot

Virtual Machine Screenshot

Once you have tested the ISO file, you will have to run the following command. Make sure that you have copied the ISO to some other location or burnt it on disc. The following command cleans up the entire contents of /home/remastersys/ directory.

sudo remastersys clean

That’s all!!! You are ready to keep this backup of your Entire System and reinstall to the current state in case you face system crash.

Thanks a lot Remastersys!!!

Note : If the contents of the ISO are growing more than the capacity of a DVD then the complete process may fail.

Creating a boot script in Ubuntu


All the people who wish to run scripts at boot time in Ubuntu, here’s the solution.

I will demonstrate a simple script that will copy the /var/log/syslog file onto my Desktop every time my machine boots. Open the terminal and do the following.

cd ~/Desktop
nano cpsyslog

Here I type the following lines. The first line is to copy the syslog file to my Desktop. The second line is to change the ownership of the copied file to user milind and group milind.

cp /var/log/syslog /home/milind/Desktop/syslog
chown milind.milind /home/milind/Desktop/syslog

Close the editor and exit.

ctrl+o and enter
ctrl+x

With this I have successfully created a script (cpsyslog) to copy the /var/log/syslog file to my Desktop. This file needs to be placed in /etc/init.d/ folder.

sudo cp cpsyslog /etc/init.d/

The copied script needs to be made executable. This can be done as follows.

sudo chmod +x /etc/init.d/cpsyslog

Now update rc.d with default values for the script.

sudo update-rc.d cpsyslog defaults

And you are done. Your script will be executed every time your machine is booted.

What if at some point of time you feel that running the script at boot time is no longer required? You just need to remove the symlink to your script using the following command.

sudo update-rc.d -f cpsyslog remove

Optionally, you may also delete the script from /etc/init.d/ folder it you never want to activate this script in future.

sudo rm /etc/init.d/cpsyslog

And you are done!!! :-) :-) :-)

Sharing folders over the network using Samba in Ubuntu


Hi everyone!!!

This time I’ll demonstrate how to setup Folder Sharing over the network in Ubuntu with appropriate permissions for each user. This shall be applicable to other linux distributions as well. The shared content will be available on both Microsoft systems as well as on Linux systems. We will be using the Samba package for this purpose. We start with downloading Samba.

Open the terminal (shortcut : Alt+Ctrl+t) and install the samba package

sudo apt-get install samba smbfs system-config-samba

On prompting enter your password to start the download and install process.

Now create the users who you wish to use the shared folders. Say, I want a user shareuser1 to access the shared folder from anywhere on the network. In such a case I will have to create the user shareuser1 on the machine having the shared folders and then connect to the share from other machines on the network using the username shareuser1.

For this tutorial I will create 8 such users.

sudo useradd -m shareuser1
sudo useradd -m shareuser2
sudo useradd -m shareuser3
sudo useradd -m shareuser4
sudo useradd -m shareuser5
sudo useradd -m shareuser6
sudo useradd -m shareuser7
sudo useradd -m shareuser8

To check if the users are successfully created, check the /etc/passwd file

cat /etc/passwd

cat /etc/passwd

If the usernames are not mentioned here, then something went wrong. Read the man useradd page in the terminal and do the needful. If you get the output similar to the above then go ahead.

Let us assign the newly created users to various groups as follows.

shareuser1, shareuser2  in sharegroup1
shareuser1, shareuser2, shareuser3  in sharegroup2
shareuser4, shareuser5, shareuser6  in sharegroup3
shareuser4, shareuser7, shareuser8  in sharegroup4
shareuser2, shareuser5, shareuser6  in sharegroup5

First create the groups using sudo groupadd <groupname>.

sudo groupadd sharegroup1
sudo groupadd sharegroup2
sudo groupadd sharegroup3
sudo groupadd sharegroup4
sudo groupadd sharegroup5

Now assign users to these groups using the format sudo usermod -G <group list separated by comma(,)> <username>.

sudo usermod -G sharegroup1,sharegroup2 shareuser1
sudo usermod -G sharegroup1,sharegroup2,sharegroup5 shareuser2
sudo usermod -G sharegroup2 shareuser3
sudo usermod -G sharegroup3,sharegroup4 shareuser4
sudo usermod -G sharegroup3,sharegroup5 shareuser5
sudo usermod -G sharegroup3,sharegroup5 shareuser6
sudo usermod -G sharegroup4 shareuser7
sudo usermod -G sharegroup4 shareuser8

Check if the groups are properly assigned to each user using the format groups username. Here I show it for shareuser2.

groups shareuser2

Output :

groups shareuser2

To enable a user to use a share, an entry must be made in the local smbpasswd file. For each user we create a such an entry using sudo smbpasswd -a <username>.

sudo smbpasswd -a shareuser1
sudo smbpasswd -a shareuser2
sudo smbpasswd -a shareuser3
sudo smbpasswd -a shareuser4
sudo smbpasswd -a shareuser5
sudo smbpasswd -a shareuser6
sudo smbpasswd -a shareuser7
sudo smbpasswd -a shareuser8

Output:

sudo smbpasswd -a shareuser1

sudo smbpasswd -a shareuser1

Now that the users and groups are set up, we can move to configuring Samba. Make sure that the partitions consisting the folders to be shared are mounted with proper permissions. You may read the post on Auto-mounting NTFS partitions at boot time. Before configure the shares, I suggest to backup the original samba configuration file.

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bkp

We are now ready to configure our shares.

Start the terminal and open the smb.conf file. This file consists the configuration for the shares.

sudo nano /etc/samba/smb.conf

Go to the end of this file (Shortcut : press and hold Ctrl+v till you reach the end of the file). Use the following skeleton to configure the shares.

[Share-name] # A name that you want to display for this share
<tab>path = # path to the folder to be shared
<tab>valid users = # list of valid users. ( ex. @administrators, @users, administrator ). Those starting with @ are groups.
<tab>writeable = # yes/no
<tab>browseable = # yes/no
<tab>read list = # list of users and groups who are allowed to read this share.
<tab>write list = # list of user and groups who are given permission to write to this share.
<tab>guest ok = # yes/no
 

You may refer SambaConf file as a complete guide for shares and available options. In my case I want permissions to various shares as follows.

/media/sda7/Videos to be readable by sharegroup1 and writable by shareuser1.

/media/sda7/Docs to be readable by sharegroup2, sharegroup3, sharegroup4, sharegroup5 and writable by sharegroup3 and shareuser1.

/media/sda6/Pics to be readable by sharegroup5, shareuser7 and writable by shareuser7.

/media/sda6/Desktop to be readable to all.

To achieve the this I add the following lines to the end of /etc/samba/smb.conf file.

[Videos]
    path = /media/sda7/Videos/
    valid users = @sharegroup1, shareuser1
    browseable = yes
    writeable = yes
    read list = @sharegroup1, shareuser1
    write list = shareuser1
#    guest ok =

[Docs]
    path = /media/sda7/Docs/
    valid users = @sharegroup2, @sharegroup3, @sharegroup4, @sharegroup5, shareuser1
    browseable = yes
    writeable = yes
    read list = @sharegroup2, @sharegroup3, @sharegroup4, @sharegroup5, shareuser1
    write list = shareuser1, @sharegroup3
#    guest ok =

[Pics]
    path = /media/sda6/Pics/
    valid users = @sharegroup5, shareuser7
    browseable = yes
    writeable = yes
    read list = @sharegroup5, shareuser7
    write list = shareuser7
#    guest ok =

[Desktop]
    path = /media/sda6/Desktop/
    browseable = yes
    writeable = no
    guest ok =yes

Here’s my attached smb.conf file. Now restart the samba service.

sudo service smbd restart

And you are done!!! You should be able to access your shares from your Windows as well as Linux machines, giving the correct username and password for the shares in mapping the network drive. :-)

Note : To remove a user from the local smbpasswd file enter the command

sudo smbpasswd -x shareuser1

To remove a user account from your system enter,

sudo userdel -r shareuser1

To remove a group, enter

sudo groupdel sharegroup1

:-) :-) :-)

You may also have a look at a helpful suggestion by Emre.

Follow

Get every new post delivered to your Inbox.

Join 68 other followers