1#!/bin/sh
2#
3# junkfilter
4# a junk email filter system for procmail
5# Copyright 1997-2001 Gregory Sutter <gsutter@zer0.org>
6#
7# $Id: jf,v 1.17 2002/05/20 03:10:19 gsutter Exp $
8#
9# Please read the file "README" and the page
10# http://junkfilter.zer0.org/ before using junkfilter.
11#
12# jf -- unified junkfilter management
13
14SELF=$0
15
16if [ ! $JFDIR ]; then
17	JFDIR=/usr/local/etc/junkfilter
18	if [ ! -r $JFDIR/junkfilter.config ]; then
19		echo "Error: please set \$JFDIR to the location of junkfilter."
20		exit 66
21	fi
22fi
23
24#JFUSERDIR=`grep JFUSERDIR $JFDIR/junkfilter.config | awk -F "=" '{print $2}'` || \
25#	( echo "Error: junkfilter not found in $JFDIR"; exit 66 )
26
27if [ x$1 = xchk ]; then
28	cat $JFDIR/domains/* | perl -pe 'y/[A-Z]/[a-z]/' | grep $2
29
30elif [ x$1 = xadd -o x$1 = xcta ]; then
31	cat $JFDIR/domains/* | perl -pe 'y/[A-Z]/[a-z]/' | egrep -q "^$2\$" && echo "$2 already in domains list" || echo $2 >> $JFDIR/domains/general
32
33elif [ x$1 = xbuild ]; then
34	if [ x$2 = xdomains ]; then
35	  cat $JFDIR/domains/[a-z]* |\
36	  egrep -v "^#" |\
37	  perl -pe 's/[	 ]+//g; y/[A-Z]/[a-z]/; s/
38//g' |\
39	  egrep -v '^$' |\
40	  sort | uniq |\
41	  perl -p0e 's/\012(.)/\|$1/g; s/\./\\./g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-domains
42	  echo "Done. $2 built."
43
44	elif [ x$2 = xaddresses ]; then
45	  cat $JFDIR/addresses |\
46	  egrep -v "^#" | sort |\
47	  perl -p0e 's/\012(.)/\|$1/g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-addresses
48	  echo "Done. $2 built."
49
50	elif [ x$2 = xip ]; then
51	  cat $JFDIR/ip |\
52	  egrep -v "^#" | sort |\
53	  perl -p0e 's/\012(.)/\|$1/g; s/\./\\./g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-ip
54	  echo "Done. $2 built."
55
56	elif [ x$2 = xbodychk ]; then
57	  cat $JFDIR/bodychk |\
58	  egrep -v "^#" | sort |\
59	  perl -p0e 's/\012(.)/\|$1/g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-bodychk
60	  echo "Done. $2 built."
61
62	elif [ x$2 = xdialups ]; then
63	  cat $JFDIR/dialups |\
64	  egrep -v "^#" | sort |\
65	  perl -p0e 's/\012(.)/\|$1/g; s/\./\\./g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-dialups
66	  echo "Done. $2 built."
67
68	elif [ x$2 = xheaders ]; then
69	  cat $JFDIR/headers |\
70	  egrep -v "^#" | sort |\
71	  perl -p0e 's/\012(.)/\|$1/g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-headers
72	  echo "Done. $2 built."
73
74	elif [ x$2 = xwhite ]; then
75	  cat $JFDIR/white |\
76	  egrep -v "^#" | sort |\
77	  perl -p0e 's/\012(.)/\|$1/g; s/\015//g; s/\|{2,}/\|/g' > $JFDIR/jf-white
78	  echo "Done. $2 built."
79
80	elif [ x$2 = xall ]; then
81	  $SELF build addresses
82	  $SELF build bodychk
83	  $SELF build dialups
84	  $SELF build domains
85	  $SELF build headers
86	  $SELF build ip
87	  $SELF build white
88	  echo "Done. $2 built."
89
90	elif [ x = x ]; then
91	  echo "I can build 'addresses', 'bodychk', 'dialups', 'domains',"
92	  echo "'headers', 'ip', 'white', 'all'"
93	  exit 1
94
95	fi
96
97elif [ x$1 = xget ]; then
98	echo "  You can get the latest list of domains from:"
99	echo "  http://junkfilter.zer0.org/pkg/dev/domains/general"
100
101elif [ x$1 = xrel ]; then
102	if [ ! x$3 = x ]; then
103	  JFELOC=$3
104	  if [ ! -d $JFELOC ]; then
105	    echo "Usage: $SELF rel <version> <package location>"
106	    exit 1
107	  fi
108	else
109	  echo "Usage: $SELF rel <version> <package location>"
110	  exit 1
111	fi
112	if [ ! x$2 = x ]; then
113	  JFEVER=$2
114	  if [ ! -d $JFELOC/$JFEVER ]; then
115	    mkdir $JFELOC/$JFEVER
116	  else
117	    echo "That version already exists!"
118	    exit 1
119	  fi
120	else
121	  echo "Usage: $SELF rel <version> <package location>"
122	  exit 1
123	fi
124	  JFEDIR=$JFELOC/$JFEVER
125	  TMPDIR=/tmp
126	  rm $JFEDIR/*
127#	  $SELF get
128	  $SELF build all
129	  mkdir $TMPDIR/junkfilter
130	  cp -p $JFDIR/* $TMPDIR/junkfilter
131	  mkdir $TMPDIR/junkfilter/domains
132	  cp -p $JFDIR/domains/* $TMPDIR/junkfilter/domains
133	  cd $TMPDIR
134	  tar -cf - junkfilter | gzip -9 > $JFEDIR/junkfilter-$JFEVER.tar.gz
135	  mv $TMPDIR/junkfilter/* $JFEDIR
136	  rmdir $TMPDIR/junkfilter
137	  rm $JFELOC/current
138	  rm $JFELOC/junkfilter.tar.gz
139	  cd $JFELOC
140	  ln -s $JFEVER/junkfilter-$JFEVER.tar.gz junkfilter.tar.gz
141	  ln -s $JFEVER current
142	  echo "Done.  New junkfilter release in $JFEDIR."
143
144elif [ x$1 = x ]; then
145	echo "Command syntax: $SELF <command> <option>"
146	echo "commands: add [domain], chk [domain], cta [domain], build [option],"
147	echo "          get (new gulf-blocks domains file), rel (build release)"
148	echo "options: addresses, domains, bodychk, dialups, ip, headers, white"
149fi
150
151#eof
152