The R Project SVN R

Rev

Rev 26592 | Rev 33038 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26592 Rev 28188
Line 1... Line 1...
1
#!/bin/sh
1
#!/bin/sh
2
# install - install a program, script, or datafile
2
# install - install a program, script, or datafile
3
 
3
 
4
scriptversion=2003-09-24.23
4
scriptversion=2004-01-13.14
5
 
5
 
6
# This originates from X11R5 (mit/util/scripts/install.sh), which was
6
# This originates from X11R5 (mit/util/scripts/install.sh), which was
7
# later released in X11R6 (xc/config/util/install.sh) with the
7
# later released in X11R6 (xc/config/util/install.sh) with the
8
# following copyright and license.
8
# following copyright and license.
9
#
9
#
Line 70... Line 70...
70
src=
70
src=
71
dst=
71
dst=
72
dir_arg=
72
dir_arg=
73
 
73
 
74
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
74
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
-
 
75
   or: $0 [OPTION]... SRCFILES... DIRECTORY
75
   or: $0 -d DIR1 DIR2...
76
   or: $0 -d DIRECTORIES...
76
 
77
 
77
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
78
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
78
In the second, create the directory path DIR.
79
In the second, create the directory path DIR.
79
 
80
 
80
Options:
81
Options:
Line 132... Line 133...
132
        shift
133
        shift
133
        continue;;
134
        continue;;
134
 
135
 
135
    --version) echo "$0 $scriptversion"; exit 0;;
136
    --version) echo "$0 $scriptversion"; exit 0;;
136
 
137
 
-
 
138
    *)  # When -d is used, all remaining arguments are directories to create.
137
    *)  if test -z "$src"; then
139
	test -n "$dir_arg" && break
-
 
140
        # Otherwise, the last argument is the destination.  Remove it from $@.
138
          src=$1
141
	for arg
-
 
142
	do
139
        else
143
          if test -n "$dstarg"; then
140
          # this colon is to work around a 386BSD /bin/sh bug
144
	    # $@ is not empty: it contains at least $arg.
141
          :
145
	    set fnord "$@" "$dstarg"
142
          dst=$1
146
	    shift # fnord
143
        fi
147
	  fi
144
        shift
148
	  shift # arg
145
        continue;;
149
	  dstarg=$arg
-
 
150
	done
-
 
151
	break;;
146
  esac
152
  esac
147
done
153
done
148
 
154
 
149
if test -z "$src"; then
155
if test -z "$1"; then
150
  echo "$0: no input file specified." >&2
-
 
151
  exit 1
-
 
152
fi
-
 
153
 
-
 
154
# Protect names starting with `-'.
-
 
155
case $src in
-
 
156
  -*) src=./$src ;;
-
 
157
esac
-
 
158
 
-
 
159
if test -n "$dir_arg"; then
156
  if test -z "$dir_arg"; then
160
  dst=$src
-
 
161
  src=
-
 
162
 
-
 
163
  if test -d "$dst"; then
-
 
164
    instcmd=:
-
 
165
    chmodcmd=
-
 
166
  else
-
 
167
    instcmd=$mkdirprog
-
 
168
  fi
-
 
169
else
-
 
170
  # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-
 
171
  # might cause directories to be created, which would be especially bad
-
 
172
  # if $src (and thus $dsttmp) contains '*'.
-
 
173
  if test ! -f "$src" && test ! -d "$src"; then
-
 
174
    echo "$0: $src does not exist." >&2
-
 
175
    exit 1
-
 
176
  fi
-
 
177
 
-
 
178
  if test -z "$dst"; then
-
 
179
    echo "$0: no destination specified." >&2
157
    echo "$0: no input file specified." >&2
180
    exit 1
158
    exit 1
181
  fi
159
  fi
-
 
160
  # It's OK to call `install-sh -d' without argument.
-
 
161
  # This can happen when creating conditional directories.
-
 
162
  exit 0
-
 
163
fi
182
 
164
 
-
 
165
for src
-
 
166
do
183
  # Protect names starting with `-'.
167
  # Protect names starting with `-'.
184
  case $dst in
168
  case $src in
185
    -*) dst=./$dst ;;
169
    -*) src=./$src ;;
186
  esac
170
  esac
187
 
171
 
188
  # If destination is a directory, append the input filename; won't work
172
  if test -n "$dir_arg"; then
189
  # if double slashes aren't ignored.
173
    dst=$src
-
 
174
    src=
-
 
175
 
190
  if test -d "$dst"; then
176
    if test -d "$dst"; then
-
 
177
      instcmd=:
-
 
178
      chmodcmd=
-
 
179
    else
191
    dst=$dst/`basename "$src"`
180
      instcmd=$mkdirprog
192
  fi
181
    fi
-
 
182
  else
-
 
183
    # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-
 
184
    # might cause directories to be created, which would be especially bad
-
 
185
    # if $src (and thus $dsttmp) contains '*'.
-
 
186
    if test ! -f "$src" && test ! -d "$src"; then
-
 
187
      echo "$0: $src does not exist." >&2
-
 
188
      exit 1
193
fi
189
    fi
194
 
190
 
195
# This sed command emulates the dirname command.
191
    if test -z "$dstarg"; then
196
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
192
      echo "$0: no destination specified." >&2
-
 
193
      exit 1
-
 
194
    fi
197
 
195
 
-
 
196
    dst=$dstarg
198
# Make sure that the destination directory exists.
197
    # Protect names starting with `-'.
-
 
198
    case $dst in
-
 
199
      -*) dst=./$dst ;;
-
 
200
    esac
-
 
201
 
-
 
202
    # If destination is a directory, append the input filename; won't work
-
 
203
    # if double slashes aren't ignored.
-
 
204
    if test -d "$dst"; then
-
 
205
      dst=$dst/`basename "$src"`
-
 
206
    fi
-
 
207
  fi
199
 
208
 
200
# Skip lots of stat calls in the usual case.
-
 
201
if test ! -d "$dstdir"; then
-
 
202
  defaultIFS='
-
 
203
	'
-
 
204
  IFS="${IFS-$defaultIFS}"
-
 
205
 
-
 
206
  oIFS=$IFS
-
 
207
  # Some sh's can't handle IFS=/ for some reason.
209
  # This sed command emulates the dirname command.
208
  IFS='%'
-
 
209
  set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
210
  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
210
  IFS=$oIFS
-
 
211
 
-
 
212
  pathcomp=
-
 
213
 
-
 
214
  while test $# -ne 0 ; do
-
 
215
    pathcomp=$pathcomp$1
-
 
216
    shift
-
 
217
    test -d "$pathcomp" || $mkdirprog "$pathcomp"
-
 
218
    pathcomp=$pathcomp/
-
 
219
  done
-
 
220
fi
-
 
221
 
211
 
-
 
212
  # Make sure that the destination directory exists.
-
 
213
 
-
 
214
  # Skip lots of stat calls in the usual case.
222
if test -n "$dir_arg"; then
215
  if test ! -d "$dstdir"; then
223
  $doit $instcmd "$dst" \
216
    defaultIFS='
-
 
217
	 '
224
    && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
218
    IFS="${IFS-$defaultIFS}"
-
 
219
 
-
 
220
    oIFS=$IFS
225
    && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
221
    # Some sh's can't handle IFS=/ for some reason.
-
 
222
    IFS='%'
226
    && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
223
    set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
227
    && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
224
    IFS=$oIFS
228
 
225
 
-
 
226
    pathcomp=
229
else
227
 
230
  # If we're going to rename the final executable, determine the name now.
-
 
231
  if test -z "$transformarg"; then
228
    while test $# -ne 0 ; do
232
    dstfile=`basename "$dst"`
229
      pathcomp=$pathcomp$1
233
  else
230
      shift
234
    dstfile=`basename "$dst" $transformbasename \
231
      test -d "$pathcomp" || $mkdirprog "$pathcomp"
235
             | sed $transformarg`$transformbasename
232
      pathcomp=$pathcomp/
-
 
233
    done
236
  fi
234
  fi
237
 
235
 
-
 
236
  if test -n "$dir_arg"; then
-
 
237
    $doit $instcmd "$dst" \
238
  # don't allow the sed command to completely eliminate the filename.
238
      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
-
 
239
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
239
  test -z "$dstfile" && dstfile=`basename "$dst"`
240
      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
-
 
241
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
240
 
242
 
241
  # Make a couple of temp file names in the proper directory.
-
 
242
  dsttmp=$dstdir/_inst.$$_
-
 
243
  rmtmp=$dstdir/_rm.$$_
-
 
244
 
-
 
245
  # Trap to clean up those temp files at exit.
-
 
246
  trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
-
 
247
  trap '(exit $?); exit' 1 2 13 15
-
 
248
 
-
 
249
  # Move or copy the file name to the temp name
-
 
250
  $doit $instcmd "$src" "$dsttmp" &&
-
 
251
 
-
 
252
  # and set any options; do chmod last to preserve setuid bits.
-
 
253
  #
243
  else
254
  # If any of these fail, we abort the whole thing.  If we want to
244
    # If we're going to rename the final executable, determine the name now.
255
  # ignore errors from any of these, just make sure not to ignore
-
 
256
  # errors from the above "$doit $instcmd $src $dsttmp" command.
-
 
257
  #
-
 
258
  { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
-
 
259
    && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
-
 
260
    && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
-
 
261
    && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
-
 
262
 
-
 
263
  # Now remove or move aside any old file at destination location.  We
-
 
264
  # try this two ways since rm can't unlink itself on some systems and
-
 
265
  # the destination file might be busy for other reasons.  In this case,
-
 
266
  # the final cleanup might fail but the new file should still install
-
 
267
  # successfully.
-
 
268
  {
-
 
269
    if test -f "$dstdir/$dstfile"; then
245
    if test -z "$transformarg"; then
270
      $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
-
 
271
      || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
-
 
272
      || {
-
 
273
	  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
246
      dstfile=`basename "$dst"`
274
	  (exit 1); exit
-
 
275
      }
-
 
276
    else
247
    else
277
      :
248
      dstfile=`basename "$dst" $transformbasename \
-
 
249
               | sed $transformarg`$transformbasename
278
    fi
250
    fi
279
  } &&
-
 
280
 
251
 
-
 
252
    # don't allow the sed command to completely eliminate the filename.
-
 
253
    test -z "$dstfile" && dstfile=`basename "$dst"`
-
 
254
 
-
 
255
    # Make a couple of temp file names in the proper directory.
-
 
256
    dsttmp=$dstdir/_inst.$$_
-
 
257
    rmtmp=$dstdir/_rm.$$_
-
 
258
 
-
 
259
    # Trap to clean up those temp files at exit.
-
 
260
    trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
-
 
261
    trap '(exit $?); exit' 1 2 13 15
-
 
262
 
-
 
263
    # Move or copy the file name to the temp name
-
 
264
    $doit $instcmd "$src" "$dsttmp" &&
-
 
265
 
-
 
266
    # and set any options; do chmod last to preserve setuid bits.
-
 
267
    #
-
 
268
    # If any of these fail, we abort the whole thing.  If we want to
-
 
269
    # ignore errors from any of these, just make sure not to ignore
-
 
270
    # errors from the above "$doit $instcmd $src $dsttmp" command.
-
 
271
    #
-
 
272
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
-
 
273
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
-
 
274
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
-
 
275
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
-
 
276
 
-
 
277
    # Now remove or move aside any old file at destination location.  We
-
 
278
    # try this two ways since rm can't unlink itself on some systems and
-
 
279
    # the destination file might be busy for other reasons.  In this case,
-
 
280
    # the final cleanup might fail but the new file should still install
-
 
281
    # successfully.
-
 
282
    {
-
 
283
      if test -f "$dstdir/$dstfile"; then
-
 
284
        $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
-
 
285
        || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
-
 
286
        || {
-
 
287
	  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
-
 
288
	  (exit 1); exit
-
 
289
        }
-
 
290
      else
-
 
291
        :
-
 
292
      fi
-
 
293
    } &&
-
 
294
 
281
  # Now rename the file to the real destination.
295
    # Now rename the file to the real destination.
282
  $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
296
    $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
-
 
297
  fi || { (exit 1); exit; }
283
fi &&
298
done
284
 
299
 
285
# The final little trick to "correctly" pass the exit status to the exit trap.
300
# The final little trick to "correctly" pass the exit status to the exit trap.
286
{
301
{
287
  (exit 0); exit
302
  (exit 0); exit
288
}
303
}