Tag Archives: Linux

Switch BU-353 to NMEA mode

BU-353 is a nice little USB based GPS receiver that I use for several types of project. Straight out of the wraps it defaults to outputting NMEA data at 4800 baud which is exactly what I want. However, it also supports the SIRF binary protocol and may switch to that format. This can happen if you connect it to a system that uses gpsd. That daemon supports both the NMEA and the SIRF protocol but will switch the GPS to the latter if it can.

So how do you switch it back? Maybe you can just leave it be and the supercap inside will discharge and it will revert to its default settings. The FAQ kind of hinted at that. However, I wasn’t patient enough to see if that works so I needed a quicker option.

It turns out that if you use Windows it is not too difficult. You can follow any one of several guides on the net, for instance this, straight from the horse’s mouth.

But I needed a way to do this from Linux and this is how.

First make sure you have gpsctl in your path. If it is not installed you can install it by running:

sudo apt-get install gpsd-clients

I am doing this on an Ubuntu system but it should work on most Debian derivatives.

Then connect your BU-353 and type (assuming that your GPS device turns up at /dev/ttyUSB0):

sudo stty -F /dev/ttyUSB0 4800
sudo gpsctl -n -D 4 /dev/ttyUSB0

Then it should be back on NMEA.

Create bootable Ubuntu USB stick

I don’t create bootable USB sticks that often but every time I do it I think that it’s harder than it really is and start to search the web for walkthroughs.

This post could also simply be written: Look at the Ubuntu download page.

Here is the process for OS X:

  1. Download ISO file of the operating system you want to put on the USB stick
  2. Open the terminal
  3. Convert the ISO file using the convert option of hdiutil: hdiutil convert -format UDRW -o /path/to/target.img /path/to/source.iso
  4. Run diskutil list to get the current list of devices
  5. Insert the USB stick
  6. Run diskutil list again to determine the device node assigned to your USB stick
  7. Unmount the USB stick: diskutil unmountDisk /dev/diskN
  8. Write the image to the USB stick: sudo dd if=/path/to/disk.img of=/dev/rdiskN bs=1m
  9. Eject the USB stick: diskutil eject /dev/diskN

Using Drupal to run an intranet

I have been looking for ways to replace a Sharepoint driven intranet with something else. The driving force behind this has mainly been one of platform compatibility. Sharepoint is great if you use Office and Internet Explorer on Windows. For all other users it is a usability nightmare.

There are lots of hosted or shrink-wrapped solutions for sale but the market of intranet solutions is now so mature that I felt there had to be open source solutions.

I found Alfresco, LifeRay and a few others and installed most of them. I was perplexed, however, by the sheer amount of features that were enabled out of the box. I really prefer something that starts off light and can then expand according to my needs. KnowledgeTree felt lighter but didn’t do much more than document management and I knew I also wanted a wiki as well as forums.

For a while I tried to integrate KnowledgeTree with MediaWiki and phpBB for a best-of-breeds solution. I couldn’t get all of the them to play nicely together and allow users to authenticate using accounts from a Windows Active Directory.

drupalorg

In the end I settled on Drupal. Why? It starts off light but has a truck-load of modules that can be added. I like the structure of the code. And it feels fresh – perhaps almost too light. I would have liked to see some professional free themes targeted for intranets, they would have helped to sell in the concept internally in competition with professional offerings.

The question of the authentication integration with Active Directory was solved very nicely by the module “Webserver authentication” and adding HTTP authentication to the web site in Apache where the web server is configured to use the bindings provided by Samba‘s WinBind. The only thing to remember is to set the Drupal administrator to the the same login name as the administrator in the Windows domain. After that you should disable the log out menu option in Drupal. The only thing remaining is to add some Javascript code to be able to provide a link to make the browser forget the cookie in order to force a relogin.

Accessing an Oracle database from Perl

In the previous post I described how to install the Oracle Database 10g Express Edition on Ubuntu and to add some data. In this article I will show how to access that data from a Perl script.

I assume you already have Perl installed, together with the DBI framework for generic database support. We will need to add DBD::Oracle which is available from CPAN. To install this module, run this as root:

# perl -MCPAN -e shell
cpan> install DBD::Oracle

Two things are worth noting. First, the root user must have the same Oracle environment set as described in the previous article. Just issue ‘source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh’ to fix that. The second thing to note is that you will most likely get errors during testing of the newly built module which will prevent it from being installed. To override that you will need to add ‘force’ before the command, i.e.:

cpan> force install DBD::Oracle

Now, the groundwork is done and we just need to write the script. Save this in oracle_read.pl and make it executable.

#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect( 'dbi:Oracle:xe',
      'scott',
      'tiger',
      ) || die "Database connection not made: $DBI::errstr";

my $sql = qq{ SELECT id,name,age FROM persons };
my $sth = $dbh->prepare($sql);
$sth->execute();
my($id, $name, $age);
$sth->bind_columns(\$id, \$name, \$age);

print "List of persons:\n";
while( $sth->fetch() ) {
    print "$name [$age]\n";
}
$sth->finish();
$dbh->disconnect;

Oracle under Ubuntu

I am a rather proficient user of MySQL but I recently needed to set up an Oracle database to test against. Since I haven’t worked with Oracle databases in more than ten years it took literally hours to get something up and running. What follows is a description on how to install Oracle XE on Ubuntu 8.10, add a user, create a table and then drop the created schema. Everything will be done from the command line.

Note that this installs the Oracle Database 10g Express Edition. Although free it comes with similar constraints as the Microsoft SQL Server 2008 Express server – maximum 4 GB data, use maximum 1 GB of RAM and run on maximum 1 CPU.

First, add the Oracle repositories by appending the following two lines to /etc/apt/sources.lst

# Oracle Repository

deb http://oss.oracle.com/debian unstable main non-free

Then, we must add the Oracle key to avoid warnings:

wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | sudo apt-key add -

Now we are ready to install by using apt-get (either run the following as root or prepend every line with sudo)

# apt-get update
# apt-get install oracle-xe oracle-xe-client
# /etc/init.d/oracle-xe configure

The last command will present options to change some default settings. you can probably use most of the defaults. I just changed the HTTP port from 8080 since I already had another service running on that port. Note that the configuration script takes a very long time to finish.

When the script is finished it is possible to access the Oracle web interface at http://127.0.0.1:8080/apex (or some other port if you changed the default). However, it will only be accessible on the local host. If you are installing on a headless remote server like me you can port-forward using SSH:

$ ssh -L 8080:127.0.0.1:8080 user@host

Or, you can remove this limitation as described further below.

Next step will be to add the Oracle environment to your shell. The installation will have added scripts to set up the environment under /usr/lib/oracle/xe/app/oracle/product/10.2.0/. There are actually two scripts: server/bin/oracle_env.sh and client/bin/oracle_env.sh. I don’t think it matters which one but it makes more sense to use the one under ‘server’.

Append this to your .bash_profile file:

. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

Then log out and back in – or run ‘source .bash_profile’.

Now it is time to log onto the system:

$ sqlplus system@localhost 

If you would have logged on remotely you would have written ‘sqlplus system@host’ – but we haven’t enabled remote access yet.

Type the password you selected during installation. At the SQL prompt, enter:

> EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
> EXIT;

Now it is time to add the first user. Save the following to a file (oracle_create.sql).

-- oracle_create.sql
CREATE USER scott IDENTIFIED BY tiger 
    DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp 
QUOTA UNLIMITED ON users;
CREATE ROLE myrole;
GRANT CREATE session, CREATE table, CREATE view, 
    CREATE procedure, CREATE synonym TO myrole;
GRANT myrole TO scott;
-- Switch user
CONNECT scott@localhost/tiger;
--
CREATE TABLE persons (
	id int,
	name varchar2(32),
	age number
);
--
INSERT INTO persons
	(id, name, age)
	VALUES (1, 'Joe', 35);
INSERT INTO persons
	(id, name, age)
	VALUES (2, 'Mary', 32);

You can then create the user and populate the table by running:

$ sqlplus system@localhost
> @oracle_create
> SELECT * FROM persons;
> EXIT

The ampersand indicates that SQL statements should be read from a file. Since the file ends with .sql the extension does not have to be stated. Please note the connect statement in the SQL file. This means that after that point we will be running as the user scott.

To drop everything we have created run the following:

$ sqlplus system@localhost
> drop user scott cascade;
> drop role myrole;

Control Debian daemons

Debian and Ubuntu place startup files for all deamons in /etc/init.d. Symbolic links are then placed in /etc/rc.X to control when deamons are to be started and stopped. While it would certainly be possible to manage it manually, there are a few tools that makes life easier whenever you want to control which daemons are started by default.

Using rcconf

rcconf

Using sysv-rc-conf

sysv-rc-conf

Using update-rc.d

usage: update-rc.d [-n] [-f]  remove
       update-rc.d [-n]  defaults|multiuser [NN | sNN kNN]
       update-rc.d [-n]  start|stop NN runlvl [runlvl] [...] .
		-n: not really
		-f: force

Ubuntu 8.10 – libpolkit error

On a newly installed system with Ubuntu 8.10 you will see these kind of lines in /var/log/syslog:

Nov 24 01:12:31 sirius console-kit-daemon[9837]: CRITICAL: cannot initialize libpolkit

The error will repeat every ten minute or so and the fix to this issue is to install policy-kit, i.e.:

sudo apt-get install policykit

This is described in more detail on Launchpad: https://bugs.launchpad.net/ubuntu/+source/policykit/+bug/275432

VirtualBox and Ubuntu 8.04.1

When installing a Ubuntu 8.04.1 virtual guest under VirtualBox 2.06 running on a Mac you will probably be faced with the following error:

Starting up ...
This kernel requires the following features not present on the CPU:
0:6
Unable to boot - please use a kernel appropriate for your CPU.

This problem is due to the fact that the last couple of versions of Ubuntu have been compiled with PAE enabled – but the default guest setting of VirtualBox is that PAE is disabled. So to solve the issue, just stop the virtual guest and enable support in the CPU for PAE/NX, it’s under the advanced general settings. Another solution would be to reinstall the guest using the alternate CD image of Ubuntu (which, last time I checked, didn’t require PAE).