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@crufty.net>
56 # $Id: install-sh,v 1.22 2023/01/28 16:21:19 sjg Exp $
58 # @(#) Copyright (c) 1993-2023 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
94 -B) OLD_EXT=$2; shift;;
95 -C) compare=Different;;
97 # check if /bin/ls supports -1
98 'ls' -1 $0 > /dev/null 2>&1 && LS_1=1
100 -o) owner="${CHOWN:-chown} $2 "; shift;;
101 -g) group="${CHGRP:-chgrp} $2 "; shift;;
102 -m) MODE=$2 mode="${CHMOD:-chmod} $2 "; shift;;
103 -s) strip=${STRIP:-strip};;
104 -d) mkdirs="mkdir -p";;
105 -i) ignore_err="$ignore_err$2"; shift;;
106 -f) chflags="${CHFLAGS:-chflags} $2 "; shift;;
113 n=`'ls' -t$LS_1 $* 2> /dev/null | head -1`
123 case "$ignore_err" in
130 # the order is important
141 # a bug in HP-UX's /bin/sh, means we need to re-set $*
142 # after any calls to add_path()
167 # make directories if needed
168 # and ensure mode etc are as desired
169 if [ "$mkdirs" ]; then
172 # make sure umask is compatible
174 ????*) MODE=`echo $MODE | sed 's,.*\(...\)$,\1,'`;;
176 umask `expr 0777 - 0$MODE |
177 sed 's,^,000,;s,^.*\(...\)$,\1,'`;;
181 [ ! -d $d ] && $mkdirs $d
184 exit 0 # that's all we do
188 if [ $# -gt 2 ]; then
190 elif [ $# -eq 1 ]; then
191 echo "what should I do with $*?" >&2
206 if [ "$dest_dir" = yes -a ! -d $dest ]; then
207 echo "no directory $dest" >&2
214 if [ -d $dest ]; then
219 $newer $f $t || continue
220 $compare $f $t || continue
221 [ -f $t ] && { mv -f $t $t.old || exit 1; }
222 { cp $CP_p $f $t && Setem $t; } || exit 1