Debian Codegraph @

base/instcopy

raw
1 #!/bin/sh
2 # Copyright (C) 2001-2023 Artifex Software, Inc.
3 # All Rights Reserved.
4 #
5 # This software is provided AS-IS with no warranty, either express or
6 # implied.
7 #
8 # This software is distributed under license and may not be copied,
9 # modified or distributed except as expressly authorized under the terms
10 # of the license contained in the file LICENSE in this distribution.
11 #
12 # Refer to licensing information at http://www.artifex.com or contact
13 # Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
14 # CA 94129, USA, for further information.
15 #
16 #
17 # Implement a uniform 'install' syntax independent of which of the two
18 # "standard" install programs is installed. Based on ideas in, but not
19 # copied from, the GNU fileutils install-sh script. Usage:
20 # instcopy -c [-m <mode>] <srcfile> (<dstdir>|<dstfile>)
21
22 doit=""
23 # Uncomment the following line for testing
24 #doit="echo "
25
26 mode=""
27
28 while true; do
29 case "$1" in
30 -c) ;;
31 -m) mode=$2; shift ;;
32 *) break ;;
33 esac
34 shift; done
35
36 src=$1
37 dst=$2
38
39 if [ $# = 2 -a -f $src ]; then true; else
40 echo "Usage: instcopy -c [-m <mode>] <srcfile> (<dstdir>|<dstfile>)"
41 exit 1
42 fi
43
44 if [ -d $dst ]; then
45 dstdir=`echo $dst | sed -e 's,/$,,'`
46 dst="$dstdir"/`basename $src`
47 else
48 dstdir=`echo $dst | sed -e 's,/[^/]*$,,'`
49 fi
50 dsttmp=$dstdir/#inst.$$#
51
52 $doit trap "rm -f $dsttmp" 0 &&
53 $doit cp $src $dsttmp &&
54 if [ x"$mode" != x ]; then $doit chmod $mode $dsttmp; else true; fi &&
55 $doit rm -f $dst &&
56 $doit mv $dsttmp $dst &&
57 exit 0