Jun 27

I wrote a super simple script to fix some issues I have with some defaults in the latest Ubuntu release.  Nothing majour here, just annoyances really.  Below is the script, read it and comment out any lines you do not want to take effect on your system. It requires root access for a few of the commands, such as managing packages and removing system-wide files. Run it as a regular user and the sudo command will be used to prompt you for a password, run like this:

$ chmod +x ubuntu-fix.sh
$ ./ubuntu-fix.sh

And the following is the source code or download the script here.

#!/usr/bin/env bash
 
#
# Simple script to remove some of what I consider to be annoyances with
# Ubuntu 10.04 Lucid Lynx (and probably future versions).
#
 
set -e
 
# keep location bar always visible instead of breadcrumbs
gconftool-2 --set '/apps/nautilus/preferences/always_use_location_entry' \
    --type bool 'true'
 
# move buttons to the correct side and add menu on left icon
gconftool-2 --set '/apps/metacity/general/button_layout' --type string \
    'menu:minimize,maximize,close'
 
# make fonts a reasonable size
gconftool-2 --set '/desktop/gnome/interface/font_name' --type string 'Sans 9'
 
# remove the poorly named and useless (to me) "ubuntuone" client package
if [ `dpkg -s ubuntuone-client | grep -c 'not-installed'` -ne 1 ]
then
    sudo apt-get remove --yes --purge ubuntuone-client
    sudo rm -f /etc/xdg/autostart/ubuntuone-launch.desktop 
fi
 
# remove the panel thing with email and other icons with wrong bg color
if [ `dpkg -s indicator-applet | grep -c 'not-installed'` -ne 1 ]
then
    sudo apt-get remove --yes --purge indicator-applet
    sudo rm -f /etc/xdg/autostart/indicator-applet.desktop 
fi
 
# add the regular volume icon back at startup
if [ ! -f /etc/xdg/autostart/gnome-volume-control-applet.desktop ]
then
    sudo cat /etc/xdg/autostart/gnome-volume-control-applet.desktop<<EOF
[Desktop Entry]
Name=Volume Control Applet
Comment=Show desktop volume control
Icon=multimedia-volume-control
Exec=gnome-volume-control-applet
Terminal=false
Type=Application
Categories=
NoDisplay=true
OnlyShowIn=XFCE;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gnome-media
X-GNOME-Bugzilla-Component=gnome-volume-control
# See http://bugzilla.gnome.org/show_bug.cgi?id=568320
#X-GNOME-Autostart-Phase=Panel
X-GNOME-Autostart-Notify=true
X-GNOME-Autostart-Delay=2
X-Ubuntu-Gettext-Domain=gnome-media-2.0
EOF
fi
 
# offer to logout
echo -n "Done fixing Ubuntu, you need to log out and log back in for some of \
the changes to take effect.  
 
Log out now? [y/N] "
read DOLOGOUT
if [ ! -z $DOLOGOUT ] && [ $DOLOGOUT == "yes" ] || [ $DOLOGOUT == "y" ] || \
        [ $DOLOGOUT == "YES" ] || [ $DOLOGOUT == "Y" ]
then
    /usr/bin/gnome-session-save --kill
fi
  • Share/Bookmark
Sep 27

I’m posting this for anyone who’s had a hard time getting Mapnik installed
along with some handy utilities on Ubuntu 9.04. Here we go.

Mapnik from Source

Update the package listing and then upgrade all packages:

apt-get update
apt-get upgrade

After that install the dependencies:

sudo apt-get install g++ cpp \
libboost1.35-dev libboost-filesystem1.35-dev \
libboost-iostreams1.35-dev libboost-program-options1.35-dev \
libboost-python1.35-dev libboost-regex1.35-dev \
libboost-thread1.35-dev \
libxml2 libxml2-dev \
libfreetype6 libfreetype6-dev \
libjpeg62 libjpeg62-dev \
libltdl7 libltdl7-dev \
libpng12-0 libpng12-dev \
libgeotiff-dev libtiff4 libtiff4-dev \
libcairo2 libcairo2-dev python-cairo python-cairo-dev \
libcairomm-1.0-1 libcairomm-1.0-dev \
ttf-dejavu ttf-dejavu-core ttf-dejavu-extra \
libgdal1-dev python-gdal \
postgresql-8.3-postgis postgresql-8.3 \
postgresql-server-dev-8.3 postgresql-contrib-8.3 \
libsqlite3-dev  \
subversion build-essential

Now we need to get the Mapnik source from the repository:

mkdir -v ~/src
cd ~/src
svn co http://svn.mapnik.org/trunk mapnik
cd mapnik

After that we can configure and build Mapnik:

python scons/scons.py configure INPUT_PLUGINS=all \
OPTIMIZATION=3 \
SYSTEM_FONTS=/usr/share/fonts/truetype/ttf-dejavu/
python scons/scons.py
sudo python scons/scons.py install
sudo ldconfig

Now we’ll do a quick test to see if Mapnik installed correctly:

python # will start the python interpreter
>>> import mapnik
>>> exit()

If the import mapnik line didn’t spit out any errors, everything is probably ok.


Setting Up the Database

First we need to tweak some configuration files. Open
/etc/postgresql/8.3/main/postgresql.conf with your favourite
text edit and modify the following lines:

shared_buffers = 128MB
checkpoint_segments = 20
maintenance_work_mem = 256MB
autovacuum = off

Next edit /etc/sysctl.conf and add the following at the end:

kernel.shmmax=268435456

Now to avoid a reboot, we’ll update the kernel like this:

sudo sh -c 'echo 268435456 >/proc/sys/kernel/shmmax'

Then restart the PostgreSQL server:

sudo /etc/init.d/postgresql-8.3 restart

The next thing we need to do is create the database. Substitute
your_user” below with your user name. Note: If your user name is ‘user’ you might get an error from the commands below, I did when I tried.

sudo -u postgres -i
createuser -s your_user
createdb -E UTF8 -O your_user gis
createlang plpgsql gis
exit

Now setup PostGIS on our database:

psql -d gis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql

And then change some permissions on the database:

echo "ALTER TABLE geometry_columns OWNER TO your_user; ALTER TABLE spatial_ref_sys OWNER TO your_user;" | psql -d gis

Now we’ll enable the intarray module:

psql gis < /usr/share/postgresql/8.3/contrib/_int.sql

Installing Some Extra Tools

The tools we’ll be installing here are useful for working with OpenStreetMap
data and also to facilitate generating maps with Mapnik.

OSM2PGSQL

This utility will import OpenStreetMap data files into the PostGIS database. First we’ll install some dependencies:

sudo apt-get install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev proj

And then checkout the latest version from the repository:

cd ~/src
svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/
cd osm2pgsql
make

Mapnik-Tools

We’re going to put this right in our home directory:

cd ~
svn co http://svn.openstreetmap.org/applications/rendering/mapnik/

Setting up the World

Now we’re going to grab some boundaries data for the world.

cd ~/mapnik
wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz
wget http://tile.openstreetmap.org/processed_p.tar.bz2
wget http://tile.openstreetmap.org/shoreline_300.tar.bz2

We’ll extract them each into ~/mapnik/world_boundaries:

tar xfv world_boundaries-spherical.tgz
rm -v world_boundaries-spherical.tgz
mv -v processed_p.tar.bz2 shoreline_300.tar.bz2 world_boundaries/
cd world_boundaries
tar xfv processed_p.tar.bz2
tar xfv shoreline_300.tar.bz2
rm -v processed_p.tar.bz2 shoreline_300.tar.bz2

Importing Some Data

The last thing we’re going to do is put some OpenStreetMap data into our database. You can either import the whole planet:

cd ~
wget http://ftp.heanet.ie/mirrors/openstreetmap.org/planet-latest.osm.bz2

But it’s a HUGE file, so if you just want to have a smaller part of the world,
you can use extracts. To create your own extracts, read this tutorial. Otherwise
grab an extract for your area of interest from somewhere (ex.CloudMade). You’ll want to download the file ending in .osm.bz2. In my example I’ll be using british_columbia.osm.bz2.

cd ~
wget http://downloads.cloudmade.com/north_america/canada/british_columbia/british_columbia.osm.bz2

We just need to import the data into the database now, for this we’ll use osm2pgsql which we installed earlier.

cd ~/src/osm2pgsql
./osm2pgsql --slim -d gis ~/british_columbia.osm.bz2

And there you have it. If you want to test this out from the command line, you
can use the last portion of this tutorial, or to use python, try the examples here.

Resources

Most of this tutorial was ripped directly off from the following sites:

  • Share/Bookmark
Sep 26

I made a Debian/Ubuntu package for Mapnik v0.6.1. There’s a 32-bit and 64-bit package. I’ve only tested it on Ubuntu 9.04, but it will probably work on Debian.

To install it download the package and type:

sudo dpkg -i mapnik_0.6.1-1_i386.deb

Then when it complains about dependencies, type:

sudo apt-get install -f

To install all the dependencies and finish the install. Sorry I don’t have a repository to put this package in.

I think if you use GDebi Installer it will do everything in one step.

Note: There are lots of dependencies (~500MB on a clean Ubuntu alternate install), I used those listed here. I tried removing all the -dev packages and anything else that looked like it was just for compiling, but it didn’t work.

UPDATE: I’ve also made an osm2pgsql package from the latest subversion copy. Download it here.

Enjoy

Download the Mapnik v0.6.1 x86 Package Here

Download the Mapnik v0.6.1 amd64 Package Here

  • Share/Bookmark
Sep 20

As part of one of my current projects, maptop, I needed a simple module to detect whether or not a GPS receiver is connected to the computer, and if so, which port is it connected to.

For the task, I used PySerial, along with some of their example code, to test if each serial port can be opened, and if so, if there are NMEA GPS sentences coming in on it.  It uses a fixed baud rate of 4800, which is what my receiver is using and is also specified here.  The timeout of 2 seconds seems to work (at least with my device).  Both the baud rate and the timeout can be changed by modifying the BAUD_RATE and TIMEOUT “constants” at the top of the script.

I’m not sure if this works on Windows or not, I haven’t tested it yet, but it *should work*.

Below is the code for the module:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# 
# Copyright 2009 Matthew Brush < mbrush AT leftclick DOT ca >
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
 
__version__ = "0.1"
__all__ = [ 'get_gps_port', 'test_port' ]
 
import serial
import glob
import re
import platform
 
BAUD_RATE = 4800    # the standard nmea baud rate
TIMEOUT = 2         # time to wait for nmea sentences
 
class NoGpsReceiverError(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)
 
def scan():
    """ Scan for available ports. return a list of device names. """
    if platform.system == 'Windows':
        import scanwin32
        ports = []
        for order, port, desc, hwid in sorted(scanwin32.comports()):
            ports.append(port)
        return ports
    else:
        import scanlinux
        return scanlinux.scan()
 
 
def test_port(port):
    """ Detects whether NMEA GPS sentences can be read from the port. """
    nmea_gps_pattern = '^\$GP[A-Z]{3},'
    gps_detected = False
    try:
        s = serial.Serial(port, BAUD_RATE, timeout=TIMEOUT)
        for i in range(1,10):   # try 10 lines in a row
            line = s.readline().strip()
            m = re.match(nmea_gps_pattern, line)
            if m:
                gps_detected = True
                break
        s.close()
        return gps_detected
    except serial.SerialException:
        return False
 
def get_gps_port():
    """ Looks for GPS data coming in on any serial port and returns the port name. """
    for port in scan():
        if test_port(port):
            return port
    raise NoGpsReceiverError('Unable to locate a suitable GPS receiver.')
 
def main():
    print "Testing ports to find GPS receiver..."
    try:
        if platform.system == 'Windows':
            print "  Warning: gpsdetect not tested in Windows yet."
        for port in scan():
            if test_port(port):
                print "Detected GPS receiver on '" + port + "'."
                found_gps = True
                break
    except NoGpsReceiverError:
        print "No GPS receivers were detected on the system."
 
 
if __name__ == '__main__': main()

The complete source can be downloaded here.

  • Share/Bookmark
Sep 15

I finally got so fed up of my Samba shares not being accessible after a while that I did some digging around. One of my 3 external USB drives attached to my file server keeps going to sleep, which sounds like a good thing. What happens, however, is when I attempt to access the shares from my Windows machine, I get a “Not Accessible” error and I can no longer use any of my Samba shares.

My file server is running Ubuntu 9.04 and all the drives are mounted under /media, then each important directory from each drive is symlinked to a sub directory of /media/shared, and /media/shared is the Samba share. This is convenient because it allows my file server, which has 5 various sized disks and attachments, to appear as one huge drive on the network. I’m not sure if this is why the one sleepy drive is bringing down the whole share or not.

To resolve the issue, I keep having to SSH into my file server, run a command such as fdisk -l to access the drive(s) and then restart Samba. There is a noticeable delay when fdisk -l hits that one sleepy drive while it spins up. My super simple hack to prevent this drive from spinning down, even though I’d rather let it sleep and wake on its own, is this:

$ sudo crontab -e

Then I added the following line to the cron tab file:

5 * * * * fdisk -l >/dev/null 2>&1

This will issue the fdisk -l command every 5 minutes, dumping the fdisk output to neverland. The idea is to access the drive every once in a while to prevent it from going to sleep. I expect to do some tweaking on the 5 minutes part, in an attempt to run the job less frequently, but still enough to keep the drive awake.

It’s an ugly hack and I’m sure there’s something I could do with hdparm if I spent some more time on it, but whatever. It’s only me accessing the file server and the performance is not very critical.

If you do know of slicker way of doing this, drop a comment and let me know.

  • Share/Bookmark
Sep 14

I’m pretty excited I got my USB GPS receiver in the mail today.  It’s even small enough that Canada Post was able to fit it into my small apartment mailbox.  No going to the depot to pick it up!  It’s a little bit larger than I would have thought, but still pretty small (about 1.5 x the size of regular USB thumb drive).  Here is a picture of it:

It took me all of 5 minutes to get it running in Ubuntu.  All you need to do is enable the Prolific Serial to USB module called pl2303.  After that, you need to set the baud rate to 4800 and off you go.  Here is a quick list of the commands required to get this receiver running:



$ sudo modprobe pl2303
$ sudo echo "pl2303" >> /etc/modules
$ dmesg
... lots of output snipped ...
[ 1003.292048] usb 2-1: new full speed USB device using uhci_hcd and address 3
[ 1003.496629] usb 2-1: configuration #1 chosen from 1 choice
[ 1003.499558] pl2303 2-1:1.0: pl2303 converter detected
[ 1003.519282] usb 2-1: pl2303 converter now attached to ttyUSB0
$ stty 4800 < /dev/ttyUSB0
$ cat /dev/ttyUSB0
... press Ctrl+C to stop reading from the device

That’s all there is to it! Now I’m off to write a Python script to set the baud rate, read the output, and parse it into something more useful. After that I can start working on integrating it into the GPS applications I just started writing (more on this in a later post).

More Information:

  • Share/Bookmark
Sep 11

I’ve had this super simple “Web Service” up on my other website for some time now, and I’ve used it fairly often through the browser and in scripts. I decided to make an even simpler one on CodeBrainz.ca for others and myself to use. The old service returned a single-node XML document, which is basically pointless and just adds a tiny bit of complexity on the client who is using it. The new address of the service is:

http://showip.codebrainz.ca

The actual code for the new service is a whopping 1 line of code:

<?php
 
echo $_SERVER['REMOTE_ADDR'];
 
?>


I’ve whipped up a couple ultra simple apps and a pointlessly simple library to save writing a few lines of code. The bash script is for for *nix-style systems while the .NET binaries are for Windows/.NET/Mono.

Here are links to each file:

I hope someone out there finds this simple service as useful as I have.

  • Share/Bookmark
Sep 11

I’m posting this table here mostly for my own reference but also for anyone else that might find it handy. I can’t count how many times I’ve searched for these values. To use the table, find the desired resolution, and find the corresponding color depth and that will be the value you need to put in your bootloader to get the kernel to boot with the non-default resolution.

For example in GRUB, open the config. file (in Debian/Ubuntu it’s at /boot/grub/menu.lst in most cases). Find the line that corresponds to the kernel you want to use the new resolution, and at the end of the line, add vga=XXX where XXX is a value from the table below. When you’re putting the video mode into the bootloader, use decimal and it will be converted to hex for the kernel.

Colours System 640×400 640×480 800×600 1024×768 1152×864 1280×1024 1600×1200
4 Hex - - 0×302 - - - -
Dec 0 0 770 0 0 0 0
8 Hex 0×300 0×301 0×303 0×305 0×161 0×307 0×31C
Dec 768 769 771 773 353 775 796
15 Hex - 0×310 0×313 0×316 0×162 0×319 0×31D
Dec 0 784 787 790 354 793 797
16 Hex - 0×311 0×314 0×317 0×163 0×31A 0×31E
Dec 0 785 788 791 355 794 798
24 Hex - 0×312 0×315 0×318 - 0×31B 0×31F
Dec 0 786 789 792 0 795 799
32 Hex - - - - 0×164 - -
Dec 0 0 0 0 356 0 0


Key: 8 bits = 256 colours, 15 bits = 32,768 colours, 16 bits = 65,536 colours, 24 bits = 16.8 million colours, 32 bits - same as 24 bits, but the extra 8 bits can be used for other things, and fits perfectly with a 32 bit PCI/VLB/EISA bus.

Additional modes are at the discretion of the manufacturer, as the VESA 2.0 document only defines modes up to 0×31F. You may need to do some fiddling around to find these extra modes.

Source: http://tldp.org/HOWTO/Framebuffer-HOWTO-5.html#ss5.3

  • Share/Bookmark
Sep 06

Not sure why there isn’t a whole lot of information on doing this, but I wanted to install Ubuntu 9.04 using the Alternate CD on my EeePC using a USB drive, so here’s a little guide for preparing the installation USB drive.  Hopefully someone out there will also find it useful.  Don’t hesitate to ask if you have any question about installing Ubuntu this way.

What you need:

  • The hd-media image for Jaunty
  • The Ubuntu Alternate CD ISO Image (x86 or AMD64)
  • A USB drive that will be completely erased, so back it up first
  • A computer running Ubuntu (or other GNU/Linux distro)


The Process:

I’m assuming the person following this guide is fairly comfortable with the command line and knows how to determine which device your USB drive is detected as.  If you don’t know how to do this, Google is your friend.  I’ll only warn about this once, but if you don’t get the right device name, there is a possibility that you will screw up one of your other partitions, possibly hosing your whole system, or at least wiping the wrong partition.  On my system the USB drive is detected as /dev/sdb so I will use this in my example, obviously substitute whatever you USB drive is detected as.  CONTINUE AT YOUR OWN RISK!

We’re going to do this as root, so be careful!

sudo su		# enter your password

Then we’ll setup a temporary location to do our thing in.

mkdir /tmp/altinst && cd /tmp/altinst

Now we’ll download the required files, the hd-media image and the Alternate CD image.

wget http://archive.ubuntu.com/ubuntu/dists/jaunty/main/installer-i386/current/images/hd-media/boot.img.gz
wget http://mirror.csclub.uwaterloo.ca/ubuntu-releases/9.04/ubuntu-9.04-alternate-i386.iso

Note that I’m using a Canadian mirror, feel free to choose another mirror closer to you if you want. They are listed on this page.

The next thing is to erase and prepare the USB drive. This isn’t really necessary if your USB drive already has a single FAT partition that is empty.

Start by blowing away any existing partition table on the disk.

dd if=/dev/zero of=/dev/sdb bs=1M count=1

I’m using cfdisk here to do the partitioning, but use whatever program you want (ex, fdisk, sfdisk, etc).

cfdisk /dev/sdb

Using the cfdisk program, create a single primary partition and set its type to 0c (FAT32 LBA). After the partition is created we’ll format it.

mkfs -t vfat /dev/sdb1

Ok, so now that we have a nice clean USB drive with a single FAT partition, we’ll copy the hd-media image onto the USB drive.

zcat boot.img.gz >/dev/sdb1

Now we’re almost done, we just need to copy the Alternate CD image onto the drive. First we’ll mount the partition.

mount /dev/sdb1 /mnt

Then we’ll copy the image to the USB drive.

cp ubuntu-9.04-alternate-i386.iso /mnt/

That’s it! You now have USB drive that you can use to install the Ubuntu Alternate CD without a CDROM drive.

You can now delete our working directory:

rm -r /tmp/altinst
  • Share/Bookmark

1,134 spam comments
blocked by
Akismet