~ubuntu-branches/ubuntu/lucid/libwpd/lucid

« back to all changes in this revision

Viewing changes to install-sh

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2007-01-11 15:15:57 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070111151557-rn1kysabqbccx3as
Tags: 0.8.8-2
run make check for stream check; build-depend on libcppunit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
# install - install a program, script, or datafile
3
3
 
4
 
scriptversion=2005-05-14.22
 
4
scriptversion=2004-02-15.20
5
5
 
6
6
# This originates from X11R5 (mit/util/scripts/install.sh), which was
7
7
# later released in X11R6 (xc/config/util/install.sh) with the
58
58
rmprog="${RMPROG-rm}"
59
59
mkdirprog="${MKDIRPROG-mkdir}"
60
60
 
 
61
transformbasename=
 
62
transform_arg=
 
63
instcmd="$mvprog"
61
64
chmodcmd="$chmodprog 0755"
62
65
chowncmd=
63
66
chgrpcmd=
67
70
src=
68
71
dst=
69
72
dir_arg=
70
 
dstarg=
71
 
no_target_directory=
72
73
 
73
 
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
 
74
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
74
75
   or: $0 [OPTION]... SRCFILES... DIRECTORY
75
 
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
76
 
   or: $0 [OPTION]... -d DIRECTORIES...
 
76
   or: $0 -d DIRECTORIES...
77
77
 
78
 
In the 1st form, copy SRCFILE to DSTFILE.
79
 
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
80
 
In the 4th, create DIRECTORIES.
 
78
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
 
79
In the second, create the directory path DIR.
81
80
 
82
81
Options:
83
 
-c         (ignored)
 
82
-b=TRANSFORMBASENAME
 
83
-c         copy source (using $cpprog) instead of moving (using $mvprog).
84
84
-d         create directories instead of installing files.
85
 
-g GROUP   $chgrpprog installed files to GROUP.
86
 
-m MODE    $chmodprog installed files to MODE.
87
 
-o USER    $chownprog installed files to USER.
88
 
-s         $stripprog installed files.
89
 
-t DIRECTORY  install into DIRECTORY.
90
 
-T         report an error if DSTFILE is a directory.
 
85
-g GROUP   $chgrp installed files to GROUP.
 
86
-m MODE    $chmod installed files to MODE.
 
87
-o USER    $chown installed files to USER.
 
88
-s         strip installed files (using $stripprog).
 
89
-t=TRANSFORM
91
90
--help     display this help and exit.
92
91
--version  display version info and exit.
93
92
 
97
96
 
98
97
while test -n "$1"; do
99
98
  case $1 in
100
 
    -c) shift
 
99
    -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
 
100
        shift
 
101
        continue;;
 
102
 
 
103
    -c) instcmd=$cpprog
 
104
        shift
101
105
        continue;;
102
106
 
103
107
    -d) dir_arg=true
109
113
        shift
110
114
        continue;;
111
115
 
112
 
    --help) echo "$usage"; exit $?;;
 
116
    --help) echo "$usage"; exit 0;;
113
117
 
114
118
    -m) chmodcmd="$chmodprog $2"
115
119
        shift
125
129
        shift
126
130
        continue;;
127
131
 
128
 
    -t) dstarg=$2
129
 
        shift
130
 
        shift
131
 
        continue;;
132
 
 
133
 
    -T) no_target_directory=true
134
 
        shift
135
 
        continue;;
136
 
 
137
 
    --version) echo "$0 $scriptversion"; exit $?;;
 
132
    -t=*) transformarg=`echo $1 | sed 's/-t=//'`
 
133
        shift
 
134
        continue;;
 
135
 
 
136
    --version) echo "$0 $scriptversion"; exit 0;;
138
137
 
139
138
    *)  # When -d is used, all remaining arguments are directories to create.
140
 
        # When -t is used, the destination is already specified.
141
 
        test -n "$dir_arg$dstarg" && break
 
139
        test -n "$dir_arg" && break
142
140
        # Otherwise, the last argument is the destination.  Remove it from $@.
143
141
        for arg
144
142
        do
176
174
    src=
177
175
 
178
176
    if test -d "$dst"; then
179
 
      mkdircmd=:
 
177
      instcmd=:
180
178
      chmodcmd=
181
179
    else
182
 
      mkdircmd=$mkdirprog
 
180
      instcmd=$mkdirprog
183
181
    fi
184
182
  else
185
 
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
 
183
    # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
186
184
    # might cause directories to be created, which would be especially bad
187
185
    # if $src (and thus $dsttmp) contains '*'.
188
186
    if test ! -f "$src" && test ! -d "$src"; then
204
202
    # If destination is a directory, append the input filename; won't work
205
203
    # if double slashes aren't ignored.
206
204
    if test -d "$dst"; then
207
 
      if test -n "$no_target_directory"; then
208
 
        echo "$0: $dstarg: Is a directory" >&2
209
 
        exit 1
210
 
      fi
211
205
      dst=$dst/`basename "$src"`
212
206
    fi
213
207
  fi
214
208
 
215
209
  # This sed command emulates the dirname command.
216
 
  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
 
210
  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
217
211
 
218
212
  # Make sure that the destination directory exists.
219
213
 
226
220
    oIFS=$IFS
227
221
    # Some sh's can't handle IFS=/ for some reason.
228
222
    IFS='%'
229
 
    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
230
 
    shift
 
223
    set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
231
224
    IFS=$oIFS
232
225
 
233
226
    pathcomp=
236
229
      pathcomp=$pathcomp$1
237
230
      shift
238
231
      if test ! -d "$pathcomp"; then
239
 
        $mkdirprog "$pathcomp"
 
232
        $mkdirprog "$pathcomp" || lasterr=$?
240
233
        # mkdir can fail with a `File exist' error in case several
241
234
        # install-sh are creating the directory concurrently.  This
242
235
        # is OK.
243
 
        test -d "$pathcomp" || exit
 
236
        test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
244
237
      fi
245
238
      pathcomp=$pathcomp/
246
239
    done
247
240
  fi
248
241
 
249
242
  if test -n "$dir_arg"; then
250
 
    $doit $mkdircmd "$dst" \
 
243
    $doit $instcmd "$dst" \
251
244
      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
252
245
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
253
246
      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
254
247
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
255
248
 
256
249
  else
257
 
    dstfile=`basename "$dst"`
 
250
    # If we're going to rename the final executable, determine the name now.
 
251
    if test -z "$transformarg"; then
 
252
      dstfile=`basename "$dst"`
 
253
    else
 
254
      dstfile=`basename "$dst" $transformbasename \
 
255
               | sed $transformarg`$transformbasename
 
256
    fi
 
257
 
 
258
    # don't allow the sed command to completely eliminate the filename.
 
259
    test -z "$dstfile" && dstfile=`basename "$dst"`
258
260
 
259
261
    # Make a couple of temp file names in the proper directory.
260
262
    dsttmp=$dstdir/_inst.$$_
261
263
    rmtmp=$dstdir/_rm.$$_
262
264
 
263
265
    # Trap to clean up those temp files at exit.
264
 
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
 
266
    trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
265
267
    trap '(exit $?); exit' 1 2 13 15
266
268
 
267
 
    # Copy the file name to the temp name.
268
 
    $doit $cpprog "$src" "$dsttmp" &&
 
269
    # Move or copy the file name to the temp name
 
270
    $doit $instcmd "$src" "$dsttmp" &&
269
271
 
270
272
    # and set any options; do chmod last to preserve setuid bits.
271
273
    #
272
274
    # If any of these fail, we abort the whole thing.  If we want to
273
275
    # ignore errors from any of these, just make sure not to ignore
274
 
    # errors from the above "$doit $cpprog $src $dsttmp" command.
 
276
    # errors from the above "$doit $instcmd $src $dsttmp" command.
275
277
    #
276
278
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
277
279
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
278
280
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
279
281
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
280
282
 
 
283
    # Now remove or move aside any old file at destination location.  We
 
284
    # try this two ways since rm can't unlink itself on some systems and
 
285
    # the destination file might be busy for other reasons.  In this case,
 
286
    # the final cleanup might fail but the new file should still install
 
287
    # successfully.
 
288
    {
 
289
      if test -f "$dstdir/$dstfile"; then
 
290
        $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
 
291
        || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
 
292
        || {
 
293
          echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
 
294
          (exit 1); exit
 
295
        }
 
296
      else
 
297
        :
 
298
      fi
 
299
    } &&
 
300
 
281
301
    # Now rename the file to the real destination.
282
 
    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
283
 
      || {
284
 
           # The rename failed, perhaps because mv can't rename something else
285
 
           # to itself, or perhaps because mv is so ancient that it does not
286
 
           # support -f.
287
 
 
288
 
           # Now remove or move aside any old file at destination location.
289
 
           # We try this two ways since rm can't unlink itself on some
290
 
           # systems and the destination file might be busy for other
291
 
           # reasons.  In this case, the final cleanup might fail but the new
292
 
           # file should still install successfully.
293
 
           {
294
 
             if test -f "$dstdir/$dstfile"; then
295
 
               $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
296
 
               || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
297
 
               || {
298
 
                 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
299
 
                 (exit 1); exit 1
300
 
               }
301
 
             else
302
 
               :
303
 
             fi
304
 
           } &&
305
 
 
306
 
           # Now rename the file to the real destination.
307
 
           $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
308
 
         }
309
 
    }
310
 
  fi || { (exit 1); exit 1; }
 
302
    $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
 
303
  fi || { (exit 1); exit; }
311
304
done
312
305
 
313
306
# The final little trick to "correctly" pass the exit status to the exit trap.
314
307
{
315
 
  (exit 0); exit 0
 
308
  (exit 0); exit
316
309
}
317
310
 
318
311
# Local variables: