source: trunk/essentials/sys-devel/m4/install-sh@ 3137

Last change on this file since 3137 was 3090, checked in by bird, 19 years ago

m4 1.4.8

File size: 12.9 KB
Line 
1#!/bin/sh
2# install - install a program, script, or datafile
3
4scriptversion=2006-10-14.15
5
6# This originates from X11R5 (mit/util/scripts/install.sh), which was
7# later released in X11R6 (xc/config/util/install.sh) with the
8# following copyright and license.
9#
10# Copyright (C) 1994 X Consortium
11#
12# Permission is hereby granted, free of charge, to any person obtaining a copy
13# of this software and associated documentation files (the "Software"), to
14# deal in the Software without restriction, including without limitation the
15# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16# sell copies of the Software, and to permit persons to whom the Software is
17# furnished to do so, subject to the following conditions:
18#
19# The above copyright notice and this permission notice shall be included in
20# all copies or substantial portions of the Software.
21#
22# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28#
29# Except as contained in this notice, the name of the X Consortium shall not
30# be used in advertising or otherwise to promote the sale, use or other deal-
31# ings in this Software without prior written authorization from the X Consor-
32# tium.
33#
34#
35# FSF changes to this file are in the public domain.
36#
37# Calling this script install-sh is preferred over install.sh, to prevent
38# `make' implicit rules from creating a file called install from it
39# when there is no Makefile.
40#
41# This script is compatible with the BSD install script, but was written
42# from scratch.
43
44nl='
45'
46IFS=" "" $nl"
47
48# set DOITPROG to echo to test this script
49
50# Don't use :- since 4.3BSD and earlier shells don't like it.
51doit="${DOITPROG-}"
52if test -z "$doit"; then
53 doit_exec=exec
54else
55 doit_exec=$doit
56fi
57
58# Put in absolute file names if you don't have them in your path;
59# or use environment vars.
60
61mvprog="${MVPROG-mv}"
62cpprog="${CPPROG-cp}"
63chmodprog="${CHMODPROG-chmod}"
64chownprog="${CHOWNPROG-chown}"
65chgrpprog="${CHGRPPROG-chgrp}"
66stripprog="${STRIPPROG-strip}"
67rmprog="${RMPROG-rm}"
68mkdirprog="${MKDIRPROG-mkdir}"
69
70posix_glob=
71posix_mkdir=
72
73# Desired mode of installed file.
74mode=0755
75
76chmodcmd=$chmodprog
77chowncmd=
78chgrpcmd=
79stripcmd=
80rmcmd="$rmprog -f"
81mvcmd="$mvprog"
82src=
83dst=
84dir_arg=
85dstarg=
86no_target_directory=
87
88usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
89 or: $0 [OPTION]... SRCFILES... DIRECTORY
90 or: $0 [OPTION]... -t DIRECTORY SRCFILES...
91 or: $0 [OPTION]... -d DIRECTORIES...
92
93In the 1st form, copy SRCFILE to DSTFILE.
94In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
95In the 4th, create DIRECTORIES.
96
97Options:
98-c (ignored)
99-d create directories instead of installing files.
100-g GROUP $chgrpprog installed files to GROUP.
101-m MODE $chmodprog installed files to MODE.
102-o USER $chownprog installed files to USER.
103-s $stripprog installed files.
104-t DIRECTORY install into DIRECTORY.
105-T report an error if DSTFILE is a directory.
106--help display this help and exit.
107--version display version info and exit.
108
109Environment variables override the default commands:
110 CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
111"
112
113while test $# -ne 0; do
114 case $1 in
115 -c) shift
116 continue;;
117
118 -d) dir_arg=true
119 shift
120 continue;;
121
122 -g) chgrpcmd="$chgrpprog $2"
123 shift
124 shift
125 continue;;
126
127 --help) echo "$usage"; exit $?;;
128
129 -m) mode=$2
130 shift
131 shift
132 case $mode in
133 *' '* | *' '* | *'
134'* | *'*'* | *'?'* | *'['*)
135 echo "$0: invalid mode: $mode" >&2
136 exit 1;;
137 esac
138 continue;;
139
140 -o) chowncmd="$chownprog $2"
141 shift
142 shift
143 continue;;
144
145 -s) stripcmd=$stripprog
146 shift
147 continue;;
148
149 -t) dstarg=$2
150 shift
151 shift
152 continue;;
153
154 -T) no_target_directory=true
155 shift
156 continue;;
157
158 --version) echo "$0 $scriptversion"; exit $?;;
159
160 --) shift
161 break;;
162
163 -*) echo "$0: invalid option: $1" >&2
164 exit 1;;
165
166 *) break;;
167 esac
168done
169
170if test $# -ne 0 && test -z "$dir_arg$dstarg"; then
171 # When -d is used, all remaining arguments are directories to create.
172 # When -t is used, the destination is already specified.
173 # Otherwise, the last argument is the destination. Remove it from $@.
174 for arg
175 do
176 if test -n "$dstarg"; then
177 # $@ is not empty: it contains at least $arg.
178 set fnord "$@" "$dstarg"
179 shift # fnord
180 fi
181 shift # arg
182 dstarg=$arg
183 done
184fi
185
186if test $# -eq 0; then
187 if test -z "$dir_arg"; then
188 echo "$0: no input file specified." >&2
189 exit 1
190 fi
191 # It's OK to call `install-sh -d' without argument.
192 # This can happen when creating conditional directories.
193 exit 0
194fi
195
196if test -z "$dir_arg"; then
197 trap '(exit $?); exit' 1 2 13 15
198
199 # Set umask so as not to create temps with too-generous modes.
200 # However, 'strip' requires both read and write access to temps.
201 case $mode in
202 # Optimize common cases.
203 *644) cp_umask=133;;
204 *755) cp_umask=22;;
205
206 *[0-7])
207 if test -z "$stripcmd"; then
208 u_plus_rw=
209 else
210 u_plus_rw='% 200'
211 fi
212 cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
213 *)
214 if test -z "$stripcmd"; then
215 u_plus_rw=
216 else
217 u_plus_rw=,u+rw
218 fi
219 cp_umask=$mode$u_plus_rw;;
220 esac
221fi
222
223for src
224do
225 # Protect names starting with `-'.
226 case $src in
227 -*) src=./$src ;;
228 esac
229
230 if test -n "$dir_arg"; then
231 dst=$src
232 dstdir=$dst
233 test -d "$dstdir"
234 dstdir_status=$?
235 else
236
237 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
238 # might cause directories to be created, which would be especially bad
239 # if $src (and thus $dsttmp) contains '*'.
240 if test ! -f "$src" && test ! -d "$src"; then
241 echo "$0: $src does not exist." >&2
242 exit 1
243 fi
244
245 if test -z "$dstarg"; then