Sensible Shortcuts in Ubuntu

November 30, 2008 by John Jenkins · Leave a Comment
Filed under: Tools 

I find the standard shortcuts in Ubuntu fairly useless. They don’t take me to the location they point at in the way that (for example) Windows shortcuts do. Once you have followed a shortcut, you cannot traverse the directory tree as in Windows. If you followed a shortcut to /u/websites/blog and then went to the parent directory, rather than pointing at /u/websites you end up back at the desktop. Not helpful.

There is a way of getting reasonable shortcuts. You need to create a location launcher. First, right click on the desktop which will bring up the menu in figure 1. Select the Type: location and enter a name and a location as in figure 2. Once you have created the launcher, arrange it on the desktop.

Instructions on creating a launcher


You can edit the launcher’s details in a text editor after it has been created. It will be stored in $HOME/Desktop

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=pages
Type=Link
Icon[en_GB]=gnome-panel-launcher
URL=/u/websites/pages
Name[en_GB]=pages
Icon=/usr/share/pixmaps/gnome-folder.png

A Script for Creating Custom Wordpress Templates

November 26, 2008 by John Jenkins · 1 Comment
Filed under: Tools 

How many wordpress blogs have you created? If you’re an affiliate marketer I bet it is a few. Most of them start the same way by setting up wordpress, then adding a few plugins and then some themes. I use the same plugins and themes on all (three!) blogs so after going through the same steps for a third time I figured I would write a script.

As I didn’t want to write anything too complicated, the script depends on everything being in a particular location. It needs to be run from the same directory as the wordpress tarball and plugins and themes need to be in directories called plugins and themes respectively. Therefore, the directory structure will be:

wp-maker/
wp-maker/plugins
wp-maker/themes

When I looked at the files in my directory it looked like this:

$ find wp-maker/
wp-maker/
wp-maker/plugins
wp-maker/plugins/wassup.1.6.3.zip
wp-maker/plugins/google-sitemap-generator.3.1.0.1.zip
wp-maker/plugins/clean-archives-reloaded.zip
wp-maker/plugins/all-in-one-seo-pack.zip
wp-maker/plugins/stats.1.3.5.zip
wp-maker/extras.tar.gz
wp-maker/themes
wp-maker/themes/my-code-blue.tar.gz
wp-maker/make-tarball.sh
wp-maker/wordpress-2.7.tar.gz
$

The script also adds any files in a tarball called extras.tar.gz if present. You can download it here. Note: all code written by me in this blog is licensed under the GNU GPL which is the same license as Wordpress itself. The license states (amongst other things), you are free to use it but I provide no warranty and accept no liability. You can read the license here.


This function extracts files from either zipfiles or tarballs. It isn’t particularly important to understand how it works but if you’re interested, let me know in the comments.

extract_files()
{
    SOURCE=$1

    if [ ! -e "$SOURCE" ]; then
        return 1
    elif [ ! -z "`echo $SOURCE | egrep -i '\\.zip$'`" ]; then
        unzip $SOURCE
    elif [ ! -z "`echo $SOURCE | egrep -i '\\.gz$'`" ]; then
        gunzip -c $SOURCE | tar -xvf -
    else
        echo "Unrecognised filetype: $SOURCE"
    fi
}

Set up some useful variables including the list of themes and plugins that are present.

TOP=`pwd`
EXTRAS="$TOP/extras.tar.gz"

THEME_DIR=$TOP/wordpress/wp-content/themes
PLUGIN_DIR=$TOP/wordpress/wp-content/plugins

THEMES=`echo $TOP/themes/*.gz $TOP/themes/*.zip`
PLUGINS=`echo $TOP/plugins/*.gz $TOP/plugins/*.zip`
WORDPRESS=$1
if [ -z "$WORDPRESS" ]; then
    WORDPRESS=`echo wordpress*.tar.gz`
    if [ -z "$WORDPRESS" ]; then
        echo "Error: unable to find wordpress tarball"
        exit
    fi
    WORDPRESS="$TOP/$WORDPRESS"
fi
# Extract files from tarball
gunzip -c $WORDPRESS | tar -xvf -
if [ -e "$EXTRAS" ]; then
    gunzip -c $EXTRAS | tar -xvf -
fi
cd $TOP/wordpress
tar -cvf $TOP/wp-basic.tar *
gzip $TOP/wp-basic.tar
# Extract the required themes into the theme directory
echo "Info: Extracting themes"
cd $THEME_DIR
for theme in $THEMES; do
    extract_files $theme
done

# Extract the required plugins into the plugin directory
echo "Info: Extracting plugins"
cd $PLUGIN_DIR
rm hello.php
for plugin in $PLUGINS; do
    extract_files $plugin
done
# Create the final tarball
echo "Info: Creating the tarball"
cd $TOP/wordpress
find . -name RCS -type d | xargs rm -rf
tar -cvf $TOP/wp-starter.tar *
gzip $TOP/wp-starter.tar

My extras tarball contains the following shell script called init.sh which creates some handy files.

#!/bin/sh

# Create empty files that will be populated by wordpress later
touch .htaccess sitemap.xml sitemap.xml.gz
chmod 666 .htaccess sitemap.xml sitemap.xml.gz

Webserver Management using SSH

November 22, 2008 by John Jenkins · Leave a Comment
Filed under: Tools 

My webserver permits access via ssh or ftp. I like to use ssh and scp for the additional security. I could use a graphical client to transfer my files to and from the webserver but I find the command-line more comfortable. However, the full command to transfer a file to the webserver is not easy to remember.

$ scp me_mysite@long.and.difficult.servername:~/

I create shortcuts to both scp (copy) and ssh (connect to remote server) that mean I only need to enter myscp filename mysite. The shortcut will also echo the password to the screen so I don’t need to remember it. To avoid security problems, I only interact with the webserver in my own home. When I am out and about, I develop using the local server. There is a way of setting up ssh so that you don’t need to enter a password at all and the server validates the client using a shared certificate but so far I have not needed to set this up.

I split my shortcuts and variables into seperate files.

.shell-fns

myscp()
{
    FILE=$1
    SITE=$2

    echo "Password is: $SSH_PASSWORD"
    scp $FILE ${SSH_USER}_${SITE}@${SSH_SERVER}:~/
}

myssh()
{
    SITE=$1

    echo "Password is: $SSH_PASSWORD"
    ssh ${SSH_USER}_${SITE}@${SSH_SERVER}
}

Update: I often find I want to transfer multiple files at the same time and it would be useful if I could do this with a single myscp command. I fixed the function to do this, but I’m not particularly happy with the method of extracting the parameters using sed. Perhaps there is a better way.

myscp()
{
    FILES=`echo "$@" | sed -e 's/  *\w\w* *$//'`
    SITE=`echo "$@" | sed -e 's/.*  *\(\w\w*\)$/\1/'`

    echo "Password is: $PASSWORD"
    scp $FILES ${USER}_${SITE}@${SSH_SERVER}:~/
}

.env

PACKAGES=/u/packages

PATH=$HOME/bin:$PACKAGES/bin:$PATH
PYTHONPATH=$PACKAGES/lib/python:$PYTHONPATH

HISTSIZE=10000
HISTFILESIZE=$HISTSIZE

PS1="`whoami`@`hostname` \$ "

export PATH PYTHONPATH HISTSIZE HISTFILESIZE

SSH_USER=not_my_real_user_name
SSH_PASSWORD=not_my_real_password
SSH_SERVER=very.long.and.difficult.to.remember.servername

Then add the following to the .bashrc file and it is ready

. $HOME/.env
. $HOME/.shell-fns

Apache Setup on Ubuntu

November 19, 2008 by John Jenkins · 2 Comments
Filed under: Tools 

I like to have a copy of my blog hosted on my local computer for two reasons. The first, and most important, is that I can try different configurations of the blog without them being visible to the world. The second is that making changes is more immediate on a local server.

The Apache setup on Ubuntu is quite unusual. To activate a module you need to create a link. And, as mod-rewrite isn’t enabled by default you need to execute the following:

$ cd /etc/apache2/mods-enabled
$ sudo ln -s ../mods-available/rewrite.load rewrite.load

For each of my local websites there main setting I need is AllowOverride all to allow .htaccess to set various parameters on a directory by directory basis.

Here is a section of my /etc/apache2/httpd.conf:

ServerName localhost

<VirtualHost *>
    Alias /images "/u/websites/images/"
    <Directory "/u/websites/images/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride all
    </Directory>

    Alias /test-blog "/u/websites/blog/test-blog/"
    <Directory "/u/websites/blog/test-blog/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride all
    </Directory>

    Alias /timepoor "/u/websites/blog/timepoor/"
    <Directory "/u/websites/blog/timepoor/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride all
    </Directory>
</VirtualHost>