1 |
asvitkine |
1.1 |
#!/bin/sh |
2 |
|
|
# A script to copy recursively ignoring detritus. |
3 |
|
|
# I based this off of a script I had that copied over ssh. |
4 |
|
|
# source can be a file or directory. |
5 |
|
|
# Mike Sliczniak 2009 |
6 |
|
|
|
7 |
|
|
# Don't copy resource forks or extended attributes on Mac OS X 10.4. |
8 |
|
|
COPY_EXTENDED_ATTRIBUTES_DISABLE=true; export COPY_EXTENDED_ATTRIBUTES_DISABLE |
9 |
|
|
|
10 |
|
|
# Don't copy resource forks or extended attributes on Mac OS X 10.5. |
11 |
|
|
COPYFILE_DISABLE=true; export COPYFILE_DISABLE |
12 |
|
|
|
13 |
|
|
case $# in |
14 |
|
|
2) |
15 |
|
|
;; |
16 |
|
|
*) |
17 |
|
|
echo "Usage: cpr source destdir" >&2 |
18 |
|
|
exit 2 |
19 |
|
|
;; |
20 |
|
|
esac |
21 |
|
|
|
22 |
|
|
# dir and base names of the source |
23 |
|
|
d=`dirname "$1"` || exit |
24 |
|
|
b=`basename "$1"` || exit |
25 |
|
|
|
26 |
|
|
# handle relative and absolute destination dirs |
27 |
|
|
case "$2" in |
28 |
|
|
/*) |
29 |
|
|
p=$2 |
30 |
|
|
;; |
31 |
|
|
*) |
32 |
|
|
p="$PWD"/"$2" |
33 |
|
|
;; |
34 |
|
|
esac |
35 |
|
|
|
36 |
|
|
# cd into the source dir |
37 |
|
|
cd "$d" || exit |
38 |
|
|
|
39 |
|
|
# This is only for Mac OS X, but some systems do not have gtar, find |
40 |
|
|
# sometimes lacks -f, and other systems use test -a. |
41 |
|
|
|
42 |
|
|
# List all interesting files for tar to copy: |
43 |
|
|
# The first clause skips directories used for revision control. |
44 |
|
|
# The second clause ignores detritus files from revision control and OSs. |
45 |
|
|
# The third clause ignores ._ style files created by Mac OS X on file systems |
46 |
|
|
# that do not have native resource forks or extended attributes. It checks to |
47 |
|
|
# see that the file it is associated with exists. |
48 |
|
|
find -f "$b" \( \! \( -type d \( \ |
49 |
|
|
-name CVS -o -name RCS -o -name SCCS -o -name .git -o -name .svn \ |
50 |
|
|
\) -prune \) \) \ |
51 |
|
|
\ |
52 |
|
|
\( \! \( -type f \( \ |
53 |
|
|
-name .DS_Store -o -name Thumbs.db -o -name .cvsignore -o -name .gitignore \ |
54 |
|
|
\) \) \) \ |
55 |
|
|
\ |
56 |
|
|
\( \! \( \ |
57 |
|
|
-type f -name '._*' -execdir /bin/sh -c \ |
58 |
|
|
'f=`echo "$1" | sed "s:^\._:./:"`; [ -e "$f" ]' /bin/sh '{}' \; \ |
59 |
|
|
\) \) -print0 | tar -c -f - --null -T - --no-recursion | tar -x -C "$p" -f - |