123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- #!/bin/sh
- scriptversion=2004-07-05.00
- doit="${DOITPROG-}"
- mvprog="${MVPROG-mv}"
- cpprog="${CPPROG-cp}"
- chmodprog="${CHMODPROG-chmod}"
- chownprog="${CHOWNPROG-chown}"
- chgrpprog="${CHGRPPROG-chgrp}"
- stripprog="${STRIPPROG-strip}"
- rmprog="${RMPROG-rm}"
- mkdirprog="${MKDIRPROG-mkdir}"
- chmodcmd="$chmodprog 0755"
- chowncmd=
- chgrpcmd=
- stripcmd=
- rmcmd="$rmprog -f"
- mvcmd="$mvprog"
- src=
- dst=
- dir_arg=
- dstarg=
- no_target_directory=
- usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
- or: $0 [OPTION]... SRCFILES... DIRECTORY
- or: $0 [OPTION]... -t DIRECTORY SRCFILES...
- or: $0 [OPTION]... -d DIRECTORIES...
- In the 1st form, copy SRCFILE to DSTFILE.
- In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
- In the 4th, create DIRECTORIES.
- Options:
- -c (ignored)
- -d create directories instead of installing files.
- -g GROUP $chgrpprog installed files to GROUP.
- -m MODE $chmodprog installed files to MODE.
- -o USER $chownprog installed files to USER.
- -s $stripprog installed files.
- -t DIRECTORY install into DIRECTORY.
- -T report an error if DSTFILE is a directory.
- --help display this help and exit.
- --version display version info and exit.
- Environment variables override the default commands:
- CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
- "
- while test -n "$1"; do
- case $1 in
- -c) shift
- continue;;
- -d) dir_arg=true
- shift
- continue;;
- -g) chgrpcmd="$chgrpprog $2"
- shift
- shift
- continue;;
- --help) echo "$usage"; exit 0;;
- -m) chmodcmd="$chmodprog $2"
- shift
- shift
- continue;;
- -o) chowncmd="$chownprog $2"
- shift
- shift
- continue;;
- -s) stripcmd=$stripprog
- shift
- continue;;
- -t) dstarg=$2
- shift
- shift
- continue;;
- -T) no_target_directory=true
- shift
- continue;;
- --version) echo "$0 $scriptversion"; exit 0;;
- *)
-
- test -n "$dir_arg$dstarg" && break
-
- for arg
- do
- if test -n "$dstarg"; then
-
- set fnord "$@" "$dstarg"
- shift
- fi
- shift
- dstarg=$arg
- done
- break;;
- esac
- done
- if test -z "$1"; then
- if test -z "$dir_arg"; then
- echo "$0: no input file specified." >&2
- exit 1
- fi
-
-
- exit 0
- fi
- for src
- do
-
- case $src in
- -*) src=./$src ;;
- esac
- if test -n "$dir_arg"; then
- dst=$src
- src=
- if test -d "$dst"; then
- mkdircmd=:
- chmodcmd=
- else
- mkdircmd=$mkdirprog
- fi
- else
-
-
-
- if test ! -f "$src" && test ! -d "$src"; then
- echo "$0: $src does not exist." >&2
- exit 1
- fi
- if test -z "$dstarg"; then
- echo "$0: no destination specified." >&2
- exit 1
- fi
- dst=$dstarg
-
- case $dst in
- -*) dst=./$dst ;;
- esac
-
-
- if test -d "$dst"; then
- if test -n "$no_target_directory"; then
- echo "$0: $dstarg: Is a directory" >&2
- exit 1
- fi
- dst=$dst/`basename "$src"`
- fi
- fi
-
- dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-
- if test ! -d "$dstdir"; then
- defaultIFS='
- '
- IFS="${IFS-$defaultIFS}"
- oIFS=$IFS
-
- IFS='%'
- set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
- IFS=$oIFS
- pathcomp=
- while test $# -ne 0 ; do
- pathcomp=$pathcomp$1
- shift
- if test ! -d "$pathcomp"; then
- $mkdirprog "$pathcomp"
-
-
-
- test -d "$pathcomp" || exit
- fi
- pathcomp=$pathcomp/
- done
- fi
- if test -n "$dir_arg"; then
- $doit $mkdircmd "$dst" \
- && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
- && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
- && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
- && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
- else
- dstfile=`basename "$dst"`
-
- dsttmp=$dstdir/_inst.$$_
- rmtmp=$dstdir/_rm.$$_
-
- trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
- trap '(exit $?); exit' 1 2 13 15
-
- $doit $cpprog "$src" "$dsttmp" &&
-
-
-
-
-
-
- { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
- && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
- && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
- && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
-
- { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
- || {
-
-
-
-
-
-
-
-
- {
- if test -f "$dstdir/$dstfile"; then
- $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
- || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
- || {
- echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
- (exit 1); exit
- }
- else
- :
- fi
- } &&
-
- $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
- }
- }
- fi || { (exit 1); exit; }
- done
- {
- (exit 0); exit
- }
|