"Fossies" - the Fresh Open Source Software Archive

Member "shorewall-init-5.2.8/init.suse.sh" (24 Sep 2020, 3854 Bytes) of package /linux/misc/shorewall/shorewall-init-5.2.8.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "init.suse.sh": 5.2.3.6_vs_5.2.6.

    1 #! /bin/bash
    2 #     The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V5.2
    3 #
    4 #     This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
    5 #
    6 #     (c) 2010,2012 - Tom Eastep (teastep@shorewall.net)
    7 #
    8 #       On most distributions, this file should be called /etc/init.d/shorewall.
    9 #
   10 #       Complete documentation is available at https://shorewall.org
   11 #
   12 #       This program is free software; you can redistribute it and/or modify
   13 #       it under the terms of Version 2 of the GNU General Public License
   14 #       as published by the Free Software Foundation.
   15 #
   16 #       This program is distributed in the hope that it will be useful,
   17 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
   18 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   19 #       GNU General Public License for more details.
   20 #
   21 #       You should have received a copy of the GNU General Public License
   22 #       along with this program; if not, write to the Free Software
   23 #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   24 #
   25 #
   26 ### BEGIN INIT INFO
   27 # Provides: shorewall-init
   28 # Required-Start: $local_fs
   29 # Required-Stop:  $local_fs
   30 # Default-Start:  2 3 5
   31 # Default-Stop:   0 1 6
   32 # Short-Description: Initialize the firewall at boot time
   33 # Description:       Place the firewall in a safe state at boot time
   34 #                    prior to bringing up the network.  
   35 ### END INIT INFO
   36 
   37 #Return values acc. to LSB for all commands but status:
   38 # 0 - success
   39 # 1 - generic or unspecified error
   40 # 2 - invalid or excess argument(s)
   41 # 3 - unimplemented feature
   42 # 4 - insufficient privilege
   43 # 5 - program is not installed
   44 # 6 - program is not configured
   45 # 7 - program is not running
   46 
   47 if [ "$(id -u)" != "0" ]
   48 then
   49   echo "You must be root to start, stop or restart \"Shorewall \"."
   50   exit 4
   51 fi
   52 
   53 # check if shorewall-init is configured or not
   54 if [ -f "/etc/sysconfig/shorewall-init" ]
   55 then
   56     . /etc/sysconfig/shorewall-init
   57 
   58     if [ -z "$PRODUCTS" ]
   59     then
   60     echo "No PRODUCTS configured"
   61     exit 6
   62     fi
   63 else
   64     echo "/etc/sysconfig/shorewall-init not found"
   65     exit 6
   66 fi
   67 
   68 #
   69 # The installer may alter this
   70 #
   71 . /usr/share/shorewall/shorewallrc
   72 
   73 # set the STATEDIR variable
   74 setstatedir() {
   75     local statedir
   76     if [ -f ${CONFDIR}/${PRODUCT}/vardir ]; then
   77     statedir=$( . /${CONFDIR}/${PRODUCT}/vardir && echo $VARDIR )
   78     fi
   79 
   80     [ -n "$statedir" ] && STATEDIR=${statedir} || STATEDIR=${VARLIB}/${PRODUCT}
   81 
   82     if [ -x ${STATEDIR}/firewall ]; then
   83     return 0
   84     elif [ $PRODUCT = shorewall ]; then
   85     ${SBINDIR}/shorewall compile
   86     elif [ $PRODUCT = shorewall6 ]; then
   87     ${SBINDIR}/shorewall -6 compile
   88     else
   89     return 6
   90     fi
   91 }
   92 
   93 # Initialize the firewall
   94 shorewall_start () {
   95   local PRODUCT
   96   local STATEDIR
   97 
   98   printf "Initializing \"Shorewall-based firewalls\": "
   99   for PRODUCT in $PRODUCTS; do
  100       if setstatedir; then
  101       if ! ${SBIN}/$PRODUCT status > /dev/null 2>&1; then
  102           $STATEDIR/$PRODUCT/firewall ${OPTIONS} stop
  103       fi
  104       fi
  105   done
  106 
  107   if [ -n "$SAVE_IPSETS" -a -f "$SAVE_IPSETS" ]; then
  108       ipset -R < "$SAVE_IPSETS"
  109   fi
  110 }
  111 
  112 # Clear the firewall
  113 shorewall_stop () {
  114   local PRODUCT
  115   local STATEDIR
  116 
  117   printf "Clearing \"Shorewall-based firewalls\": "
  118   for PRODUCT in $PRODUCTS; do
  119       if setstatedir; then
  120       ${STATEDIR}/firewall ${OPTIONS} clear
  121       fi
  122   done
  123 
  124   if [ -n "$SAVE_IPSETS" ]; then
  125       mkdir -p $(dirname "$SAVE_IPSETS")
  126       if ipset -S > "${SAVE_IPSETS}.tmp"; then
  127       grep -qE -- '^(-N|create )' "${SAVE_IPSETS}.tmp" && mv -f "${SAVE_IPSETS}.tmp" "$SAVE_IPSETS" || rm -f "${SAVE_IPSETS}.tmp"
  128       else
  129       rm -f "${SAVE_IPSETS}.tmp"
  130       fi
  131   fi
  132 }
  133 
  134 case "$1" in
  135     start)
  136     shorewall_start
  137     ;;
  138     stop)
  139     shorewall_stop
  140     ;;
  141     reload|forced-reload)
  142     ;;
  143     *)
  144     echo "Usage: /etc/init.d/shorewall-init {start|stop}"
  145     exit 1
  146     ;;
  147 esac
  148 
  149 exit 0