#!/bin/bash

#
# Warning: this script is *REALLY* dirty, but it took me a few
# minutes to get what I needed. Don't complain if it destroys
# your computer, it's your problem, not mine.
#


KERNEL_DIR=${KERNEL_DIR:-/usr/src/linux-2.4.25-pomng}
IPTABLE_DIR=${IPTABLE_DIR:-/users/willy/download/iptables-1.2.9}


if [ "$1" = "-n" ]; then
    for family in pending base extra; do
        echo "####### $family #######"
        grep "^Repository: $family" */info|cut -f1 -d/|while read; do
            grep -q "^. $REPLY" $0 || echo "? $REPLY" 
        done
    done
    exit 0
elif [ "$1" != "-a" ]; then
    echo "Usage: $0 [ -n | -a ]"
    echo "  -n shows for each family the new lines to add for the current repository."
    echo "  -a applies all the patches marked with '+' in the script."
    echo
    echo "This needs to be started from the patch-o-matic-ng directory"
    exit 0
fi

list=( )
while read tag name comment ; do
    if [ "$tag" = "-" ]; then
	echo "Excluding $name"
    elif [ "$tag" = "+" ]; then
	echo "Including $name"
	list=( ${list[@]} $name )
	#./runme --path=$KERNEL_DIR:$IPTABLE_DIR --batch $name
    fi
done << EOF
# The first char indicates what to do with the patch
# '-' means 'do not apply it'
# '+' means 'apply it'
# '?' means 'not tested yet'
# '!' means 'does not apply'
# everything else is ignored.

####### pending #######
- expect-optimize
- init_conntrack-optimize
- linuxdoc
+ nf-log


####### base #######
- HOPLIMIT
+ IPV4OPTSSTRIP
+ NETLINK
+ NETMAP
+ REJECT
+ SAME
+ TTL
+ connlimit
? dstlimit
? fuzzy
+ iprange
+ ipv4options
+ mport
+ nth
+ osf
+ pool
+ psd
? quota
+ random
? raw
? realm
? sctp
+ set
+ time
+ u32


####### extra #######
+ CLASSIFY
- CONNMARK
- IPMARK
+ ROUTE
+ TARPIT
- TCPLAG
- TRACE
+ XOR
+ addrtype
- childlevel
+ condition
? connbytes
? conntrack-seqfile
+ conntrack_arefcount
+ conntrack_locking
+ conntrack_nonat
- ctstat
+ cuseeme-nat
+ eggdrop-conntrack
+ h323-conntrack-nat
? layer2-hooks
+ mms-conntrack-nat
! netfilter-docbook
- nfnetlink-ctnetlink-0.13
+ owner-socketlookup
- owner-supgids
+ ownercmd
? pptp-conntrack-nat
+ quake3-conntrack-nat
+ rpc
+ rsh
+ rtsp-conntrack
+ string
+ talk-conntrack-nat
+ tcp-window-tracking

EOF

echo "Now starting runme..."
./runme --path=$KERNEL_DIR:$IPTABLE_DIR --batch ${list[@]}
exit 0

