Commit | Line | Data |
---|---|---|
bfdc045d MW |
1 | ### -*-m4-*- |
2 | ### | |
3 | ### Failsafe prologue for firewall scripts | |
4 | ### | |
5 | ### (c) 2008 Mark Wooding | |
6 | ### | |
7 | ||
8 | ###----- Licensing notice --------------------------------------------------- | |
9 | ### | |
10 | ### This program is free software; you can redistribute it and/or modify | |
11 | ### it under the terms of the GNU General Public License as published by | |
12 | ### the Free Software Foundation; either version 2 of the License, or | |
13 | ### (at your option) any later version. | |
14 | ### | |
15 | ### This program is distributed in the hope that it will be useful, | |
16 | ### but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ### GNU General Public License for more details. | |
19 | ### | |
20 | ### You should have received a copy of the GNU General Public License | |
21 | ### along with this program; if not, write to the Free Software Foundation, | |
22 | ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | ||
24 | m4_divert(10)m4_dnl | |
25 | ###-------------------------------------------------------------------------- | |
26 | ### Failsafe prologue. | |
27 | ||
28 | revert () { | |
29 | echo "$1! Retreating to safe version..." | |
30 | if ! "$firewall_failsafe" revert; then | |
31 | echo >&2 "Safe firewall failed. You're screwed. Good luck." | |
32 | exit 1 | |
33 | fi | |
34 | echo >&2 "Phew! Fallback to safe version successful." | |
35 | exit 1 | |
36 | } | |
37 | ||
38 | finished () { | |
39 | echo "Done." | |
40 | exit 0 | |
41 | } | |
42 | ||
43 | exit_after_clearing=: | |
44 | export FWCOOKIE=magical | |
45 | case "${1-update}" in | |
46 | start | restart | reload | force-reload) | |
47 | echo -n "Starting up firewall... " | |
48 | "$firewall_script" install || revert "Failed" | |
49 | finished | |
50 | ;; | |
51 | stop) | |
52 | echo -n "Shutting down firewall... " | |
53 | exit_after_clearing=finished | |
54 | ;; | |
55 | update) | |
56 | echo -n "Installing new firewall... " | |
57 | "$firewall_script" install || revert "Failed" | |
58 | echo "Done." | |
59 | echo "Can you hear me?" | |
60 | parent=$$ | |
61 | (sleep 5; kill $parent; revert "Timeout")& | |
62 | child=$! | |
63 | read answer | |
64 | kill $child | |
65 | case "$answer" in | |
66 | y* | Y*) | |
67 | echo "Cool. We're done here." | |
68 | exit 0 | |
69 | ;; | |
70 | esac | |
71 | revert "Bogus" | |
72 | ;; | |
73 | install | revert) | |
74 | ;; | |
75 | *) | |
76 | echo >&2 "Usage: firewall start|stop|reload|restart|force-reload|update|install|revert" | |
77 | exit 1 | |
78 | ;; | |
79 | esac | |
80 | ||
81 | m4_divert(-1) | |
82 | ###----- That's all, folks -------------------------------------------------- |