"Fossies" - the Fresh Open Source Software Archive

Member "shorewall-core-5.2.8/install.sh" (24 Sep 2020, 9607 Bytes) of package /linux/misc/shorewall/shorewall-core-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 Core Modules
    4 #
    5 #     (c) 2000-2018 - 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 PRODUCT=shorewall-core
   27 Product="Shorewall Core"
   28 
   29 usage() # $1 = exit status
   30 {
   31     ME=$(basename $0)
   32     echo "usage: $ME [ <option> ] [ <shorewallrc file> ]"
   33     echo "where <option> is one of"
   34     echo "  -h"
   35     echo "  -v"
   36     exit $1
   37 }
   38 
   39 install_file() # $1 = source $2 = target $3 = mode
   40 {
   41     if cp -f $1 $2; then
   42     if chmod $3 $2; then
   43         if [ -n "$OWNER" ]; then
   44         if chown $OWNER:$GROUP $2; then
   45             return
   46         fi
   47         else
   48         return 0
   49         fi
   50     fi
   51     fi
   52 
   53     echo "ERROR: Failed to install $2" >&2
   54     exit 1
   55 }
   56 
   57 #
   58 # Change to the directory containing this script
   59 #
   60 cd "$(dirname $0)"
   61 
   62 #
   63 # Source common functions
   64 #
   65 . ./lib.installer || { echo "ERROR: Can not load common functions." >&2; exit 1; }
   66 
   67 #
   68 # Parse the run line
   69 #
   70 finished=0
   71 
   72 while [ $finished -eq 0 ]; do
   73     option=$1
   74 
   75     case "$option" in
   76     -*)
   77         option=${option#-}
   78 
   79         while [ -n "$option" ]; do
   80         case $option in
   81             h)
   82             usage 0
   83             ;;
   84             v)
   85             echo "$Product Firewall Installer Version $VERSION"
   86             exit 0
   87             ;;
   88             *)
   89             usage 1
   90             ;;
   91         esac
   92         done
   93 
   94         shift
   95         ;;
   96     *)
   97         finished=1
   98         ;;
   99     esac
  100 done
  101 
  102 #
  103 # Read the RC file
  104 #
  105 if [ $# -eq 0 ]; then
  106     if [ -f ./shorewallrc ]; then
  107     file=./shorewallrc
  108         . $file || fatal_error "Can not load the RC file: $file"
  109     elif [ -f ~/.shorewallrc ]; then
  110     file=~/.shorewallrc
  111         . $file || fatal_error "Can not load the RC file: $file"
  112     elif [ -f /usr/share/shorewall/shorewallrc ]; then
  113     file=/usr/share/shorewall/shorewallrc
  114         . $file || fatal_error "Can not load the RC file: $file"
  115     else
  116     fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
  117     fi
  118 elif [ $# -eq 1 ]; then
  119     file=$1
  120     case $file in
  121     /*|.*)
  122         ;;
  123     *)
  124         file=./$file || exit 1
  125         ;;
  126     esac
  127 
  128     . $file || fatal_error "Can not load the RC file: $file"
  129 else
  130     usage 1
  131 fi
  132 
  133 update=0
  134 
  135 if [ -z "${VARLIB}" ]; then
  136     VARLIB=${VARDIR}
  137     VARDIR="${VARLIB}/${PRODUCT}"
  138     update=1
  139 elif [ -z "${VARDIR}" ]; then
  140     VARDIR="${VARLIB}/${PRODUCT}"
  141     update=2
  142 fi
  143 
  144 for var in SHAREDIR LIBEXECDIR PERLLIBDIR CONFDIR SBINDIR VARLIB VARDIR; do
  145     require $var
  146 done
  147 
  148 [ "${INITFILE}" != 'none/' ] && require INITSOURCE && require INITDIR
  149 
  150 if [ -z "$BUILD" ]; then
  151     case $(uname) in
  152     cygwin*|CYGWIN*)
  153         BUILD=cygwin
  154         ;;
  155     Darwin)
  156         BUILD=apple
  157         ;;
  158     *)
  159         if [ -f /etc/os-release ]; then
  160         eval $(cat /etc/os-release | grep ^ID)
  161 
  162         case $ID in
  163             fedora|rhel|centos|foobar)
  164             BUILD=redhat
  165             ;;
  166             debian)
  167             BUILD=debian
  168             ;;
  169             gentoo)
  170             BUILD=gentoo
  171             ;;
  172             opensuse)
  173             BUILD=suse
  174             ;;
  175             alt|basealt|altlinux)
  176             BUILD=alt
  177             ;;
  178             *)
  179             BUILD="$ID"
  180             ;;
  181         esac
  182         elif [ -f /etc/debian_version ]; then
  183         BUILD=debian
  184         elif [ -f /etc/gentoo-release ]; then
  185         BUILD=gentoo
  186         elif [ -f /etc/altlinux-release ]; then
  187         BUILD=alt
  188         elif [ -f /etc/redhat-release ]; then
  189         BUILD=redhat
  190         elif [ -f /etc/slackware-version ] ; then
  191         BUILD=slackware
  192         elif [ -f /etc/SuSE-release ]; then
  193         BUILD=suse
  194         elif [ -f /etc/arch-release ] ; then
  195         BUILD=archlinux
  196         elif [ -f ${CONFDIR}/openwrt_release ] ; then
  197         BUILD=openwrt
  198         else
  199         BUILD=linux
  200         fi
  201         ;;
  202     esac
  203 fi
  204 
  205 case $BUILD in
  206     cygwin*)
  207     if [ -z "$DESTDIR" ]; then
  208         DEST=
  209         INIT=
  210     fi
  211 
  212     OWNER=$(id -un)
  213     GROUP=$(id -gn)
  214     ;;
  215     apple)
  216     if [ -z "$DESTDIR" ]; then
  217         DEST=
  218         INIT=
  219         SPARSE=Yes
  220     fi
  221 
  222     [ -z "$OWNER" ] && OWNER=root
  223     [ -z "$GROUP" ] && GROUP=wheel
  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 #
  234 # Determine where to install the firewall script
  235 #
  236 
  237 [ -n "$HOST" ] || HOST=$BUILD
  238 
  239 case "$HOST" in
  240     cygwin)
  241     echo "Installing Cygwin-specific configuration..."
  242     ;;
  243     apple)
  244     echo "Installing Mac-specific configuration...";
  245     ;;
  246     debian|gentoo|redhat|slackware|archlinux|linux|suse|openwrt|alt)
  247     ;;
  248     *)
  249     fatal_error "Unknown HOST \"$HOST\""
  250     ;;
  251 esac
  252 
  253 if [ -z "$file" ]; then
  254     if [ $HOST = linux ]; then
  255     file=shorewallrc.default
  256     else
  257     file=shorewallrc.${HOST}
  258     fi
  259 
  260     echo "You have not specified a configuration file and ~/.shorewallrc does not exist" >&2
  261     echo "Shorewall-core $VERSION has determined that the $file configuration is appropriate for your system" >&2
  262     echo "Please review the settings in that file. If you wish to change them, make a copy and modify the copy" >&2
  263     echo "Then re-run install.sh passing either $file or the name of your modified copy" >&2
  264     echo "" >&2
  265     echo "Example:" >&2
  266     echo "" >&2
  267     echo "   ./install.sh $file" >&2
  268     exit 1
  269 fi
  270 
  271 if [ -n "$DESTDIR" ]; then
  272     if [ $BUILD != cygwin ]; then
  273     if [ `id -u` != 0 ] ; then
  274         echo "Not setting file owner/group permissions, not running as root."
  275     fi
  276     fi
  277 fi
  278 
  279 echo "Installing $Product Version $VERSION"
  280 
  281 #
  282 # Create directories
  283 #
  284 make_parent_directory ${DESTDIR}${LIBEXECDIR}/shorewall 0755
  285 
  286 make_parent_directory ${DESTDIR}${SHAREDIR}/shorewall 0755
  287 
  288 make_parent_directory ${DESTDIR}${CONFDIR} 0755
  289 
  290 [ -n "${SYSCONFDIR}" ] && make_parent_directory ${DESTDIR}${SYSCONFDIR} 0755
  291 
  292 if [ -z "${SERVICEDIR}" ]; then
  293     SERVICEDIR="$SYSTEMD"
  294 fi
  295 
  296 [ -n "${SERVICEDIR}" ] && make_parent_directory ${DESTDIR}${SERVICEDIR} 0755
  297 
  298 make_parent_directory ${DESTDIR}${SBINDIR} 0755
  299 
  300 [ -n "${MANDIR}" ] && make_parent_directory ${DESTDIR}${MANDIR} 0755
  301 
  302 if [ -n "${INITFILE}" ]; then
  303     make_parent_directory ${DESTDIR}${INITDIR} 0755
  304 
  305     if [ -n "$AUXINITSOURCE" -a -f "$AUXINITSOURCE" ]; then
  306     install_file $AUXINITSOURCE ${DESTDIR}${INITDIR}/$AUXINITFILE 0544
  307     [ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${INITDIR}/$AUXINITFILE
  308     echo  "SysV init script $AUXINITSOURCE installed in ${DESTDIR}${INITDIR}/$AUXINITFILE"
  309     fi
  310 fi
  311 #
  312 # Note: ${VARDIR} is created at run-time since it has always been
  313 #       a relocatable directory on a per-product basis
  314 #
  315 # Install the CLI
  316 #
  317 install_file shorewall ${DESTDIR}${SBINDIR}/shorewall 0755
  318 [ $SHAREDIR = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SBINDIR}/shorewall
  319 echo "Shorewall CLI program installed in ${DESTDIR}${SBINDIR}/shorewall"
  320 #
  321 # Install wait4ifup
  322 #
  323 install_file wait4ifup ${DESTDIR}${LIBEXECDIR}/shorewall/wait4ifup 0755
  324 
  325 echo
  326 echo "wait4ifup installed in ${DESTDIR}${LIBEXECDIR}/shorewall/wait4ifup"
  327 
  328 #
  329 # Install the libraries
  330 #
  331 for f in lib.* ; do
  332     case $f in
  333         *installer)
  334             ;;
  335         *)
  336             install_file $f ${DESTDIR}${SHAREDIR}/shorewall/$f 0644
  337             echo "Library ${f#*.} file installed as ${DESTDIR}${SHAREDIR}/shorewall/$f"
  338             ;;
  339     esac
  340 done
  341 
  342 if [ $SHAREDIR != /usr/share ]; then
  343     eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SHAREDIR}/shorewall/lib.base
  344     eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SHAREDIR}/shorewall/lib.cli
  345 fi
  346 
  347 #
  348 # Install the Man Pages
  349 #
  350 if [ -n "$MANDIR" ]; then
  351     cd manpages
  352 
  353     [ -n "$INSTALLD" ] || make_parent_directory ${DESTDIR}${MANDIR}/man8 0755
  354 
  355     for f in *.8; do
  356     gzip -9c $f > $f.gz
  357     install_file $f.gz ${DESTDIR}${MANDIR}/man8/$f.gz 0644
  358     echo "Man page $f.gz installed to ${DESTDIR}${MANDIR}/man8/$f.gz"
  359     done
  360 
  361     cd ..
  362 
  363     echo "Man Pages Installed"
  364 fi
  365 
  366 #
  367 # Symbolically link 'functions' to lib.base
  368 #
  369 ln -sf lib.base ${DESTDIR}${SHAREDIR}/shorewall/functions
  370 #
  371 # Create the version file
  372 #
  373 echo "$VERSION" > ${DESTDIR}${SHAREDIR}/shorewall/coreversion
  374 chmod 0644 ${DESTDIR}${SHAREDIR}/shorewall/coreversion
  375 
  376 if [ -z "${DESTDIR}" ]; then
  377     if [ $update -ne 0 ]; then
  378     echo "Updating $file - original saved in $file.bak"
  379 
  380     cp $file $file.bak
  381 
  382     echo '#'                                             >> $file
  383     echo "# Updated by Shorewall-core $VERSION -" `date` >> $file
  384     echo '#'                                             >> $file
  385 
  386     [ $update -eq 1 ] && sed -i 's/VARDIR/VARLIB/' $file
  387 
  388     echo 'VARDIR=${VARLIB}/${PRODUCT}' >> $file
  389     fi
  390 fi
  391 
  392 [ $file != "${DESTDIR}${SHAREDIR}/shorewall/shorewallrc" ] && cp $file ${DESTDIR}${SHAREDIR}/shorewall/shorewallrc
  393 
  394 
  395 [ -z "${DESTDIR}" ] && [ ! -f ~/.shorewallrc ] && cp ${SHAREDIR}/shorewall/shorewallrc ~/.shorewallrc
  396 
  397 if [ ${SHAREDIR} != /usr/share ]; then
  398     for f in lib.*; do
  399         case $f in
  400             *installer)
  401                 ;;
  402             *)
  403                 if [ $BUILD != apple ]; then
  404                     eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SHAREDIR}/shorewall/$f
  405                 else
  406                     eval sed -i \'\' -e \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${SHAREDIR}/shorewall/$f
  407                 fi
  408                 ;;
  409         esac
  410     done
  411 fi
  412 #
  413 # Report Success
  414 #
  415 echo "$Product Version $VERSION Installed"