#!/bin/sh # (c) Dinko Korunic, InfoMAR, 2008 # SquidGuard merge blacklists # bail out on error set -e # variables TARGET=/var/lib/squidguard/tmp TMPDIR=bl-final SADIR=/var/lib/squidguard/db LOCKFILE=/var/lock/squidguard-black-gen.lock # merge lists merge_bl() { SRC="$1" DST="$2" # sanity checking if [ -z "$SRC" -o -z "$DST" ]; then return fi if [ ! -r "$SRC" ]; then return fi cat "$SRC" >> "$DST" sort -u "$DST" | grep -v '^#' > "$DST.$$" && \ mv -f "$DST.$$" "$DST" rm -f "$DST.$$" } # iterate lists, sort and merge if possible add_bl() { SRCDIR="$1" DSTDIR="$2" # sanity checking if [ -z "$SRCDIR" -o -z "$DSTDIR" ]; then return fi if [ ! -d "$SRCDIR" ]; then return fi # possible that it is empty mkdir -p "$DSTDIR" # iterate the merge procedure DIRS=$(find "$SRCDIR" \( -type d -o -type l \)) for dir in $DIRS; do # extract first-level name short=$(echo "$dir" | cut -d/ -f2) for file in domains urls; do if [ -e "$dir/$file" ]; then mkdir -p "$DSTDIR/$short" merge_bl "$dir/$file" "$DSTDIR/$short/$file" fi done done rm -rf "$SRCDIR" } # lock us lockfile -r1 "$LOCKFILE" trap "rm -f $LOCKFILE $TARGET/$TMPDIR; exit" INT TERM EXIT mkdir -p "$TARGET" cd "$TARGET" # cleanup rm -rf bl BL blacklists "$TMPDIR" *tgz *tar.gz mkdir "$TMPDIR" # if possible, merge the local lists if [ -d crolist ]; then cp -a crolist/* "$TMPDIR" fi # mesd wget http://squidguard.mesd.k12.or.us/blacklists.tgz tar -xvf blacklists.tgz rm -f blacklists.tgz add_bl blacklists "$TMPDIR" # shalla wget http://squidguard.shalla.de/Downloads/shallalist.tar.gz tar -xzf shallalist.tar.gz rm -f shallalist.tar.gz add_bl BL "$TMPDIR" # touloise wget ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz tar -xvf blacklists.tar.gz rm -f blacklists.tar.gz add_bl blacklists "$TMPDIR" # post actions (be atomic if possible) mv "$SADIR" "$SADIR.$$" && mv "$TARGET/$TMPDIR" "$SADIR" /usr/bin/squidGuard -c /etc/squid/squidGuard.conf -C all || true chown -R proxy:proxy "$SADIR" /usr/sbin/squid -k reconfigure rm -rf "$TARGET/$TMPDIR" "$SADIR.$$" # unlock rm -f "$LOCKFILE" trap - INT TERM EXIT