"Fossies" - the Fresh Open Source Software Archive

Member "bonnie++-1.04/install.sh" (26 May 2000, 4541 Bytes) of package /linux/privat/bonnie++_1.04.tgz:


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.

    1 ##
    2 ##  install -- Install a program, script or datafile
    3 ##  Copyright (c) 1997-2000 Ralf S. Engelschall <rse@engelschall.com>
    4 ##  Originally written for shtool
    5 ##
    6 ##  This file is part of shtool and free software; you can redistribute
    7 ##  it and/or modify it under the terms of the GNU General Public
    8 ##  License as published by the Free Software Foundation; either version
    9 ##  2 of the License, or (at your option) any later version.
   10 ##
   11 ##  This file is distributed in the hope that it will be useful,
   12 ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   14 ##  General Public License for more details.
   15 ##
   16 ##  You should have received a copy of the GNU General Public License
   17 ##  along with this program; if not, write to the Free Software
   18 ##  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
   19 ##  USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
   20 ##
   21 
   22 str_tool="install"
   23 str_usage="[-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>] [-e<ext>] <file> [<file> ...] <path>"
   24 arg_spec="2+"
   25 opt_spec="v.t.c.C.s.m:o:g:e:"
   26 opt_v=no
   27 opt_t=no
   28 opt_c=no
   29 opt_C=no
   30 opt_s=no
   31 opt_m=""
   32 opt_o=""
   33 opt_g=""
   34 opt_e=""
   35 
   36 . ./sh.common
   37 
   38 #   determine source(s) and destination 
   39 argc=$#
   40 srcs=""
   41 while [ $# -gt 1 ]; do
   42     srcs="$srcs $1"
   43     shift
   44 done
   45 dstpath="$1"
   46 
   47 #   type check for destination
   48 dstisdir=0
   49 if [ -d $dstpath ]; then
   50     dstpath=`echo "$dstpath" | sed -e 's:/$::'`
   51     dstisdir=1
   52 fi
   53 
   54 #   consistency check for destination
   55 if [ $argc -gt 2 -a $dstisdir = 0 ]; then
   56     echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
   57     exit 1
   58 fi
   59 
   60 #   iterate over all source(s)
   61 for src in $srcs; do
   62     dst=$dstpath
   63 
   64     #  If destination is a directory, append the input filename
   65     if [ $dstisdir = 1 ]; then
   66         dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
   67         dst="$dst/$dstfile"
   68     fi
   69 
   70     #  Add a possible extension to src and dst
   71     if [ ".$opt_e" != . ]; then
   72         src="$src$opt_e"
   73         dst="$dst$opt_e"
   74     fi
   75 
   76     #  Check for correct arguments
   77     if [ ".$src" = ".$dst" ]; then
   78         echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
   79         continue
   80     fi
   81     if [ -d "$src" ]; then
   82         echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
   83         continue
   84     fi
   85 
   86     #  Make a temp file name in the destination directory
   87     dsttmp=`echo $dst |\
   88             sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
   89                 -e "s;\$;/#INST@$$#;"`
   90 
   91     #  Verbosity
   92     if [ ".$opt_v" = .yes ]; then
   93         echo "$src -> $dst" 1>&2
   94     fi
   95 
   96     #  Copy or move the file name to the temp name
   97     #  (because we might be not allowed to change the source)
   98     if [ ".$opt_C" = .yes ]; then
   99         opt_c=yes
  100     fi
  101     if [ ".$opt_c" = .yes ]; then
  102         if [ ".$opt_t" = .yes ]; then
  103             echo "cp $src $dsttmp" 1>&2
  104         fi
  105         cp $src $dsttmp || exit $?
  106     else
  107         if [ ".$opt_t" = .yes ]; then
  108             echo "mv $src $dsttmp" 1>&2
  109         fi
  110         mv $src $dsttmp || exit $?
  111     fi
  112 
  113     #  Adjust the target file
  114     #  (we do chmod last to preserve setuid bits)
  115     if [ ".$opt_s" = .yes ]; then
  116         if [ ".$opt_t" = .yes ]; then
  117             echo "strip $dsttmp" 1>&2
  118         fi
  119         strip $dsttmp || exit $?
  120     fi
  121     if [ ".$opt_o" != . ]; then
  122         if [ ".$opt_t" = .yes ]; then
  123             echo "chown $opt_o $dsttmp" 1>&2
  124         fi
  125         chown $opt_o $dsttmp || exit $?
  126     fi
  127     if [ ".$opt_g" != . ]; then
  128         if [ ".$opt_t" = .yes ]; then
  129             echo "chgrp $opt_g $dsttmp" 1>&2
  130         fi
  131         chgrp $opt_g $dsttmp || exit $?
  132     fi
  133     if [ ".$opt_m" != . ]; then
  134         if [ ".$opt_t" = .yes ]; then
  135             echo "chmod $opt_m $dsttmp" 1>&2
  136         fi
  137         chmod $opt_m $dsttmp || exit $?
  138     fi
  139 
  140     #   Determine whether to do a quick install
  141     #   (has to be done _after_ the strip was already done)
  142     quick=no
  143     if [ ".$opt_C" = .yes ]; then
  144         if [ -r $dst ]; then
  145             if cmp -s $src $dst; then
  146                 quick=yes
  147             fi
  148         fi
  149     fi
  150 
  151     #   Finally install the file to the real destination
  152     if [ $quick = yes ]; then
  153         if [ ".$opt_t" = .yes ]; then
  154             echo "rm -f $dsttmp" 1>&2
  155         fi
  156         rm -f $dsttmp
  157     else
  158         if [ ".$opt_t" = .yes ]; then
  159             echo "rm -f $dst && mv $dsttmp $dst" 1>&2
  160         fi
  161         rm -f $dst && mv $dsttmp $dst
  162     fi
  163 done
  164