~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to include/install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2009-05-06 11:29:18 UTC
  • mfrom: (8.1.1 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090506112918-uzoyzcp90rtr8td7
Tags: 3.0.2
New bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
#
 
3
# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
 
4
#
 
5
# This script emulates bsd install and also recognises
 
6
# two environment variables, with the following semantics :-
 
7
#
 
8
# $DIST_MANIFEST - if set, the name of the file to append manifest
 
9
#                  information in the following format:
 
10
#                  File     :  f mode owner group src target
 
11
#                  Directory:  d mode owner group target
 
12
#                  Symlink  :  l linkval target
 
13
#
 
14
# $DIST_ROOT     - if set, prepend to target
 
15
#
 
16
# The sematics of all combinations of these two variables
 
17
# are as follows:
 
18
#
 
19
# $DIST_MANIFEST?  $DIST_ROOT? |   Copy?  Append Manifest?
 
20
# -----------------------------+--------------------------
 
21
#       not set       not set  |    yes        no
 
22
#       not set       set      |    yes        no
 
23
#       set           not set  |    no         yes
 
24
#       set           set      |    yes        yes
 
25
#
 
26
_usage() {
 
27
    echo "Usage: $prog [-o owner] [-g group] [-m mode] -d directory"
 
28
    echo "or     $prog [-D] [-o owner] [-g group] [-m mode] file directory/file"
 
29
    echo "or     $prog [-o owner] [-g group] [-m mode] file [file ...] directory"
 
30
    echo "or     $prog -S file target  (creates \"target\" symlink)"
 
31
    echo "or     $prog -T lt_arg [-o owner] [-g group] [-m mode] libtool.lai directory"
 
32
    echo ""
 
33
    echo "The \$DIST_MANIFEST and \$DIST_ROOT environment variables affect the"
 
34
    echo "behaviour of this command - see comments in the script."
 
35
    echo "The -D flag is only available for the second usage, and causes"
 
36
    echo "the target directory to be created before installing the file."
 
37
    echo ""
 
38
    exit 1
 
39
}
 
40
 
 
41
_chown ()
 
42
{
 
43
    _st=255
 
44
    if [ $# -eq 3 ] ; then
 
45
        chown $1:$2 $3
 
46
        _st=$?
 
47
        if [ $_st -ne 0 ] ; then
 
48
            if [ $REAL_UID != '0' ] ; then
 
49
                if [ ! -f $DIST_ROOT/.chown.quiet ] ; then
 
50
                    echo '==============================================='
 
51
                    echo Ownership of files under ${DIST_ROOT:-/}
 
52
                    echo cannot be changed
 
53
                    echo '==============================================='
 
54
                    if [ -n "$DIST_ROOT" ] ; then
 
55
                        touch $DIST_ROOT/.chown.quiet
 
56
                    fi
 
57
                fi
 
58
               _st=0
 
59
            fi     
 
60
        fi
 
61
    fi
 
62
 
 
63
    return $_st
 
64
}
 
65
 
 
66
 
 
67
_manifest ()
 
68
 
69
    echo $* | sed -e 's/\/\//\//g' >>${DIST_MANIFEST:-/dev/null}
 
70
}
 
71
 
 
72
prog=`basename $0`
 
73
HERE=`pwd`
 
74
dflag=false
 
75
Dflag=false
 
76
Sflag=false
 
77
Tflag=false
 
78
DIRMODE=755
 
79
FILEMODE=644
 
80
OWNER=`id -u`
 
81
GROUP=`id -g`
 
82
REAL_UID=$OWNER
 
83
 
 
84
# default is to install and don't append manifest
 
85
INSTALL=true
 
86
MANIFEST=:
 
87
 
 
88
[ -n "$DIST_MANIFEST" -a -z "$DIST_ROOT" ] && INSTALL=false
 
89
[ -n "$DIST_MANIFEST" ] && MANIFEST="_manifest"
 
90
 
 
91
[ $# -eq 0 ] && _usage
 
92
 
 
93
if $INSTALL
 
94
then
 
95
    CP=cp; LN=ln; MKDIR=mkdir; CHMOD=chmod; CHOWN=_chown
 
96
else
 
97
    CP=true; LN=true; MKDIR=true; CHMOD=true; CHOWN=true
 
98
fi
 
99
 
 
100
[ -n "$DIST_ROOT" -a $REAL_UID -ne 0 ] && CHOWN=true
 
101
 
 
102
while getopts "Dcm:d:S:o:g:T:" c $*
 
103
do
 
104
   case $c in
 
105
   c)
 
106
        ;;
 
107
   g)
 
108
        GROUP=$OPTARG
 
109
        ;;
 
110
   o)
 
111
        OWNER=$OPTARG
 
112
        ;;
 
113
   m)
 
114
        DIRMODE=`expr $OPTARG`
 
115
        FILEMODE=$DIRMODE
 
116
        ;;
 
117
   D) 
 
118
        Dflag=true
 
119
        ;;
 
120
   S) 
 
121
        symlink=$OPTARG
 
122
        Sflag=true
 
123
        ;;
 
124
   d) 
 
125
        dir=$DIST_ROOT/$OPTARG
 
126
        dflag=true
 
127
        ;;
 
128
   T)
 
129
        lt_install=$OPTARG
 
130
        Tflag=true
 
131
        ;;
 
132
   *)
 
133
        _usage
 
134
        ;;
 
135
   esac
 
136
done
 
137
 
 
138
shift `expr $OPTIND - 1`
 
139
 
 
140
status=0
 
141
if $dflag
 
142
then
 
143
    #
 
144
    # first usage
 
145
    #
 
146
    $MKDIR -p $dir 
 
147
    status=$?
 
148
    if [ $status -eq 0 ]
 
149
    then
 
150
        $CHMOD $DIRMODE $dir
 
151
        status=$?
 
152
    fi
 
153
    if [ $status -eq 0 ]
 
154
    then
 
155
        $CHOWN $OWNER $GROUP $dir
 
156
        status=$?
 
157
    fi
 
158
    $MANIFEST d $DIRMODE $OWNER $GROUP ${dir#$DIST_ROOT}
 
159
elif $Sflag
 
160
then
 
161
    #
 
162
    # fourth usage (symlink)
 
163
    #
 
164
    if [ $# -ne 1 ]
 
165
    then
 
166
        _usage
 
167
    else
 
168
        target=$DIST_ROOT/$1
 
169
    fi
 
170
    $LN -s -f $symlink $target
 
171
    status=$?
 
172
    $MANIFEST l $symlink ${target#$DIST_ROOT} 
 
173
elif $Tflag
 
174
then
 
175
    #
 
176
    # -T (install libs built by libtool)
 
177
    #
 
178
    if [ $# -ne 2 ]
 
179
    then
 
180
        _usage
 
181
    else
 
182
        libtool_lai=$1
 
183
        # source the libtool variables
 
184
        if [ ! -f $libtool_lai ]
 
185
        then
 
186
                echo "$prog: Unable to find libtool library file $libtool_lai"
 
187
                exit 2
 
188
        fi
 
189
        . ./$libtool_lai
 
190
        target=$DIST_ROOT/$2
 
191
    fi
 
192
    case $lt_install in
 
193
    so_dot_version)
 
194
        # Loop until we find libfoo.so.x.y.z, then break out.
 
195
        for solib in $library_names
 
196
        do
 
197
                # does it have enough parts?  libfoo.so.x.y.z == 5
 
198
                cnt=`echo "$solib" | sed -e 's/\./ /g' | wc -w`
 
199
                if [ $cnt -eq 5 ]
 
200
                then
 
201
                        install_name=$target/$solib
 
202
                        $CP $solib $install_name
 
203
                        status=$?
 
204
                        $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$solib ${install_name#$DIST_ROOT}
 
205
                        break
 
206
                fi
 
207
        done
 
208
        ;;
 
209
 
 
210
    so_*)
 
211
        case $lt_install in
 
212
        so_dot_current)
 
213
                # ln -s libfoo.so.x.y.z to libfoo.so.x
 
214
                from_parts=5  # libfoo.so.x.y.z
 
215
                to_parts=3    # libfoo.so.x
 
216
                ;;
 
217
        so_base)
 
218
                # ln -s libfoo.so.x to libfoo.so
 
219
                from_parts=3  # libfoo.so.x
 
220
                to_parts=2    # libfoo.so
 
221
                ;;
 
222
        *)
 
223
                echo "$prog: -T $lt_install invalid"
 
224
                exit 2
 
225
                ;;
 
226
        esac
 
227
 
 
228
        # Loop until we find the names, then break out.
 
229
        for solib in $library_names
 
230
        do
 
231
                # does it have enough parts?
 
232
                cnt=`echo "$solib" | sed -e 's/\./ /g' | wc -w`
 
233
                if [ $cnt -eq $from_parts ]
 
234
                then
 
235
                        from_name=$solib
 
236
                elif [ $cnt -eq $to_parts ]
 
237
                then
 
238
                        to_name=$solib
 
239
                fi
 
240
 
 
241
                if [ -n "$from_name" ] && [ -n "$to_name" ]
 
242
                then
 
243
                        install_name=$target/$to_name
 
244
                        $LN -s -f $from_name $install_name
 
245
                        status=$?
 
246
                        $MANIFEST l $from_name ${install_name#$DIST_ROOT}
 
247
                        break
 
248
                fi
 
249
        done
 
250
        ;;
 
251
    old_lib)
 
252
        install_name=$target/$old_library
 
253
        $CP $old_library $install_name
 
254
        status=$?
 
255
        $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$old_library ${install_name#$DIST_ROOT}
 
256
        ;;
 
257
    *)
 
258
        echo "$prog: -T $lt_install invalid"
 
259
        exit 2
 
260
        ;;
 
261
    esac
 
262
 
 
263
    case $lt_install in
 
264
    old_lib|so_dot_version)
 
265
        if [ $status -eq 0 ]
 
266
        then
 
267
                $CHMOD $FILEMODE $install_name
 
268
                $CHOWN $OWNER $GROUP $install_name
 
269
        fi
 
270
        ;;
 
271
    esac
 
272
 
 
273
else
 
274
    list=""
 
275
    dir=""
 
276
    if [ $# -eq 2 ]
 
277
    then
 
278
        #
 
279
        # second usage
 
280
        #
 
281
        f=$1
 
282
        dir=$DIST_ROOT/$2
 
283
        if $Dflag
 
284
        then
 
285
            mkdir -p `dirname $dir`
 
286
        fi
 
287
        $CP $f $dir
 
288
        status=$?
 
289
        if [ $status -eq 0 ]
 
290
        then 
 
291
            if [ -f $dir/$f ]
 
292
            then
 
293
                $CHMOD $FILEMODE $dir/$f
 
294
                status=$?
 
295
                if [ $status -eq 0 ]
 
296
                then
 
297
                    $CHOWN $OWNER $GROUP $dir/$f
 
298
                    status=$?
 
299
                fi
 
300
                $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f
 
301
            else
 
302
                $CHMOD $FILEMODE $dir
 
303
                status=$?
 
304
                if [ $status -eq 0 ]
 
305
                then
 
306
                    $CHOWN $OWNER $GROUP $dir
 
307
                    status=$?
 
308
                fi
 
309
                $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$dir ${dir#$DIST_ROOT}
 
310
            fi
 
311
        fi
 
312
    else
 
313
        #
 
314
        # third usage
 
315
        #
 
316
        n=1
 
317
        while [ $# -gt 0 ]
 
318
        do
 
319
            if [ $# -gt 1 ]
 
320
            then
 
321
                list="$list $1"
 
322
            else
 
323
                dir=$DIST_ROOT/$1
 
324
            fi
 
325
            shift
 
326
        done
 
327
 
 
328
        # echo DIR=$dir list=\"$list\"
 
329
        for f in $list
 
330
        do
 
331
            $CP $f $dir
 
332
            status=$?
 
333
            if [ $status -eq 0 ]
 
334
            then
 
335
                $CHMOD $FILEMODE $dir/$f
 
336
                status=$?
 
337
                if [ $status -eq 0 ]
 
338
                then
 
339
                    $CHOWN $OWNER $GROUP $dir/$f
 
340
                    status=$?
 
341
                fi
 
342
                $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f
 
343
            fi
 
344
            [ $status -ne 0 ] && break
 
345
        done
 
346
    fi
 
347
fi
 
348
 
 
349
exit $status