How to delete .svn folders recursively

There is a very simple way of doing this. We use the find command to get all the s/.v .svn folders in a folder. The next step is to pass the output of this command to the delete command .

So  to list all .svn folders in the current folder:

find . -type d -name .svn

Next pass the output of this to the rm command by enclosing the find command in accented single quotes:

rm -rf `find. -type d -name .svn`
Posted in FreeBSD Unix by amit. No Comments

Checklist of applications to install

A reference list of all installed apps required for use on FreeBSD 8.0 or later

abiword - Word processing application

aterm - Better alternative to xterm

firefox - browser

fluxbox - window manager

filezilla - ftp client

gcolor2 - color picker utility

gkrellm - system monitoring util

linux-base-f10  - fedora linux compatibility base libraries

linux-f10-flashplugin - flash plugin for firefox and other browsers

mysql 5.x - mysql server and client

apache22 - apache http server

php5.x - php

opera - browser

portsnap - port updater tool

portaudit - port security tool

portmaster - port installer

putty - ssh tool

subversion - svn version control

vim - editor

xpdf - pdf viewer

xnview - image capture and processing utility

ffmpeg - audio/video conversion tool

xmms - mp3 player

mplayer - video player

Posted in FreeBSD Unix by amit. No Comments

Spara beta version is launched

We have beta launched Spara - a free online service for taking backups of your Facebook data. This should be a godsend for people who have a lot of data in their Facebook profiles.

Spara is available here

Spara - Save your Facebook

Spara - Save your Facebook

Posted in Misc by amit. No Comments

Recovering from a corrupt rc.conf

Sometimes we may make a mistake in the rc.conf file - either a syntax error or loading something which causes the system to crash. In such a case we need to fix the rc.conf file so that the system can boot normally.

The steps to do this are given below:

  • Boot into single user mode
  • When prompted for a shell pathname,  press Enter
  • Type mount -urw / to re-mount the root file system in read/write mode.
  • Type mount -a -t ufs to mount the current file system so that you can runyour preferred editor eg. vi
  • Edit /etc/rc.conf as required and save it
  • Restart the system
Posted in FreeBSD Unix by amit. No Comments

Apache post-install issue with mod_unique_id

If after installing Apache and starting the server the following message shows in the error logs and the apache server does not start:

hostname nor servname provided, or not known: mod_unique_id: unable to find IPv4 address of xxxxxx

then in httpd.conf disable the line

LoadModule unique_id_module libexec/apache2/mod_unique_id.so

Restart again. This is usually the fix if changing hosts and httpd.conf ServerName entries etc. do not fix the problem.

Posted in FreeBSD Unix by amit. No Comments

Installing Mysql 5.x

The commands are given below. Though this was used to install mysql 5.5.4 , it is applicable to older versions also (and perhaps newer ones as well).

cd /usr/ports/databases/mysql55-server/
make install clean
/usr/local/bin/mysql_install_db
chown -R mysql /var/db/mysql/
chgrp -R mysql /var/db/mysql/
/usr/local/bin/mysqld_safe –user=mysql &
/usr/local/bin/mysqladmin -u root password newpassword

Edit /etc/rc.conf to start mysql server at startup by putting the line

mysql_enable=”YES”

After this, restart FreeBSD.

Posted in FreeBSD Unix by amit. 1 Comment

Setting Background Wallpaper in Fluxbox

First of all you need images to show as wallpaper. You can easily get them from various wallpaper sites on the web. Make sure you store the files in a single directory - you can organize them into sub-directories if there are too many.

Install feh which is an application for viewing images. This is in /usr/ports/graphics .
There are other wallpaper setting applications which can be used:

  • Esetroot
  • wmsetbg
  • feh
  • hsetroot
  • chbg
  • display
  • qiv
  • xv
  • xsri
  • xli
  • xsetbg

Once installed, run fbsetbg (fluxbox set background) . Run it first with fbsetbg -i which makes sure that there is a suitable application to set the wallpaper. You can now set the background wallpaper by using the command

fbsetbg -f /path/to/graphic/file

Eg. fbsetbg -f /var/data/wallpaper.jpg

You can even specify wildcards and fbsetbg will set the first matching file as the wallpaper.

Given below is a sample full-blown fluxbox installation.

screen_lynucs_46828721040bd81f35dc42_2

Posted in FreeBSD Unix by amit. No Comments

Always Keep root shell as part of base OS

Most people keep bash as their preferred shell program in FreeBSD. The problem with bash is that it does not come as part of the default FreeBSD package - it has to be installed as a third party application either using pkg_add or by compiling it from ports.

chsh -s /usr/local/bin/bash

If for some reason your ports tree has corruption or the bash port or a supporting port has not been updated properly, you might get locked out from the system the next time you try to log in. The problem would be that root uses bash for login and bash is not working in the ports so you can’t get in.

The way around such a case is to log in to single user mode and set the root shell back to something like sh or tcsh.

To prevent such a thing from happening in the first case, always keep the root shell as something which is not dependent on third party libraries. If you must keep bash then link it statically from ports by specifying WITH_STATIC_BASH during building.

My own preference is install bash but keep csh as the root shell. Once I have logged in to root, I manually run bash and then continue using bash.

Posted in FreeBSD Unix by amit. No Comments

Installing FreeBSD over an old installation

A crucial part in installing FreeBSD again over a corrupt or existing FreeBSD installation is knowing how to recreate the disk partitions. By default, even if you change the disk geometry and slicing configuration, the actual changes will be written to the disk, only when installation of files is about to start.

In such a case, if your existing partitions have data, you may very well end up with a situation where FreeBSD says that there is not enough space to install the new files.

To make FreeBSD ignore existing data on the disk, once you have completed configuration press W either in the FDisk screen or in the Disk Labelling screen.

FDisk Screen

FDisk Screen

W is not a key that is listed in the help commands but it works. It ‘W’rites the new disk configuration to the disk and thereby invalidates all existing partition configuration and data.
screen_disk_label

FreeBSD will warn you once before committing the Write. For obvious reasons, this step should not be taken if you are installing FreeBSD for the first time in your disk.

Posted in FreeBSD Unix by amit. No Comments

How to embed a Google map in a Wordpress blog

Overview

I get a lot of requests from people who want to put up a google map in their blog (which most of the time is Wordpress) but they have no idea how to do it. Unlike embedding  a google map in a standard web page ,  a simple pasting of the map script will not work in Wordpress.

The best way to show a google map as part of a Wordpress blog post is to make it a Wordpress Plugin. For most non developers, creating a Wordpress plugin is simply not worth the trouble as it takes too much knowledge of PHP and the Wordpress API . For PHP developers who are proficient in PHP but have never worked with Wordpress code before, the task of making a WP plugin can be a little daunting at first. It takes some time and some trial and error to understand how a WP plugin works.

For both the above kinds of people I thought it would be a good idea to create a simple Google map plugin for WP which can be used by anyone who just wants to show a map in WP. This basic plugin can also form a base for creating a more complex map plugin if required.

It is assumed the reader already knows how to paste a google map in a standard web page. I am just going to deal with the basics of writing a WP plugin and how to plug the google map into it.

gmaphomepage

The Plugin Deployment

The plugin has the following files :

  • index.php - this is the main plugin file
  • showmap.php - this is the code which actually displays the map
  • /includes/globals.php - some global variables required by the plugin
  • /includes/scripts.js - the javascript to control the map display via Google Maps API

The plugin is available as downloadable zip file here. To install the plugin in your WP blog

  • Unzip the contents of the zip in the wp-content/plugins directory.
  • After unzipping all the files should have gone into a folder called wp-content/plugins/gmapplugin.
  • Edit the file globals.php in the includes folder and change  $g_docRoot to reflect the base path of your gmapplugin folder , change the $g_serverName to reflect the domain name of the website, $g_map_key to reflect the google map api key for your domain.
  • Go to wp-admin, login as admin , go to the Plugins page and activate the plugin.
  • After this, the homepage, all the posts and all the pages should show the sample map alongwith whatever original content is present.

How It Works

The main plugin file is index.php. The entire plugin is created as a class which gets instantiated only once. This class can have any methods or atrributes that is required. WP does not place any restrictions on the internal functioning of the class.

In our class we have defined a method called loadData which gets called in the constructor. For now this method does nothing but can be used to run any initialization tasks required for the class to function.

The main method which handles the displaying of the map is showMap(). This method acts as the main point of contact between the WP blog and the Google map. There are a few WP functions which are used in this function. They are explained below:

  • get_bloginfo(’wpurl’) gets the base url of the WP blog
  • $post->post_type returns either “post” or “page” depending on what the current content is . This helps you distinguish between the two kinds of content in WP.
  • is_home() returns a true or false depending on whether the current page is the homepage or not.

The showMap() checks whether the current page is the homepage or a post or a content and then shows the map in all three cases.

        function showMap($content) {
           global $post;
            $url = get_bloginfo('wpurl');// this is to get the current WP base url
                    // check if this is a post
            if ($post->post_type == "post" && !is_home()) {
                $more_content = file_get_contents($url . "/wp-content/plugins/gmapplugin/showmap.php");
                return $more_content. $content ;
            }
                    // other pages and not homepage
            if ($post->post_type == "page" && !is_home()) {
                $more_content = file_get_contents($url . "/wp-content/plugins/gmapplugin/showmap.php");
                return $more_content . $content;
            }
            else {
                    // show map in homepage
                    if (is_home()) {
                    $more_content = file_get_contents($url . "/wp-content/plugins/gmapplugin/showmap.php");
                return $more_content. $content ;
                  }
            }
            return $content;
        }

There is a function at the bottom of index.php called add_filter(’the_content’, array(&$GMS, ’showMap’));

This is an inbuilt WP function which adds third party code to its event queue or processing pipeline. This line tells it to add this class into the list of classes which will filter “the content”

Enhancements and Changes

It is unlikely that anyone would want to show a map in every post or page. To fix that, you can filter on the $post->ID for showing maps only if particular posts are shown.

You can also filter on custom fields added to the post while editing it. This can be done using get_post_meta($pageId, ‘custom_field_tag’, true) . If the current post has this particular custom field value then it will return true and the map can be shown.

Posted in Maps Programming by amit. No Comments