typo fix customary -> custom bnc#835677
[opensuse:susefirewall2.git] / SuSEfirewall2-batch
1 #!/bin/bash
2 # SuSEfirewall2-batch - batchmode support functions
3 # Copyright (C) 2004 SUSE LINUX Products GmbH
4 #
5 # Author:     Ludwig Nussel
6
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # version 2 as published by the Free Software Foundation.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 check_iptables_batch()
21 {
22     if [ -n "$USE_IPTABLES_BATCH" ]; then
23             IPTABLES_BATCH=/usr/sbin/iptables-batch
24             IP6TABLES_BATCH=/usr/sbin/ip6tables-batch
25             if [ ! -x "$IPTABLES_BATCH" ]; then
26                     [ "$USE_IPTABLES_BATCH" != 'auto' ] && echo "iptables-batch missing, batch support disabled."
27                     USE_IPTABLES_BATCH=""
28             elif [ ! -x "$IP6TABLES_BATCH" ]; then
29                     [ "$USE_IPTABLES_BATCH" != 'auto' ] && echo "ip6tables-batch missing, batch support disabled."
30                     USE_IPTABLES_BATCH=""
31             fi
32     fi
33
34     # override iptables calls with shell function if in batch mode
35     if [ -n "$USE_IPTABLES_BATCH" ]; then
36             iptables_batchfile=`mktemp -t SuSEfirewall2_iptables.XXXXXXXX` || exit 1
37             removeonexit "$iptables_batchfile"
38             exec 4> "$iptables_batchfile"
39             echo "#!$IPTABLES_BATCH" >&4
40             iptables()
41             {
42                     local i
43                     echo -n "iptables" >&4
44                     for i in "$@"; do echo -n " \"$i\""; done >&4
45                     echo >&4
46             }
47             ip6tables_batchfile=`mktemp -t SuSEfirewall2_ip6tables.XXXXXXXX` || exit 1
48             removeonexit "$ip6tables_batchfile"
49             exec 6> "$ip6tables_batchfile"
50             echo "#!$IP6TABLES_BATCH" >&6
51             ip6tables()
52             {
53                     local i
54                     echo -n "ip6tables" >&6
55                     for i in "$@"; do echo -n " \"$i\""; done >&6
56                     echo >&6
57             }
58     fi
59 }
60
61 iptables_batch_commitpoint()
62 {
63     echo commit >&4
64     echo commit >&6
65 }
66
67 commit_iptables_batch()
68 {
69     if [ -n "$USE_IPTABLES_BATCH" ]; then
70         if ! $IPTABLES_BATCH "$iptables_batchfile"; then
71             error "iptables-batch failed, re-running using iptables"
72             iptables() { $IPTABLES_BIN "$@"; }
73             commit() { :; }
74             . $iptables_batchfile
75         fi
76         if ! $IP6TABLES_BATCH "$ip6tables_batchfile"; then
77             error "ip6tables-batch failed, re-running using ip6tables"
78             ip6tables() { $IP6TABLES_BIN "$@"; }
79             commit() { :; }
80             . $ip6tables_batchfile
81         fi
82     fi
83 }
84
85 # vim: sw=4