lilypond-0.1.36
[lilypond.git] / install-sh
blob398f7f861ed6dff0df7186886c23dce4be24bd2d
1 #! /bin/sh
3 # ugr. Why $#^&@ does configure need this?
6 # install - install a program, script, or datafile
7 # This comes from X11R5.
9 # Calling this script install-sh is preferred over install.sh, to prevent
10 # `make' implicit rules from creating a file called install from it
11 # when there is no Makefile.
13 # This script is compatible with the BSD install script, but was written
14 # from scratch.
18 # set DOITPROG to echo to test this script
20 # Don't use :- since 4.3BSD and earlier shells don't like it.
21 doit="${DOITPROG-}"
24 # put in absolute paths if you don't have them in your path; or use env. vars.
26 mvprog="${MVPROG-mv}"
27 cpprog="${CPPROG-cp}"
28 chmodprog="${CHMODPROG-chmod}"
29 chownprog="${CHOWNPROG-chown}"
30 chgrpprog="${CHGRPPROG-chgrp}"
31 stripprog="${STRIPPROG-strip}"
32 rmprog="${RMPROG-rm}"
33 mkdirprog="${MKDIRPROG-mkdir}"
35 transformbasename=""
36 transform_arg=""
37 instcmd="$mvprog"
38 chmodcmd="$chmodprog 0755"
39 chowncmd=""
40 chgrpcmd=""
41 stripcmd=""
42 rmcmd="$rmprog -f"
43 mvcmd="$mvprog"
44 src=""
45 dst=""
46 dir_arg=""
48 while [ x"$1" != x ]; do
49 case $1 in
50 -c) instcmd="$cpprog"
51 shift
52 continue;;
54 -d) dir_arg=true
55 shift
56 continue;;
58 -m) chmodcmd="$chmodprog $2"
59 shift
60 shift
61 continue;;
63 -o) chowncmd="$chownprog $2"
64 shift
65 shift
66 continue;;
68 -g) chgrpcmd="$chgrpprog $2"
69 shift
70 shift
71 continue;;
73 -s) stripcmd="$stripprog"
74 shift
75 continue;;
77 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
78 shift
79 continue;;
81 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
82 shift
83 continue;;
85 *) if [ x"$src" = x ]
86 then
87 src=$1
88 else
89 # this colon is to work around a 386BSD /bin/sh bug
91 dst=$1
93 shift
94 continue;;
95 esac
96 done
98 if [ x"$src" = x ]
99 then
100 echo "install: no input file specified"
101 exit 1
102 else
103 true
106 if [ x"$dir_arg" != x ]; then
107 dst=$src
108 src=""
110 if [ -d $dst ]; then
111 instcmd=:
112 else
113 instcmd=mkdir
115 else
117 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
118 # might cause directories to be created, which would be especially bad
119 # if $src (and thus $dsttmp) contains '*'.
121 if [ -f $src -o -d $src ]
122 then
123 true
124 else
125 echo "install: $src does not exist"
126 exit 1
129 if [ x"$dst" = x ]
130 then
131 echo "install: no destination specified"
132 exit 1
133 else
134 true
137 # If destination is a directory, append the input filename; if your system
138 # does not like double slashes in filenames, you may need to add some logic
140 if [ -d $dst ]
141 then
142 dst="$dst"/`basename $src`
143 else
144 true
148 ## this sed command emulates the dirname command
149 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
151 # Make sure that the destination directory exists.
152 # this part is taken from Noah Friedman's mkinstalldirs script
154 # Skip lots of stat calls in the usual case.
155 if [ ! -d "$dstdir" ]; then
156 defaultIFS='
158 IFS="${IFS-${defaultIFS}}"
160 oIFS="${IFS}"
161 # Some sh's can't handle IFS=/ for some reason.
162 IFS='%'
163 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
164 IFS="${oIFS}"
166 pathcomp=''
168 while [ $# -ne 0 ] ; do
169 pathcomp="${pathcomp}${1}"
170 shift
172 if [ ! -d "${pathcomp}" ] ;
173 then
174 $mkdirprog "${pathcomp}"
175 else
176 true
179 pathcomp="${pathcomp}/"
180 done
183 if [ x"$dir_arg" != x ]
184 then
185 $doit $instcmd $dst &&
187 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
188 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
189 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
190 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
191 else
193 # If we're going to rename the final executable, determine the name now.
195 if [ x"$transformarg" = x ]
196 then
197 dstfile=`basename $dst`
198 else
199 dstfile=`basename $dst $transformbasename |
200 sed $transformarg`$transformbasename
203 # don't allow the sed command to completely eliminate the filename
205 if [ x"$dstfile" = x ]
206 then
207 dstfile=`basename $dst`
208 else
209 true
212 # Make a temp file name in the proper directory.
214 dsttmp=$dstdir/#inst.$$#
216 # Move or copy the file name to the temp name
218 $doit $instcmd $src $dsttmp &&
220 trap "rm -f ${dsttmp}" 0 &&
222 # and set any options; do chmod last to preserve setuid bits
224 # If any of these fail, we abort the whole thing. If we want to
225 # ignore errors from any of these, just make sure not to ignore
226 # errors from the above "$doit $instcmd $src $dsttmp" command.
228 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
229 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
230 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
231 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
233 # Now rename the file to the real destination.
235 $doit $rmcmd -f $dstdir/$dstfile &&
236 $doit $mvcmd $dsttmp $dstdir/$dstfile
238 fi &&
241 exit 0