#!/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-bk-pomng}
IPTABLES_DIR=${IPTABLES_DIR:-../iptables-1.2.10}


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:$IPTABLES_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
- ipt_helper-invert-fix
+ proc-no-internal-targets
- orphaned-expect-fix
- helper-reassign-fix
? expect-evict-order
? nf_reset
+ expect-slab-cache
+ ip_nf_assert-fix
+ proc_net_conntrack-permissions
? CLASSIFY_more-hooks
? amanda_offset-fix
? conntrack-acct
? conntrack-cacheline-opt
? conntrack_error-api
? early-drop-norandom
? ip_nat_helper_static
+ mangle-reroute
? module_parm
+ owner-broken
+ unclean_fragment-fix
+ helper-locking_fix
- ip_queue_nonlinear_skbs

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


####### 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
? iptables-loopcheck-speedup
- 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
+ account
? ipt_helper-any
? policy
- nat-reservations
? connrate
? dropped-table
? ipsec-01-output-hooks
? ipsec-02-input-hooks
? ipsec-03-policy-lookup
? ipsec-04-policy-checks
? sctp-conntrack-nat
+ goto
? MARK-operations
? comment
? conntrack_protocol-arrays
? tproxy
? conntrack_memsave
? directx8-conntrack-nat
? ACCOUNT
? ip_queue_vwmark
? nf_conntrack
? xover
? CLUSTERIP
+ geoip
+ msnp-conntrack-nat
- ULOG

EOF

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

