]> git.ipfire.org Git - thirdparty/cups.git/blame - install-sh
Remove old files.
[thirdparty/cups.git] / install-sh
CommitLineData
ef416fc2 1#!/bin/sh
2#
3# install - install a program, script, or datafile
4# This comes from X11R5 (mit/util/scripts/install.sh).
5#
839a51c8 6# Library stripping changes Copyright 2008 by Apple Inc.
ef416fc2 7# Copyright 1991 by the Massachusetts Institute of Technology
8#
9# Permission to use, copy, modify, distribute, and sell this software and its
10# documentation for any purpose is hereby granted without fee, provided that
11# the above copyright notice appear in all copies and that both that
12# copyright notice and this permission notice appear in supporting
13# documentation, and that the name of M.I.T. not be used in advertising or
14# publicity pertaining to distribution of the software without specific,
15# written prior permission. M.I.T. makes no representations about the
16# suitability of this software for any purpose. It is provided "as is"
17# without express or implied warranty.
18#
19# Calling this script install-sh is preferred over install.sh, to prevent
20# `make' implicit rules from creating a file called install from it
21# when there is no Makefile.
22#
23# This script is compatible with the BSD install script, but was written
24# from scratch. It can only install one file at a time, a restriction
25# shared with many OS's install programs.
26
27
28# set DOITPROG to echo to test this script
29
30# Don't use :- since 4.3BSD and earlier shells don't like it.
31doit="${DOITPROG-}"
32
33
34# put in absolute paths if you don't have them in your path; or use env. vars.
35
36mvprog="${MVPROG-mv}"
37cpprog="${CPPROG-cp}"
38chmodprog="${CHMODPROG-chmod}"
39chownprog="${CHOWNPROG-chown}"
40chgrpprog="${CHGRPPROG-chgrp}"
41stripprog="${STRIPPROG-strip}"
42rmprog="${RMPROG-rm}"
43mkdirprog="${MKDIRPROG-mkdir}"
44
45transformbasename=""
46transform_arg=""
47instcmd="$mvprog"
48chmodcmd="$chmodprog 0755"
49chowncmd=""
50chgrpcmd=""
51stripcmd=""
52rmcmd="$rmprog -f"
53mvcmd="$mvprog"
54src=""
55dst=""
56dir_arg=""
57
58while [ x"$1" != x ]; do
59 case $1 in
60 -c) instcmd="$cpprog"
61 shift
62 continue;;
63
64 -d) dir_arg=true
65 shift
66 continue;;
67
68 -m) chmodcmd="$chmodprog $2"
69 shift
70 shift
71 continue;;
72
73 -o) chowncmd="$chownprog $2"
74 shift
75 shift
76 continue;;
77
78 -g) chgrpcmd="$chgrpprog $2"
79 shift
80 shift
81 continue;;
82
83 -s) stripcmd="$stripprog"
84 shift
85 continue;;
86
87 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
88 shift
89 continue;;
90
91 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
92 shift
93 continue;;
94
95 *) if [ x"$src" = x ]
96 then
97 src=$1
98 else
99 # this colon is to work around a 386BSD /bin/sh bug
100 :
101 dst=$1
102 fi
103 shift
104 continue;;
105 esac
106done
107
108if [ x"$src" = x ]
109then
110 echo "install: no input file specified"
111 exit 1
112else
113 :
114fi
115
116if [ x"$dir_arg" != x ]; then
117 dst=$src
118 src=""
119
120 if [ -d $dst ]; then
121 instcmd=:
122 chmodcmd=""
123 else
124 instcmd=$mkdirprog
125 fi
126else
127
128# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
129# might cause directories to be created, which would be especially bad
130# if $src (and thus $dsttmp) contains '*'.
131
132 if [ -f $src -o -d $src ]
133 then
134 :
135 else
136 echo "install: $src does not exist"
137 exit 1
138 fi
139
140 if [ x"$dst" = x ]
141 then
142 echo "install: no destination specified"
143 exit 1
144 else
145 :
146 fi
147
148# If destination is a directory, append the input filename; if your system
149# does not like double slashes in filenames, you may need to add some logic
150
151 if [ -d $dst ]
152 then
153 dst="$dst"/`basename $src`
154 else
155 :
156 fi
157fi
158
159## this sed command emulates the dirname command
160dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
161
162# Make sure that the destination directory exists.
163# this part is taken from Noah Friedman's mkinstalldirs script
164
165# Skip lots of stat calls in the usual case.
166if [ ! -d "$dstdir" ]; then
167defaultIFS='
168 '
169IFS="${IFS-${defaultIFS}}"
170
171oIFS="${IFS}"
172# Some sh's can't handle IFS=/ for some reason.
173IFS='%'
174set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
175IFS="${oIFS}"
176
177pathcomp=''
178
179while [ $# -ne 0 ] ; do
180 pathcomp="${pathcomp}${1}"
181 shift
182
183 if [ ! -d "${pathcomp}" ] ;
184 then
839a51c8
MS
185 $mkdirprog "${pathcomp}" &&
186 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$pathcomp"; else : ; fi &&
187 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$pathcomp"; else : ; fi
ef416fc2 188 else
189 :
190 fi
191
192 pathcomp="${pathcomp}/"
193done
194fi
195
196if [ x"$dir_arg" != x ]
197then
198 $doit $instcmd $dst &&
199
200 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
201 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
ef416fc2 202 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
203else
204
205# If we're going to rename the final executable, determine the name now.
206
207 if [ x"$transformarg" = x ]
208 then
209 dstfile=`basename $dst`
210 else
211 dstfile=`basename $dst $transformbasename |
212 sed $transformarg`$transformbasename
213 fi
214
215# don't allow the sed command to completely eliminate the filename
216
217 if [ x"$dstfile" = x ]
218 then
219 dstfile=`basename $dst`
220 else
221 :
222 fi
223
839a51c8
MS
224# Check the destination file - for libraries just use the "-x" option to strip
225 case "$dstfile" in
226 *.a | *.dylib | *.sl | *.sl.* | *.so | *.so.*)
227 stripopt="-x"
228 ;;
229 *)
230 stripopt=""
231 ;;
232 esac
233
ef416fc2 234# Make a temp file name in the proper directory.
235
236 dsttmp=$dstdir/#inst.$$#
237
238# Move or copy the file name to the temp name
239
240 $doit $instcmd $src $dsttmp &&
241
242 trap "rm -f ${dsttmp}" 0 &&
243
244# and set any options; do chmod last to preserve setuid bits
245
246# If any of these fail, we abort the whole thing. If we want to
247# ignore errors from any of these, just make sure not to ignore
248# errors from the above "$doit $instcmd $src $dsttmp" command.
249
250 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
251 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
839a51c8 252 if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripopt $dsttmp; else :;fi &&
ef416fc2 253 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
254
255# Now rename the file to the real destination.
256
257 $doit $rmcmd -f $dstdir/$dstfile &&
258 $doit $mvcmd $dsttmp $dstdir/$dstfile
259
260fi &&
261
262
263exit 0