ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/install-sh
Revision: 33
Committed: Sun Oct 2 20:50:00 2005 UTC (18 years, 5 months ago) by knight
Original Path: ircd-hybrid/install-sh
File size: 6413 byte(s)
Log Message:
- svn:keywords

File Contents

# User Rev Content
1 adx 30 #!/bin/sh
2 knight 31 # $Id$
3 adx 30 #
4     # install - install a program, script, or datafile
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. It can only install one file at a time, a restriction
43     # shared with many OS's install programs.
44    
45    
46     # set DOITPROG to echo to test this script
47    
48     # Don't use :- since 4.3BSD and earlier shells don't like it.
49     doit="${DOITPROG-}"
50    
51    
52     # put in absolute paths if you don't have them in your path; or use env. vars.
53    
54     mvprog="${MVPROG-mv}"
55     cpprog="${CPPROG-cp}"
56     chmodprog="${CHMODPROG-chmod}"
57     chownprog="${CHOWNPROG-chown}"
58     chgrpprog="${CHGRPPROG-chgrp}"
59     stripprog="${STRIPPROG-strip}"
60     rmprog="${RMPROG-rm}"
61     mkdirprog="${MKDIRPROG-mkdir}"
62    
63     transformbasename=""
64     transform_arg=""
65     instcmd="$mvprog"
66     chmodcmd="$chmodprog 0755"
67     chowncmd=""
68     chgrpcmd=""
69     stripcmd=""
70     rmcmd="$rmprog -f"
71     mvcmd="$mvprog"
72     src=""
73     dst=""
74     dir_arg=""
75    
76     while [ x"$1" != x ]; do
77     case $1 in
78     -c) instcmd="$cpprog"
79     shift
80     continue;;
81    
82     -d) dir_arg=true
83     shift
84     continue;;
85    
86     -m) chmodcmd="$chmodprog $2"
87     shift
88     shift
89     continue;;
90    
91     -o) chowncmd="$chownprog $2"
92     shift
93     shift
94     continue;;
95    
96     -g) chgrpcmd="$chgrpprog $2"
97     shift
98     shift
99     continue;;
100    
101     -s) stripcmd="$stripprog"
102     shift
103     continue;;
104    
105     -t=*) transformarg=`echo $1 | sed 's/-t=//'`
106     shift
107     continue;;
108    
109     -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
110     shift
111     continue;;
112    
113     *) if [ x"$src" = x ]
114     then
115     src=$1
116     else
117     # this colon is to work around a 386BSD /bin/sh bug
118     :
119     dst=$1
120     fi
121     shift
122     continue;;
123     esac
124     done
125    
126     if [ x"$src" = x ]
127     then
128     echo "install: no input file specified"
129     exit 1
130     else
131     true
132     fi
133    
134     if [ x"$dir_arg" != x ]; then
135     dst=$src
136     src=""
137    
138     if [ -d $dst ]; then
139     instcmd=:
140     chmodcmd=""
141     else
142     instcmd=mkdir
143     fi
144     else
145    
146     # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
147     # might cause directories to be created, which would be especially bad
148     # if $src (and thus $dsttmp) contains '*'.
149    
150     if [ -f $src -o -d $src ]
151     then
152     true
153     else
154     echo "install: $src does not exist"
155     exit 1
156     fi
157    
158     if [ x"$dst" = x ]
159     then
160     echo "install: no destination specified"
161     exit 1
162     else
163     true
164     fi
165    
166     # If destination is a directory, append the input filename; if your system
167     # does not like double slashes in filenames, you may need to add some logic
168    
169     if [ -d $dst ]
170     then
171     dst="$dst"/`basename $src`
172     else
173     true
174     fi
175     fi
176    
177     ## this sed command emulates the dirname command
178     dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
179    
180     # Make sure that the destination directory exists.
181     # this part is taken from Noah Friedman's mkinstalldirs script
182    
183     # Skip lots of stat calls in the usual case.
184     if [ ! -d "$dstdir" ]; then
185     defaultIFS='
186     '
187     IFS="${IFS-${defaultIFS}}"
188    
189     oIFS="${IFS}"
190     # Some sh's can't handle IFS=/ for some reason.
191     IFS='%'
192     set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
193     IFS="${oIFS}"
194    
195     pathcomp=''
196    
197     while [ $# -ne 0 ] ; do
198     pathcomp="${pathcomp}${1}"
199     shift
200    
201     if [ ! -d "${pathcomp}" ] ;
202     then
203     $mkdirprog "${pathcomp}"
204     else
205     true
206     fi
207    
208     pathcomp="${pathcomp}/"
209     done
210     fi
211    
212     if [ x"$dir_arg" != x ]
213     then
214     $doit $instcmd $dst &&
215    
216     if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
217     if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
218     if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
219     if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
220     else
221    
222     # If we're going to rename the final executable, determine the name now.
223    
224     if [ x"$transformarg" = x ]
225     then
226     dstfile=`basename $dst`
227     else
228     dstfile=`basename $dst $transformbasename |
229     sed $transformarg`$transformbasename
230     fi
231    
232     # don't allow the sed command to completely eliminate the filename
233    
234     if [ x"$dstfile" = x ]
235     then
236     dstfile=`basename $dst`
237     else
238     true
239     fi
240    
241     # Make a temp file name in the proper directory.
242    
243     dsttmp=$dstdir/#inst.$$#
244    
245     # Move or copy the file name to the temp name
246    
247     $doit $instcmd $src $dsttmp &&
248    
249     trap "rm -f ${dsttmp}" 0 &&
250    
251     # and set any options; do chmod last to preserve setuid bits
252    
253     # If any of these fail, we abort the whole thing. If we want to
254     # ignore errors from any of these, just make sure not to ignore
255     # errors from the above "$doit $instcmd $src $dsttmp" command.
256    
257     if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
258     if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
259     if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
260     if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
261    
262     # Now rename the file to the real destination.
263    
264     $doit $rmcmd -f $dstdir/$dstfile &&
265     $doit $mvcmd $dsttmp $dstdir/$dstfile
266    
267     fi &&
268    
269    
270     exit 0

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Id Revision