"Fossies" - the Fresh Open Source Software Archive

Member "shorewall-init-5.2.8/install.sh" (24 Sep 2020, 15508 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 latest Fossies "Diffs" side-by-side code changes report for "install.sh": 5.2.7_vs_5.2.8.

    1 #!/bin/sh
    2 #
    3 # Script to install Shoreline Firewall Init
    4 #
    5 #     (c) 2000-2016 - Tom Eastep (teastep@shorewall.net)
    6 #     (c) 2010 - Roberto C. Sanchez (roberto@connexer.com)
    7 #
    8 #       Shorewall documentation is available at https://shorewall.org
    9 #
   10 #       This program is part of Shorewall.
   11 #
   12 #   This program is free software; you can redistribute it and/or modify
   13 #   it under the terms of the GNU General Public License as published by the
   14 #       Free Software Foundation, either version 2 of the license or, at your
   15 #       option, any later version.
   16 #
   17 #   This program is distributed in the hope that it will be useful,
   18 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   20 #   GNU General Public License for more details.
   21 #
   22 #   You should have received a copy of the GNU General Public License
   23 #   along with this program; if not, see <http://www.gnu.org/licenses/>.
   24 #
   25 #       You should have received a copy of the GNU General Public License
   26 #       along with this program; if not, write to the Free Software
   27 #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   28 #
   29 
   30 VERSION=5.2.8
   31 PRODUCT=shorewall-init
   32 Product="Shorewall Init"
   33 
   34 usage() # $1 = exit status
   35 {
   36     ME=$(basename $0)
   37     echo "usage: $ME [ <option> ] [ <shorewallrc file> ]"
   38     echo "where <option> is one of"
   39     echo "  -h"
   40     echo "  -v"
   41     echo "  -n"
   42     exit $1
   43 }
   44 
   45 install_file() # $1 = source $2 = target $3 = mode
   46 {
   47     if cp -f $1 $2; then
   48     if chmod $3 $2; then
   49         if [ -n "$OWNER" ]; then
   50         if chown $OWNER:$GROUP $2; then
   51             return
   52         fi
   53         else
   54         return 0
   55         fi
   56     fi
   57     fi
   58 
   59     echo "ERROR: Failed to install $2" >&2
   60     exit 1
   61 }
   62 
   63 #
   64 # Change to the directory containing this script
   65 #
   66 cd "$(dirname $0)"
   67 
   68 #
   69 # Source common functions
   70 #
   71 . ./lib.installer || { echo "ERROR: Can not load common functions." >&2; exit 1; }
   72 
   73 #
   74 # Parse the run line
   75 #
   76 
   77 finished=0
   78 configure=1
   79 
   80 while [ $finished -eq 0 ] ; do
   81     option="$1"
   82 
   83     case "$option" in
   84     -*)
   85         option=${option#-}
   86 
   87         while [ -n "$option" ]; do
   88         case $option in
   89             h)
   90             usage 0
   91             ;;
   92             v)
   93             echo "$Product Firewall Installer Version $VERSION"
   94             exit 0
   95             ;;
   96             n*)
   97             configure=0
   98             option=${option#n}
   99             ;;
  100             *)
  101             usage 1
  102             ;;
  103         esac
  104         done
  105 
  106         shift
  107         ;;
  108     *)
  109         finished=1
  110         ;;
  111     esac
  112 done
  113 
  114 #
  115 # Read the RC file
  116 #
  117 if [ $# -eq 0 ]; then
  118     if [ -f ./shorewallrc ]; then
  119     file=./shorewallrc
  120         . $file || fatal_error "Can not load the RC file: $file"
  121     elif [ -f ~/.shorewallrc ]; then
  122     file=~/.shorewallrc
  123         . $file || fatal_error "Can not load the RC file: $file"
  124     elif [ -f /usr/share/shorewall/shorewallrc ]; then
  125     file=/usr/share/shorewall/shorewallrc
  126         . $file || fatal_error "Can not load the RC file: $file"
  127     else
  128     fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
  129     fi
  130 elif [ $# -eq 1 ]; then
  131     file=$1
  132     case $file in
  133     /*|.*)
  134         ;;
  135     *)
  136         file=./$file || exit 1
  137         ;;
  138     esac
  139 
  140     . $file || fatal_error "Can not load the RC file: $file"
  141 else
  142     usage 1
  143 fi
  144 
  145 if [ -z "${VARLIB}" ]; then
  146     VARLIB=${VARDIR}
  147     VARDIR=${VARLIB}/${PRODUCT}
  148 elif [ -z "${VARDIR}" ]; then
  149     VARDIR=${VARLIB}/${PRODUCT}
  150 fi
  151 
  152 for var in SHAREDIR LIBEXECDIR CONFDIR SBINDIR VARLIB VARDIR; do
  153     require $var
  154 done
  155 
  156 [ -n "$SANDBOX" ] && configure=0
  157 
  158 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
  159 
  160 [ $configure -eq 1 ] && ETC=/etc || ETC="${CONFDIR}"
  161 
  162 if [ -z "$BUILD" ]; then
  163     case $(uname) in
  164     cygwin*)
  165         BUILD=cygwin
  166         ;;
  167     Darwin)
  168         BUILD=apple
  169         ;;
  170     *)
  171         if [ -f /etc/os-release ]; then
  172         ID=$(grep '^ID=' /etc/os-release | sed 's/ID=//; s/"//g;')
  173 
  174         case $ID in
  175             fedora|rhel|centos|foobar)
  176             BUILD=redhat
  177             ;;
  178             debian|ubuntu)
  179             BUILD=debian
  180             ;;
  181             opensuse)
  182             BUILD=suse
  183             ;;
  184             alt|basealt|altlinux)
  185             BUILD=alt
  186             ;;
  187             *)
  188             BUILD="$ID"
  189             ;;
  190         esac
  191         elif [ -f /etc/debian_version ]; then
  192         BUILD=debian
  193         elif [ -f /etc/ubuntu_version ]; then
  194         BUILD=debian
  195         elif [ -f /etc/gentoo-release ]; then
  196         BUILD=gentoo
  197         elif [ -f /etc/altlinux-release ]; then
  198         BUILD=alt
  199         elif [ -f /etc/redhat-release ]; then
  200         BUILD=redhat
  201         elif [ -f /etc/SuSE-release ]; then
  202         BUILD=suse
  203         elif [ -f /etc/slackware-version ] ; then
  204         BUILD=slackware
  205         elif [ -f /etc/arch-release ] ; then
  206         BUILD=archlinux
  207         elif [ -f ${CONFDIR}/openwrt_release ]; then
  208         BUILD=openwrt
  209         else
  210         BUILD=linux
  211         fi
  212         ;;
  213     esac
  214 fi
  215 
  216 case $BUILD in
  217     apple)
  218     [ -z "$OWNER" ] && OWNER=root
  219     [ -z "$GROUP" ] && GROUP=wheel
  220     ;;
  221     cygwin*|CYGWIN*)
  222     OWNER=$(id -un)
  223     GROUP=$(id -gn)
  224     ;;
  225     *)
  226     if [ $(id -u) -eq 0 ]; then
  227         [ -z "$OWNER" ] && OWNER=root
  228         [ -z "$GROUP" ] && GROUP=root
  229     fi
  230     ;;
  231 esac
  232 
  233 [ -n "$OWNER" ] && OWNERSHIP="$OWNER:$GROUP"
  234 
  235 [ -n "$HOST" ] || HOST=$BUILD
  236 
  237 case "$HOST" in
  238     debian)
  239     echo "Installing Debian-specific configuration..."
  240     ;;
  241     gentoo)
  242     echo "Installing Gentoo-specific configuration..."
  243     ;;
  244     redhat)
  245     echo "Installing Redhat/Fedora-specific configuration..."
  246     ;;
  247     slackware)
  248     echo "Shorewall-init is currently not supported on Slackware" >&2
  249     exit 1
  250     ;;
  251     archlinux)
  252     echo "Shorewall-init is currently not supported on Arch Linux" >&2
  253     exit 1
  254     ;;
  255     suse)
  256     echo "Installing SuSE-specific configuration..."
  257     ;;
  258     openwrt)
  259     echo "Installing Openwrt-specific configuration..."
  260     ;;
  261     alt)
  262     echo "Installing ALT-specific configuration...";
  263     ;;
  264     linux)
  265     fatal_error "Shorewall-init is not supported on this system"
  266     ;;
  267     *)
  268     fatal_error "Unsupported HOST distribution: \"$HOST\""
  269     ;;
  270 esac
  271 
  272 [ -z "$TARGET" ] && TARGET=$HOST
  273 
  274 if [ -n "$DESTDIR" ]; then
  275     if [ $(id -u) != 0 ] ; then
  276     echo "Not setting file owner/group permissions, not running as root."
  277     OWNERSHIP=""
  278     fi
  279     
  280     make_parent_directory ${DESTDIR}${INITDIR} 0755
  281 fi
  282 
  283 echo "Installing $Product Version $VERSION"
  284 
  285 #
  286 # Check for /usr/share/shorewall-init/version
  287 #
  288 if [ -f ${DESTDIR}${SHAREDIR}/$PRODUCT/version ]; then
  289     first_install=""
  290 else
  291     first_install="Yes"
  292 fi
  293 
  294 [ -n "$DESTDIR" ] && make_parent_directory ${DESTDIR}${CONFDIR}/logrotate.d 0755
  295 
  296 #
  297 # Install the Firewall Script
  298 #
  299 if [ -n "$INITFILE" ]; then
  300     make_parent_directory ${DESTDIR}${INITDIR} 0755
  301     install_file $INITSOURCE ${DESTDIR}${INITDIR}/$INITFILE 0544
  302     [ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${INITDIR}/$INITFILE
  303     
  304     if [ -n "${AUXINITSOURCE}" ]; then
  305     install_file $INITSOURCE ${DESTDIR}${INITDIR}/$AUXINITFILE 0544
  306     fi
  307 
  308     echo  "SysV init script $INITSOURCE installed in ${DESTDIR}${INITDIR}/$INITFILE"
  309 fi
  310 
  311 #
  312 # Install the .service file
  313 #
  314 if [ -z "${SERVICEDIR}" ]; then
  315     SERVICEDIR="$SYSTEMD"
  316 fi
  317 
  318 if [ -n "$SERVICEDIR" ]; then
  319     make_parent_directory ${DESTDIR}${SERVICEDIR} 0755
  320     [ -z "$SERVICEFILE" ] && SERVICEFILE=$PRODUCT.service
  321     install_file $SERVICEFILE ${DESTDIR}${SERVICEDIR}/$PRODUCT.service 0644
  322     [ ${SBINDIR} != /sbin ] && eval sed -i \'s\|/sbin/\|${SBINDIR}/\|\' ${DESTDIR}${SERVICEDIR}/$PRODUCT.service
  323     echo "Service file $SERVICEFILE installed as ${DESTDIR}${SERVICEDIR}/$PRODUCT.service"
  324     [ -n "$DESTDIR" -o $configure -eq 0 ] && make_parent_directory ${DESTDIR}${SBINDIR} 0755
  325     install_file $PRODUCT ${DESTDIR}${SBINDIR}/$PRODUCT 0700
  326     [ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SBINDIR}/$PRODUCT
  327     echo "CLI installed as ${DESTDIR}${SBINDIR}/$PRODUCT"
  328 fi
  329 
  330 #
  331 # Create /usr/share/shorewall-init if needed
  332 #
  333 make_parent_directory ${DESTDIR}${SHAREDIR}/$PRODUCT 0755
  334 
  335 #
  336 # Install logrotate file
  337 #
  338 if [ -d ${DESTDIR}${CONFDIR}/logrotate.d ]; then
  339     install_file logrotate ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT 0644
  340     echo "Logrotate file installed as ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT"
  341 fi
  342 
  343 #
  344 # Create the version file
  345 #
  346 echo "$VERSION" > ${DESTDIR}/${SHAREDIR}/$PRODUCT/version
  347 chmod 0644 ${DESTDIR}${SHAREDIR}/$PRODUCT/version
  348 
  349 #
  350 # Remove and create the symbolic link to the init script
  351 #
  352 if [ -z "$DESTDIR" ]; then
  353     rm -f ${SHAREDIR}/$PRODUCT/init
  354     ln -s ${INITDIR}/${INITFILE} ${SHAREDIR}/$PRODUCT/init
  355 fi
  356 
  357 if [ $HOST = debian ]; then
  358     if [ -n "${DESTDIR}" ]; then
  359     make_parent_directory ${DESTDIR}${ETC}/network/if-up.d 0755
  360     make_parent_directory ${DESTDIR}${ETC}/network/if-post-down.d 0755
  361     elif [ $configure -eq 0 ]; then
  362     make_parent_directory ${CONFDIR}/network/if-up.d 0755
  363     make_parent_directory ${CONFDIR}/network/if-post-down.d 0755
  364     rm -f ${CONFDIR}/network/if-down.d/shorewall
  365     fi
  366 
  367     if [ ! -f ${DESTDIR}${CONFDIR}/default/$PRODUCT ]; then
  368     [ -n "${DESTDIR}" ] && make_parent_directory ${DESTDIR}${ETC}/default 0755
  369 
  370     [ $configure -eq 1 ] || make_parent_directory ${DESTDIR}${CONFDIR}/default 0755
  371     install_file ${SYSCONFFILE} ${DESTDIR}${ETC}/default/$PRODUCT 0644
  372     echo "${SYSCONFFILE} file installed in ${DESTDIR}${SYSCONFDIR}/${PRODUCT}"
  373     fi
  374 
  375     IFUPDOWN=ifupdown.debian.sh
  376 else
  377     if [ -n "$DESTDIR" ]; then
  378     make_parent_directory ${DESTDIR}${SYSCONFDIR} 0755
  379 
  380     if [ -z "$RPM" ]; then
  381         if [ $HOST = suse ]; then
  382         make_parent_directory ${DESTDIR}${ETC}/sysconfig/network/if-up.d 0755
  383         make_parent_directory ${DESTDIR}${ETC}/sysconfig/network/if-down.d 0755
  384         elif [ $HOST = gentoo ]; then
  385         # Gentoo does not support if-{up,down}.d
  386         /bin/true
  387         elif [ $HOST = openwrt ]; then
  388         # Not implemented on OpenWRT
  389         /bin/true
  390         elif [ "$HOST" != debian ]; then
  391         make_parent_directory ${DESTDIR}/${ETC}/NetworkManager/dispatcher.d 0755
  392         fi
  393     fi
  394     fi
  395 
  396     if [ -n "$SYSCONFFILE" -a ! -f ${DESTDIR}${SYSCONFDIR}/${PRODUCT} ]; then
  397     install_file ${SYSCONFFILE} ${DESTDIR}${SYSCONFDIR}/$PRODUCT 0644
  398     echo "${SYSCONFFILE} file installed in ${DESTDIR}${SYSCONFDIR}/${PRODUCT}"
  399     fi
  400 
  401     [ $HOST = suse ] && IFUPDOWN=ifupdown.suse.sh || IFUPDOWN=ifupdown.fedora.sh
  402 fi
  403 
  404 #
  405 # Install the ifupdown script
  406 #
  407 
  408 if [ $HOST != openwrt ]; then
  409     cp $IFUPDOWN ifupdown
  410 
  411     [ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ifupdown
  412 
  413     make_parent_directory ${DESTDIR}${LIBEXECDIR}/$PRODUCT 0755
  414 
  415     install_file ifupdown ${DESTDIR}${LIBEXECDIR}/$PRODUCT/ifupdown 0544
  416 fi
  417 
  418 if [ -d ${DESTDIR}/etc/NetworkManager ]; then
  419     if [ "$HOST" = debian ]; then
  420     rm -f ${DESTDIR}${ETC}/NetworkManager/dispatcher.d/01-shorewall
  421     else
  422     [ $configure -eq 1 ] || make_parent_directory ${DESTDIR}${CONFDIR}/NetworkManager/dispatcher.d 0755
  423     install_file ifupdown ${DESTDIR}${ETC}/NetworkManager/dispatcher.d/01-shorewall 0544
  424     fi
  425 fi
  426 
  427 case $HOST in
  428     debian)
  429     if [ $configure -eq 1 ]; then
  430         install_file ifupdown ${DESTDIR}/etc/network/if-up.d/shorewall 0544
  431         install_file ifupdown ${DESTDIR}/etc/network/if-post-down.d/shorewall 0544
  432         rm -f ${DESTDIR}/etc/network/if-down.d/shorewall
  433     else
  434         install_file ifupdown ${DESTDIR}${CONFDIR}/network/if-up.d/shorewall 0544
  435         install_file ifupdown ${DESTDIR}${CONFDIR}/network/if-post-down.d/shorewall 0544
  436     fi
  437     ;;
  438     suse)
  439     if [ -z "$RPM" ]; then
  440         if [ $configure -eq 0 ]; then
  441         make_parent_directory ${DESTDIR}${SYSCONFDIR}/network/if-up.d 0755
  442         make_parent_directory ${DESTDIR}${SYSCONFDIR}/network/if-down.d 0755
  443         fi
  444 
  445         install_file ifupdown ${DESTDIR}${SYSCONFDIR}/network/if-up.d/shorewall 0544
  446         install_file ifupdown ${DESTDIR}${SYSCONFDIR}/network/if-down.d/shorewall 0544
  447     fi
  448     ;;
  449     redhat)
  450     if [ -z "$DESTDIR" ]; then
  451         install_local=
  452 
  453         if [ -f ${SBINDIR}/ifup-local -o -f ${SBINDIR}/ifdown-local ]; then
  454         if ! grep -qF Shorewall-based ${SBINDIR}/ifup-local || ! grep -qF Shorewall-based ${SBINDIR}/ifdown-local; then
  455             echo "WARNING: ${SBINDIR}/ifup-local and/or ${SBINDIR}/ifdown-local already exist; up/down events will not be handled"
  456         else
  457             install_local=Yes
  458         fi
  459         else
  460         install_local=Yes
  461         fi
  462 
  463         if [ -n "$install_local" ]; then
  464         install_file ifupdown ${DESTDIR}${SBINDIR}/ifup-local 0544
  465         install_file ifupdown ${DESTDIR}${SBINDIR}/ifdown-local 0544
  466         fi
  467     fi
  468     ;;
  469 esac
  470 
  471 if [ -z "$DESTDIR" ]; then
  472     if [ $configure -eq 1 -a -n "first_install" ]; then
  473     if [ $HOST = debian ]; then
  474         if [ -n "$SERVICEDIR" ]; then
  475         if systemctl enable ${PRODUCT}.service; then
  476                     echo "$Product will start automatically at boot"
  477         fi
  478         elif mywhich insserv; then
  479         if insserv ${INITDIR}/$PRODUCT; then
  480                     echo "$Product will start automatically at boot"
  481         else
  482             cant_autostart
  483         fi
  484         elif mywhich update-rc.d ; then
  485         if update-rc.d $PRODUCT enable; then
  486                     echo "$Product will start automatically at boot"
  487             echo "Set startup=1 in ${CONFDIR}/default/$PRODUCT to enable"
  488         else
  489             cant_autostart
  490         fi
  491         else
  492         cant_autostart
  493         fi
  494     elif [ $HOST = openwrt -a -f ${CONFDIR}/rc.common ]; then
  495         /etc/init.d/$PRODUCT enable
  496         if /etc/init.d/$PRODUCT enabled; then
  497         echo "$Product will start automatically at boot"
  498         else
  499         cant_autostart
  500         fi
  501     elif [ $HOST = gentoo ]; then
  502         # On Gentoo, a service must be enabled manually by the user,
  503         # not by the installer
  504         /bin/true
  505     else
  506         if [ -n "$SERVICEDIR" ]; then
  507         if systemctl enable ${PRODUCT}.service; then
  508             echo "$Product will start automatically at boot"
  509         fi
  510         elif [ -x ${SBINDIR}/insserv -o -x /usr${SBINDIR}/insserv ]; then
  511         if insserv ${INITDIR}/$PRODUCT ; then
  512             echo "$Product will start automatically at boot"
  513         else
  514             cant_autostart
  515         fi
  516         elif [ -x ${SBINDIR}/chkconfig -o -x /usr${SBINDIR}/chkconfig ]; then
  517         if chkconfig --add $PRODUCT ; then
  518             echo "$Product will start automatically at boot"
  519             chkconfig --list $PRODUCT
  520         else
  521             cant_autostart
  522         fi
  523         elif [ -x ${SBINDIR}/rc-update ]; then
  524         if rc-update add $PRODUCT default; then
  525             echo "$Product will start automatically at boot"
  526         else
  527             cant_autostart
  528         fi
  529         elif [ $HOST = openwrt -a -f ${CONFDIR}/rc.common ]; then
  530         /etc/init.d/$PRODUCT enable
  531         if /etc/init.d/$PRODUCT enabled; then
  532             echo "$Product will start automatically at boot"
  533         else
  534             cant_autostart
  535         fi
  536         else
  537         cant_autostart
  538         fi
  539     fi
  540     fi
  541 else
  542     if [ $configure -eq 1 -a -n "$first_install" ]; then
  543     if [ $HOST = debian -a -z "$SERVICEDIR" ]; then
  544         if [ -n "${DESTDIR}" ]; then
  545         make_parent_directory ${DESTDIR}/etc/rcS.d 0755
  546         fi
  547 
  548         ln -sf ../init.d/$PRODUCT ${DESTDIR}${CONFDIR}/rcS.d/S38${PRODUCT}
  549         echo "$Product will start automatically at boot"
  550     fi
  551     fi
  552 fi
  553 
  554 [ -z "${DESTDIR}" ] && [ ! -f ~/.shorewallrc ] && cp ${SHAREDIR}/shorewall/shorewallrc .
  555 
  556 if [ -d ${DESTDIR}/etc/ppp ]; then
  557     case $HOST in
  558     debian|suse)
  559         for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do
  560         make_parent_directory ${DESTDIR}/etc/ppp/$directory 0755 #SuSE doesn't create the IPv6 directories
  561         cp -fp ${DESTDIR}${LIBEXECDIR}/$PRODUCT/ifupdown ${DESTDIR}${CONFDIR}/ppp/$directory/shorewall
  562         done
  563         ;;
  564     redhat)
  565         #
  566         # Must use the dreaded ip_xxx.local file
  567         #
  568         for file in ip-up.local ip-down.local; do
  569         FILE=${DESTDIR}/etc/ppp/$file
  570         if [ -f $FILE ]; then
  571             if grep -qF Shorewall-based $FILE ; then
  572             cp -fp ${DESTDIR}${LIBEXECDIR}/$PRODUCT/ifupdown $FILE
  573             else
  574             echo "$FILE already exists -- ppp devices will not be handled"
  575             break
  576             fi
  577         else
  578             cp -fp ${DESTDIR}${LIBEXECDIR}/$PRODUCT/ifupdown $FILE
  579         fi
  580         done
  581         ;;
  582     esac
  583 fi
  584 #
  585 # Report Success
  586 #
  587 echo "shorewall Init Version $VERSION Installed"