3 # install.sh - portable version of install(1)
6 # install [-CNcs] [-f flags] [-i errs] [-o owner] [-g group] [-m mode] file1 file2 ...
7 # install -d [-i errs] [-o owner] [-g group] [-m mode] directory ...
10 # Compatible with BSD install(1). Except that '-c' is always
11 # true and we always move an already installed target aside as
12 # this is important on many systems. Recent BSD install(1)
13 # versions have a '-b' option for this.
17 # -b move previous target file aside (always true).
20 # use "suffix" instead of .old for saving existing target.
22 # -c copy rather than move the file into place (always true).
24 # -C compare. Only install if target is missing or
27 # -N newer. Only install if target is missing or older.
32 # make target owned by "owner"
35 # make target group owned by "group"
38 # set permissions to "mode"
41 # Pass "flags" onto chflags(1)
44 # Ignore errors from steps indicated by "errs" (``s,o,g,m'').
47 # The '-i' option is to save your sanity when 'bsd.prog.mk'
48 # insists on haveing a '-o' "owner" option which is doomed to
49 # fail on many systems. We ignore '-b', '-B' and '-c' options.
52 # Simon J. Gerraty <sjg@quick.com.au>
56 # $Id: install-sh,v 1.18 2001/03/16 17:33:02 sjg Exp $
58 # @(#) Copyright (c) 1993 Simon J. Gerraty
60 # This file is provided in the hope that it will
61 # be of use. There is absolutely NO WARRANTY.
62 # Permission to copy, redistribute or otherwise
63 # use this file is hereby granted provided that
64 # the above copyright notice and this notice are
67 # Please send copies of changes and bug-fixes to:
71 set -- `getopt B:bpxCNcsdo:g:m:i:f: $*`
74 [ -s $Mydir/.installrc ] && . $Mydir/.installrc
93 -B) OLD_EXT=$2; shift;;
94 -C) compare=Different;;
96 # check if /bin/ls supports -1
97 /bin/ls -1 $0 >/dev/null 2>&1 && LS1=1
99 -o) owner="${CHOWN:-chown} $2 "; shift;;
100 -g) group="${CHGRP:-chgrp} $2 "; shift;;
101 -m) mode="${CHMOD:-chmod} $2 "; shift;;
102 -s) strip=${STRIP:-strip};;
103 -d) mkdirs="mkdir -p";;
104 -i) ignore_err="$ignore_err$2"; shift;;
105 -f) chflags="${CHFLAGS:-chflags} $2 "; shift;;
111 n=`/bin/ls -t$LS1 $* 2>/dev/null | head -1`
121 case "$ignore_err" in
128 # the order is important
139 # a bug in HP-UX's /bin/sh, means we need to re-set $*
140 # after any calls to add_path()
143 # all this just for chown!
144 add_path () { [ -d $1 ] && eval ${2:-PATH}="\$${2:-PATH}:$1"; }
153 # make directories if needed
154 # and ensure mode etc are as desired
155 if [ "$mkdirs" ]; then
158 [ ! -d $d ] && $mkdirs $d
161 exit 0 # that's all we do
165 if [ $# -gt 2 ]; then
167 elif [ $# -eq 1 ]; then
168 echo "what should I do with $*?" >&2
183 if [ "$dest_dir" = yes -a ! -d $dest ]; then
184 echo "no directory $dest" >&2
191 if [ -d $dest ]; then
196 $newer $f $t || continue
197 $compare $f $t || continue
198 [ -f $t ] && { mv -f $t $t.old || exit 1; }
199 { cp $CP_P $f $t && Setem $t; } || exit 1