"Fossies" - the Fresh Open Source Software Archive

Member "shorewall6-lite-5.2.8/install.sh" (24 Sep 2020, 14881 Bytes) of package /linux/misc/shorewall/shorewall6-lite-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 Lite
    4 #
    5 #     (c) 2000-2016 - Tom Eastep (teastep@shorewall.net)
    6 #
    7 #       Shorewall documentation is available at https://shorewall.org
    8 #
    9 #       This program is part of Shorewall.
   10 #
   11 #   This program is free software; you can redistribute it and/or modify
   12 #   it under the terms of the GNU General Public License as published by the
   13 #       Free Software Foundation, either version 2 of the license or, at your
   14 #       option, any later version.
   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, see <http://www.gnu.org/licenses/>.
   23 #
   24 
   25 VERSION=5.2.8
   26 
   27 usage() # $1 = exit status
   28 {
   29     ME=$(basename $0)
   30     echo "usage: $ME [ <option> ] [ <shorewallrc file> ]"
   31     echo "where <option> is one of"
   32     echo "  -h"
   33     echo "  -v"
   34     echo "  -n"
   35     exit $1
   36 }
   37 
   38 install_file() # $1 = source $2 = target $3 = mode
   39 {
   40     if cp -f $1 $2; then
   41     if chmod $3 $2; then
   42         if [ -n "$OWNER" ]; then
   43         if chown $OWNER:$GROUP $2; then
   44             return
   45         fi
   46         else
   47         return 0
   48         fi
   49     fi
   50     fi
   51 
   52     echo "ERROR: Failed to install $2" >&2
   53     exit 1
   54 }
   55 
   56 #
   57 # Change to the directory containing this script
   58 #
   59 cd "$(dirname $0)"
   60 
   61 if [ -f shorewall-lite.service ]; then
   62     PRODUCT=shorewall-lite
   63     Product="Shorewall Lite"
   64 else
   65     PRODUCT=shorewall6-lite
   66     Product="Shorewall6 Lite"
   67 fi
   68 
   69 #
   70 # Source common functions
   71 #
   72 . ./lib.installer || { echo "ERROR: Can not load common functions." >&2; exit 1; }
   73 
   74 #
   75 # Parse the run line
   76 #
   77 finished=0
   78 configure=1
   79 
   80 while [ $finished -eq 0 ] ; do
   81 
   82     option=$1
   83 
   84     case "$option" in
   85     -*)
   86         option=${option#-}
   87 
   88         while [ -n "$option" ]; do
   89         case $option in
   90             h)
   91             usage 0
   92             ;;
   93             v)
   94             echo "$Product Firewall Installer Version $VERSION"
   95             exit 0
   96             ;;
   97             n*)
   98             configure=0
   99             option=${option#n}
  100             ;;
  101             *)
  102             usage 1
  103             ;;
  104         esac
  105         done
  106 
  107         shift
  108         ;;
  109     *)
  110         finished=1
  111         ;;
  112     esac
  113 done
  114 
  115 #
  116 # Read the RC file
  117 #
  118 if [ $# -eq 0 ]; then
  119     if [ -f ./shorewallrc ]; then
  120     file=./shorewallrc
  121         . $file || fatal_error "Can not load the RC file: $file"
  122     elif [ -f ~/.shorewallrc ]; then
  123     file=~/.shorewallrc
  124         . $file || fatal_error "Can not load the RC file: $file"
  125     elif [ -f /usr/share/shorewall/shorewallrc ]; then
  126     file=/usr/share/shorewall/shorewallrc
  127         . $file || fatal_error "Can not load the RC file: $file"
  128     else
  129     fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
  130     fi
  131 elif [ $# -eq 1 ]; then
  132     file=$1
  133     case $file in
  134     /*|.*)
  135         ;;
  136     *)
  137         file=./$file || exit 1
  138         ;;
  139     esac
  140 
  141     . $file || fatal_error "Can not load the RC file: $file"
  142 else
  143     usage 1
  144 fi
  145 
  146 if [ -z "${VARLIB}" ]; then
  147     VARLIB=${VARDIR}
  148     VARDIR=${VARLIB}/${PRODUCT}
  149 elif [ -z "${VARDIR}" ]; then
  150     VARDIR=${VARLIB}/${PRODUCT}
  151 fi
  152 
  153 for var in SHAREDIR LIBEXECDIR CONFDIR SBINDIR VARLIB VARDIR; do
  154     require $var
  155 done
  156 
  157 [ -n "${INITFILE}" ] && require INITSOURCE && require INITDIR
  158 
  159 PATH=${SBINDIR}:/bin:/usr${SBINDIR}:/usr/bin:/usr/local/bin:/usr/local${SBINDIR}
  160 
  161 [ -n "$SANDBOX" ] && configure=0
  162 
  163 #
  164 # Determine where to install the firewall script
  165 #
  166 cygwin=
  167 
  168 if [ -z "$BUILD" ]; then
  169     case $(uname) in
  170     cygwin*|CYGWIN*)
  171         BUILD=cygwin
  172         ;;
  173     Darwin)
  174         BUILD=apple
  175         ;;
  176     *)
  177         if [ -f /etc/os-release ]; then
  178         eval $(cat /etc/os-release | grep ^ID)
  179 
  180         case $ID in
  181             fedora|rhel|centos|foobar)
  182             BUILD=redhat
  183             ;;
  184             debian)
  185             BUILD=debian
  186             ;;
  187             gentoo)
  188             BUILD=gentoo
  189             ;;
  190             opensuse)
  191             BUILD=suse
  192             ;;
  193             alt|basealt|altlinux)
  194             BUILD=alt
  195             ;;
  196             *)
  197             BUILD="$ID"
  198             ;;
  199         esac
  200         elif [ -f ${CONFDIR}/debian_version ]; then
  201         BUILD=debian
  202         elif [ -f /etc/gentoo-release ]; then
  203         BUILD=gentoo
  204         elif [ -f /etc/altlinux-release ]; then
  205         BUILD=alt
  206         elif [ -f ${CONFDIR}/redhat-release ]; then
  207         BUILD=redhat
  208         elif [ -f ${CONFDIR}/SuSE-release ]; then
  209         BUILD=suse
  210         elif [ -f ${CONFDIR}/slackware-version ] ; then
  211         BUILD=slackware
  212         elif [ -f ${CONFDIR}/arch-release ] ; then
  213         BUILD=archlinux
  214         elif [ -f ${CONFDIR}/openwrt_release ]; then
  215         BUILD=openwrt
  216         else
  217         BUILD=linux
  218         fi
  219         ;;
  220     esac
  221 fi
  222 
  223 case $BUILD in
  224     cygwin*|CYGWIN*)
  225     OWNER=$(id -un)
  226     GROUP=$(id -gn)
  227     ;;
  228     apple)
  229     [ -z "$OWNER" ] && OWNER=root
  230     [ -z "$GROUP" ] && GROUP=wheel
  231     ;;
  232     *)
  233     if [ $(id -u) -eq 0 ]; then
  234         [ -z "$OWNER" ] && OWNER=root
  235         [ -z "$GROUP" ] && GROUP=root
  236     fi
  237     ;;
  238 esac
  239 
  240 [ -n "$OWNER" ] && OWNERSHIP="$OWNER:$GROUP"
  241 
  242 [ -n "$HOST" ] || HOST=$BUILD
  243 
  244 case "$HOST" in
  245     cygwin)
  246     echo "$PRODUCT is not supported on Cygwin" >&2
  247     exit 1
  248     ;;
  249     apple)
  250     echo "$PRODUCT is not supported on OS X" >&2
  251     exit 1
  252     ;;
  253     debian)
  254     echo "Installing Debian-specific configuration..."
  255     ;;
  256     gentoo)
  257     echo "Installing Gentoo-specific configuration..."
  258     ;;
  259     redhat)
  260     echo "Installing Redhat/Fedora-specific configuration..."
  261     ;;
  262     slackware)
  263     echo "Installing Slackware-specific configuration..."
  264     ;;
  265     archlinux)
  266     echo "Installing ArchLinux-specific configuration..."
  267     ;;
  268     suse)
  269     echo "Installing Suse-specific configuration..."
  270     ;;
  271     openwrt)
  272     echo "Installing OpenWRT-specific configuration..."
  273     ;;
  274     alt)
  275     echo "Installing ALT-specific configuration...";
  276     ;;
  277     linux)
  278     ;;
  279     *)
  280     fatal_error "ERROR: Unknown HOST \"$HOST\""
  281     ;;
  282 esac
  283 
  284 [ -z "$INITDIR" ] && INITDIR="${CONFDIR}/init.d"
  285 
  286 if [ -n "$DESTDIR" ]; then
  287     if [ `id -u` != 0 ] ; then
  288     echo "Not setting file owner/group permissions, not running as root."
  289     OWNERSHIP=""
  290     fi
  291 
  292     make_parent_directory ${DESTDIR}${INITDIR} 0755
  293 
  294 else
  295     if [ ! -f ${SHAREDIR}/shorewall/coreversion ]; then
  296     echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2
  297     exit 1
  298     fi
  299 fi
  300 
  301 echo "Installing $Product Version $VERSION"
  302 
  303 #
  304 # Check for ${CONFDIR}/$PRODUCT
  305 #
  306 if [ -z "$DESTDIR" -a -d ${CONFDIR}/$PRODUCT ]; then
  307     if [ ! -f ${SHAREDIR}/shorewall/coreversion ]; then
  308     echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2
  309     exit 1
  310     fi
  311 
  312     [ -f ${CONFDIR}/$PRODUCT/shorewall.conf ] && \
  313     mv -f ${CONFDIR}/$PRODUCT/shorewall.conf ${CONFDIR}/$PRODUCT/$PRODUCT.conf
  314 else
  315     rm -rf ${DESTDIR}${CONFDIR}/$PRODUCT
  316     rm -rf ${DESTDIR}${SHAREDIR}/$PRODUCT
  317     rm -rf ${DESTDIR}${VARDIR}
  318     [ "$LIBEXECDIR" = /usr/share ] || rm -rf ${DESTDIR}/usr/share/$PRODUCT/wait4ifup ${DESTDIR}/usr/share/$PRODUCT/shorecap
  319 fi
  320 
  321 #
  322 # Check for ${SHAREDIR}/$PRODUCT/version
  323 #
  324 if [ -f ${DESTDIR}${SHAREDIR}/$PRODUCT/version ]; then
  325     first_install=""
  326 else
  327     first_install="Yes"
  328 fi
  329 
  330 delete_file ${DESTDIR}/usr/share/$PRODUCT/xmodules
  331 
  332 [ -n "${INITFILE}" ] && make_parent_directory ${DESTDIR}${INITDIR} 0755
  333 
  334 #
  335 # Create ${CONFDIR}/$PRODUCT, /usr/share/$PRODUCT and /var/lib/$PRODUCT if needed
  336 #
  337 make_parent_directory ${DESTDIR}${CONFDIR}/$PRODUCT 0755
  338 make_parent_directory ${DESTDIR}${SHAREDIR}/$PRODUCT 0755
  339 make_parent_directory ${DESTDIR}${LIBEXECDIR}/$PRODUCT 0755
  340 make_parent_directory ${DESTDIR}${SBINDIR} 0755
  341 make_parent_directory ${DESTDIR}${VARDIR} 0755
  342 
  343 if [ -n "$DESTDIR" ]; then
  344     make_parent_directory ${DESTDIR}${CONFDIR}/logrotate.d 0755
  345     make_parent_directory ${DESTDIR}${INITDIR} 0755
  346 fi
  347 
  348 if [ -n "$INITFILE" ]; then
  349     if [ -f "${INITSOURCE}" ]; then
  350     initfile="${DESTDIR}${INITDIR}/${INITFILE}"
  351     install_file ${INITSOURCE} "$initfile" 0544
  352 
  353     [ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' "$initfile"
  354 
  355     echo  "SysV init script $INITSOURCE installed in $initfile"
  356     fi
  357 fi
  358 #
  359 # Install the .service file
  360 #
  361 if [ -z "${SERVICEDIR}" ]; then
  362     SERVICEDIR="$SYSTEMD"
  363 fi
  364 
  365 if [ -n "$SERVICEDIR" ]; then
  366     make_parent_directory ${DESTDIR}${SERVICEDIR} 0755
  367     [ -z "$SERVICEFILE" ] && SERVICEFILE=$PRODUCT.service
  368     install_file $SERVICEFILE ${DESTDIR}${SERVICEDIR}/$PRODUCT.service 0644
  369     [ ${SBINDIR} != /sbin ] && eval sed -i \'s\|/sbin/\|${SBINDIR}/\|\' ${DESTDIR}${SERVICEDIR}/$PRODUCT.service
  370     echo "Service file $SERVICEFILE installed as ${DESTDIR}${SERVICEDIR}/$PRODUCT.service"
  371 fi
  372 #
  373 # Install the config file
  374 #
  375 if [ ! -f ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf ]; then
  376    install_file $PRODUCT.conf ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf 0744
  377    echo "Config file installed as ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf"
  378 fi
  379 
  380 if [ $HOST = archlinux ] ; then
  381    sed -e 's!LOGFILE=/var/log/messages!LOGFILE=/var/log/messages.log!' -i ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf
  382 elif [ $HOST = gentoo ]; then
  383     # Adjust SUBSYSLOCK path (see https://bugs.gentoo.org/show_bug.cgi?id=459316)
  384     perl -p -w -i -e "s|^SUBSYSLOCK=.*|SUBSYSLOCK=/run/lock/$PRODUCT|;" ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf
  385 fi
  386 #
  387 # Install the default config path file
  388 #
  389 install_file configpath ${DESTDIR}${SHAREDIR}/$PRODUCT/configpath 0644
  390 echo "Default config path file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/configpath"
  391 
  392 #
  393 # Install the libraries
  394 #
  395 for f in lib.* ; do
  396     if [ -f $f ]; then
  397         case $f in
  398             *installer)
  399                 ;;
  400             *)
  401                 install_file $f ${DESTDIR}${SHAREDIR}/$PRODUCT/$f 0644
  402                 echo "Library ${f#*.} file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/$f"
  403                 ;;
  404         esac
  405     fi
  406 done
  407 
  408 ln -sf lib.base ${DESTDIR}${SHAREDIR}/$PRODUCT/functions
  409 
  410 echo "Common functions linked through ${DESTDIR}${SHAREDIR}/$PRODUCT/functions"
  411 
  412 #
  413 # Install Shorecap
  414 #
  415 
  416 install_file shorecap ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap 0755
  417 [ $SHAREDIR = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap
  418 
  419 echo
  420 echo "Capability file builder installed in ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap"
  421 
  422 #
  423 # Install the Modules files
  424 #
  425 
  426 if [ -f modules ]; then
  427     install_file modules ${DESTDIR}${SHAREDIR}/$PRODUCT/modules 0600
  428     echo "Modules file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/modules"
  429 
  430     for f in modules.*; do
  431     install_file $f ${DESTDIR}${SHAREDIR}/$PRODUCT/$f 0644
  432     echo "Module file $f installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/$f"
  433     done
  434 fi
  435 
  436 if [ -f helpers ]; then
  437     install_file helpers ${DESTDIR}${SHAREDIR}/$PRODUCT/helpers 0600
  438     echo "Helper modules file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/helpers"
  439 fi
  440 
  441 #
  442 # Install the Man Pages
  443 #
  444 
  445 if [ -d manpages -a -n "$MANDIR" ]; then
  446     cd manpages
  447 
  448     make_parent_directory ${DESTDIR}${MANDIR}/man5 0755
  449 
  450     for f in *.5; do
  451     gzip -c $f > $f.gz
  452     install_file $f.gz ${DESTDIR}${MANDIR}/man5/$f.gz 0644
  453     echo "Man page $f.gz installed to ${DESTDIR}${MANDIR}/man5/$f.gz"
  454     done
  455 
  456     make_parent_directory ${DESTDIR}${MANDIR}/man8 0755
  457 
  458     for f in *.8; do
  459     gzip -c $f > $f.gz
  460     install_file $f.gz ${DESTDIR}${MANDIR}/man8/$f.gz 0644
  461     echo "Man page $f.gz installed to ${DESTDIR}${MANDIR}/man8/$f.gz"
  462     done
  463 
  464     cd ..
  465 
  466     echo "Man Pages Installed"
  467 fi
  468 
  469 if [ -d ${DESTDIR}${CONFDIR}/logrotate.d ]; then
  470     install_file logrotate ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT 0644
  471     echo "Logrotate file installed as ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT"
  472 fi
  473 
  474 #
  475 # Create the version file
  476 #
  477 echo "$VERSION" > ${DESTDIR}${SHAREDIR}/$PRODUCT/version
  478 chmod 0644 ${DESTDIR}${SHAREDIR}/$PRODUCT/version
  479 #
  480 # Remove and create the symbolic link to the init script
  481 #
  482 
  483 if [ -z "${DESTDIR}" -a -n "${INITFILE}" ]; then
  484     rm -f ${SHAREDIR}/$PRODUCT/init
  485     ln -s ${INITDIR}/${INITFILE} ${SHAREDIR}/$PRODUCT/init
  486 fi
  487 
  488 delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/lib.common
  489 delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/lib.cli
  490 delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/wait4ifup
  491 
  492 #
  493 #  Creatae the symbolic link for the CLI
  494 #
  495 ln -sf shorewall ${DESTDIR}${SBINDIR}/${PRODUCT}
  496 
  497 #
  498 # Note -- not all packages will have the SYSCONFFILE so we need to check for its existance here
  499 #
  500 if [ -n "$SYSCONFFILE" -a -f "$SYSCONFFILE" -a ! -f ${DESTDIR}${SYSCONFDIR}/${PRODUCT} ]; then
  501     [ ${DESTDIR} ] && make_parent_directory ${DESTDIR}${SYSCONFDIR} 0755
  502 
  503     install_file ${SYSCONFFILE} ${DESTDIR}${SYSCONFDIR}/${PRODUCT} 0640
  504     echo "$SYSCONFFILE file installed in ${DESTDIR}${SYSCONFDIR}/${PRODUCT}"
  505 fi
  506 
  507 if [ ${SHAREDIR} != /usr/share ]; then
  508     eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SHAREDIR}/${PRODUCT}/lib.base
  509 fi
  510 
  511 if [ $configure -eq 1 -a -z "$DESTDIR" -a -n "$first_install" -a -z "${cygwin}${mac}" ]; then
  512     if [ -n "$SERVICEDIR" ]; then
  513     if systemctl enable ${PRODUCT}.service; then
  514         echo "$Product will start automatically at boot"
  515     fi
  516     elif mywhich insserv; then
  517     if insserv ${INITDIR}/${INITFILE} ; then
  518         echo "$PRODUCT will start automatically at boot"
  519         if [ $HOST = debian ]; then
  520         echo "Set startup=1 in ${CONFDIR}/default/$PRODUCT to enable"
  521         touch /var/log/$PRODUCT-init.log
  522         perl -p -w -i -e 's/^STARTUP_ENABLED=No/STARTUP_ENABLED=Yes/;s/^IP_FORWARDING=On/IP_FORWARDING=Keep/;s/^SUBSYSLOCK=.*/SUBSYSLOCK=/;' ${CONFDIR}/$PRODUCT/$PRODUCT.conf
  523         else
  524         echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/$PRODUCT.conf to enable"
  525         fi
  526     else
  527         cant_autostart
  528     fi
  529     elif mywhich chkconfig; then
  530     if chkconfig --add $PRODUCT ; then
  531         echo "$PRODUCT will start automatically in run levels as follows:"
  532         echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/${PRODUCT}.conf to enable"
  533         chkconfig --list $PRODUCT
  534     else
  535         cant_autostart
  536     fi
  537     elif mywhich update-rc.d ; then
  538     echo "$PRODUCT will start automatically at boot"
  539     echo "Set startup=1 in ${CONFDIR}/default/$PRODUCT to enable"
  540     touch /var/log/$PRODUCT-init.log
  541     perl -p -w -i -e 's/^STARTUP_ENABLED=No/STARTUP_ENABLED=Yes/;s/^IP_FORWARDING=On/IP_FORWARDING=Keep/;s/^SUBSYSLOCK=.*/SUBSYSLOCK=/;' ${CONFDIR}/$PRODUCT/$PRODUCT.conf
  542     update-rc.d $PRODUCT enable
  543     elif mywhich rc-update ; then
  544     if rc-update add $PRODUCT default; then
  545         echo "$PRODUCT will start automatically at boot"
  546         if [ $HOST = debian ]; then
  547         echo "Set startup=1 in ${CONFDIR}/default/$PRODUCT to enable"
  548         touch /var/log/$PRODUCT-init.log
  549         perl -p -w -i -e 's/^STARTUP_ENABLED=No/STARTUP_ENABLED=Yes/;s/^IP_FORWARDING=On/IP_FORWARDING=Keep/;s/^SUBSYSLOCK=.*/SUBSYSLOCK=/;' ${CONFDIR}/$PRODUCT/$PRODUCT.conf
  550         else
  551         echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/$PRODUCT.conf to enable"
  552         fi
  553     else
  554         cant_autostart
  555     fi
  556     elif [ $HOST = openwrt -a -f ${CONFDIR}/rc.common ]; then
  557     /etc/init.d/$PRODUCT enable
  558     if /etc/init.d/$PRODUCT enabled; then
  559             echo "$PRODUCT will start automatically at boot"
  560     else
  561             cant_autostart
  562     fi
  563     elif [ "$INITFILE" != rc.${PRODUCT} ]; then #Slackware starts this automatically
  564     cant_autostart
  565     fi
  566 fi
  567 
  568 #
  569 # Report Success
  570 #
  571 echo "$Product Version $VERSION Installed"