### -*-m4-*- ### ### Failsafe prologue for firewall scripts ### ### (c) 2008 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This program is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### ### This program is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with this program; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. m4_divert(10)m4_dnl ###-------------------------------------------------------------------------- ### Failsafe prologue. revert () { echo "$1! Retreating to safe version..." if ! "$firewall_failsafe" revert; then echo >&2 "Safe firewall failed. You're screwed. Good luck." exit 1 fi echo >&2 "Phew! Fallback to safe version successful." exit 1 } finished () { echo "Done." exit 0 } exit_after_clearing=: export FWCOOKIE=magical case "${1-update}" in start | restart | reload | force-reload) echo -n "Starting up firewall... " "$firewall_script" install || revert "Failed" finished ;; stop) echo -n "Shutting down firewall... " exit_after_clearing=finished ;; update) echo -n "Installing new firewall... " "$firewall_script" install || revert "Failed" echo "Done." echo "Can you hear me?" parent=$$ (sleep 5; kill $parent; revert "Timeout")& child=$! read answer kill $child case "$answer" in y* | Y*) echo "Cool. We're done here." exit 0 ;; esac revert "Bogus" ;; install | revert) ;; *) echo >&2 "Usage: firewall start|stop|reload|restart|force-reload|update|install|revert" exit 1 ;; esac m4_divert(-1) ###----- That's all, folks --------------------------------------------------