Preparing for a journey: Keep your MySQL manuals in sync

The MySQL Users Conference 2006 is just a few days away. Everybody's preparing for the journey. So am I. We all might probably want to hack away on the local MySQL installations on our laptops while on the road, but there might not always be a wireless access point in reach...

So you better get yourself a fresh offline copy of the MySQL manuals to work with. That's what I just did. But it got a little bit tedious since the manual had been split into multiple versions: Download all the versions you need, unpack them, rename the directories to reflect the version of the manual, probably install a symbolic link to the index.hml and remove the tar.gz package.

I'm a lazy guy when it comes to tedious work. And when I have to do the same thing for the second time (I downloaded the manuals already when I went on another trip recently) it's definitely time to write a script that does the work for me. Enters the MySQL manual downloader.

#!/bin/bash
BASEURL="http://downloads.mysql.com/docs/"
rm -f *_????-??-??.html 2> /dev/null
while read TARGZ
do
  DOCDIR=${TARGZ%.tar.gz}
  SYMLNK=${DOCDIR%.html}_`date +%Y-%m-%d`.html
  curl -fsS $BASEURL$TARGZ > $TARGZ
  tar -xzf $TARGZ
  rm -rf $DOCDIR
  mv -f `tar tzf $TARGZ | head -n1` $DOCDIR
  ln -s `ls $DOCDIR/{index,manual}.html 2> /dev/null` $SYMLNK
  rm -f $TARGZ
done <<EOF
refman-4.1-en.html.tar.gz
refman-5.0-en.html-chapter.tar.gz
refman-5.1-en.html-chapter.tar.gz
EOF

I just installed this little shell script as a daily cron job on my iBook. Now I should always have the most recent version of the manuals on my harddrive.

Run the script in the directory where you want to keep your manuals and add the versions you want to download to the section at the end. It should work for all the tar.gz versions of the HTML manual (by chapter or all on one page). The symlink will reflect the date of the last download, so you always know if you work with a recent copy. That's a good thing with the speed at that things currently change.