D12-Anpassung
[projects.git] / tools / make / treecopy
1 #!/bin/bash
2
3 # copy all files below <from> ($1), that match <filepattern> ($3)
4 # into target <to> ($2)
5
6 function fcp
7 {
8         rel_path=${3#$1}
9         
10         # create target dir, if necessary
11         rel_dir=${rel_path%/*}
12         mkdir -p $2/$rel_dir
13         cp -a $1/$rel_path $2/$rel_dir
14 }
15         
16 usage="usage: treecopy <from> <to> <filepattern>|-e"
17
18 if [ $# -ne 3 ]
19 then
20         echo $usage
21         exit 1
22 fi
23 if [ $3 == "-e" ]
24 then
25         for file in $(find $1 \( -type f -o -type l \) -executable)
26         do
27                 fcp $1 $2 $file
28         done
29 else    
30         for file in $(find $1 \( -type f -o -type l \) -name "$3")
31         do
32                 fcp $1 $2 $file
33         done
34 fi