#!/bin/sh
#
# idefetch - Written by Danny Howard <dannyman@tellme.com>
#
# Updates virus identity (IDE) files for Sophos SWEEP.
#
# Usage: Set these two variables.
# IDEDIR is the directory where you keep your .ide files.
# FETCH is a program that can retrieve a file via HTTP and download it to the
# local directory.  "fetch" works under FreeBSD.  On other systems, you may
# need lynx, wget, lukemftp, or ncftpget.
#
# Sophos is very useful when coupled with AMaViS for scanning e-mail messages:
# Sophos: http://www.sophos.com/downloads/products/
# AMaViS: http://www.amavis.org/
#
# Further details about automatic updates for Sophos at
# http://www.sophos.com/support/faqs/autodown.html.
#
# Finally, note that Sophos support say "use wget" which could probably
# replace this entire script with a single command, but I was just trying to
# have some fun here, neh?

# Tellme Open Source License
# 
# Permission is hereby granted under the copyrights of Tellme, free of charge,
# to any person obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the
# following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# Once you know this works, you probably want to run this out of cron.  Man
# crontab for more info.

IDEDIR="/usr/local/sav"
FETCH="/usr/bin/fetch"

cd $IDEDIR

$FETCH http://www.sophos.com/downloads/ide/list.txt 2> /dev/null

# Portability note: At first I did a check, and only invoked fetch if a file
# named $d did not already exist.  However, Sophos like to update existing
# identity files.  Fetch -m is "mirror" mode, it only pulls the file if the
# remote file is newer than the local file.  If your "fetch" variant doesn't
# have a mode like this, then you'll have to worry about that.
for d in `cut -c 37- < list.txt`; do
	$FETCH -m http://www.sophos.com/downloads/ide/${d}
done

# >>>>>> SNIP HERE IF YOU ARE 31337 <<<<<<
# If you want, use this from Dag-Erling Smorgrav <des@ofug.org>
# (You can use the below without including the Tellme license ;)

#Try this on for size:
#
#idesite="http://www.sophos.com/downloads/ide/"
#idedir="/usr/local/sav"
#fetch="/usr/bin/fetch"
#${fetch} -q -o - "${idesite}list.txt" | cut -c 37- | while read d ; do
#        ${fetch} -m -q -o ${idedir} "${idesite}${d}"
#done
