source: rtems-tools/doc/asciidoc/install-sh @ f91e023

4.104.115
Last change on this file since f91e023 was f91e023, checked in by Chris Johns <chrisj@…>, on 02/17/14 at 07:04:46

Add the documentation.

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