Apr 162001

Massive website changes

Yes, I’m still in Ottawa.  The snow is all gone.  And some days are quite warm.  It was 16C about a week ago.  And I’ve managed to pay good money to watch bad hockey (Ottawa lost the first two games to Toronto).  The upside is that I’ve now managed to see my first NHL playoff games ever (apart from those I’ve seen on TV).

But while I’ve been socializing with old friends, watching hockey games, and waiting in secret for my parent to arrive back from holiday, I’ve had a few problems with the website.  It is the combined timing of this abundance of free time, total lack of responsibilities, and website problems that has prompted me to finally move towards implementing php across all of the website.

The conversion was an interesting task involving modification of well over 500 files.  Luckily, I did not have to do this by hand.  The first task involved renaming files.  I used this script to do that:

for filename in $(ls *.php); do
echo "renaming $filename"
mv $filename.new $filename

The rest of the modifications involved putting common headers into each file, changing frequently used code snippets to php code, and other various administration-type tasks.   I have learned more about perl and regular expressions in the past 4 days than at any other time in my life.

Just because each file is now a .php, this does not mean that the article text is now in the database.  In fact, none of the text is in any database.  The database just contains the article title, date, topic, etc.  But that work was done a year or more ago in order to allow the home page, the index, and the topics page to be generated automatically.  It is this same database which is used to generate the mailing list notifications.

Your old URLs should still work so you don’t have to modify your bookmarks.  I’m using rewrite to accomplish that.

But the major reason for converting all files to .php is to allow user feedback on an article by article basis.  That will be added at a later date.  I know I’ve been saying that for ages, but this time it’s different.  The biggest hurdle has been jumped.  There’s no going back now.  I’m going to customize phorum to do this.

Another thing I did was install Apache, perl, php, and mysql on my NT workstation.   This was surprisingly easy and straight forward.  Granted, I have done those tasks before in a Unix environment so that experience no doubt simplified things somewhat.   I started working locally because the lag back to my development box was getting annoying at times.  You try editing a file over a 33.6 line when it [at times] takes 2s for an echo….

The changes are ready to go.  I’ve already changed the DNS so that the TTL is low.   This will allow the IP change, when it occurs, to propagate quickly.  Before that happens, I’ll give you a temporary URL so that you can go and test out the site and see if you can break it before I finally throw the switch.  Right now, I’m just waiting for my host provider to fix a wee problem I created early this morning.  As part of the upgrade procedures on the new box, I did a rm -rf * to clear everything out of the root directory of the website.  Unfortunately that also removed /cgi-bin/.

Good move Dan….  That will teach me to do such things that early in the morning.

  One Response to “Massive website changes”

  1. One could use the below script for a more complete
    version of the script.

    For a downloadable version of the script, here’s the URL


    Comments welcome!


    # description:
    # ————
    # this shell script is a little helper
    # when you wish to change the filename
    # extension on a lot of files.
    # The intended use is when moving for
    # example from .html to .php
    # hopefully it will correctly change the
    # hyperlinks inside the files also 🙂

    # usage:
    # ——
    # put the script in ~/bin and cd to a
    # directory containing the files you want to change.
    # From there just start the script and let
    # it do the rest.

    # known bugs:
    # ———–
    # the script is regex case sensitive, meaning
    # it sees .HTML and .html as two different filename
    # extensions. This might be an issue.
    # the script assumes all hyperlinks are enclosed
    # with doublequote characters (").
    # filename extension of the files
    # we want to change

    # filename extension of what we
    # wish to give the changed files

    # where to keep the backups of
    # the old files

    # do some very basic checks before
    # we begin working
    if [ ! -w . ] ; then
    echo "===> oy, we need write permission!"
    exit 1
    elif [ -e ${bkpdir} -a ! -d ${bkpdir} ] ; then
    echo "===> backup dirname occupied by other file"
    exit 1
    elif [ -e ${bkpdir} -a -d ${bkdir} ] ; then
    echo "===> saving old backup dir"
    mv ${bkpdir} ${bkpdir}.$(date +%s)
    mkdir ${bkpdir}
    elif [ ! -e ${bkpdir} ] ; then
    mkdir ${bkpdir}

    # loop through each file with
    # the old extension
    for file in *.${oldext} ; do
    if [ -f ${file} ] ; then
    echo -n "+ ${file}"
    mv ${file} ${bkpdir}
    newfile=$(echo ${file} | \
    sed s/\.${oldext}$/.${newext}/)

    sed \
    -e "s!\.${oldext}\">!.${newext}\">!g" \
    -e "s!\.${oldext}\(\?.*\)\">!.${newext}\1\">!g" \
    < ${oldfile} > ${newfile}

    echo " -> ${newfile}"

    # we’re done
    echo -e "\noriginals are in the ‘${bkpdir}’ directory"
    exit 0