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