Update download page


I’ve added some more downloads to the download page and now I’m running into tiny troubles. When I change a script or configfile, this is placed in this blogs download directory. But the blogs database isn’t updated, so the file size, date/time and revision numbers are not the same on the download page as they are on disk. Of course it’s possible to update all this by hand, every time something changes, but being lazy I created a little script that does this all for me.

This is it:

#!/bin/bash

DIRS="git.vi header makebackup mysqlbackup"

# Top of the development tree
cd ~/develop

# Process all the download directories
for dir in ${DIRS}
do
    cd ${dir}

    # First install everything
    # The Make file also installs in the blogs download dir
    echo "Processing ${dir}"
    make install
    git push

    # Process all files
    for f in *
    do
        # Get the revision number, date and size
        rev="$(grep '^# $Revision::' $f | awk '{print $3 }')"
        dt="$(stat -c '%y' $f | cut -d '.' -f1)"
        sz="$(stat -c '%s' $f)"

        # Create a MySQL update string
        cat <<- @EOF
            #
            # Update the revision
            #
            update wp_download_monitor_files
            set dlversion='${rev}'
            where filename='/var/www/blog/downloads/${dir}/${f}';

            #
            # Update the file date
            #
            update wp_download_monitor_files
            set postDate='${dt}'
            where filename='/var/www/blog/downloads/${dir}/${f}';

            #
            # Update the file size
            #
            update
                wp_download_monitor_file_meta  m,
                wp_download_monitor_files      f
                set m.meta_value = '${sz}'
                where (
                    m.download_id: f.id
                )
                    and (
                    m.meta_name: 'filesize'
                )
                and (
                    f.filename: '/var/www/blog/downloads/${dir}/${f}'
                );
        @EOF
    done
    cd ..
done | mysql -u root -p blogdb
blog 

See also