posaune
authorMichael Wagner <michael@wagnertech.de>
Fri, 23 Feb 2018 21:42:11 +0000 (22:42 +0100)
committerMichael Wagner <michael@wagnertech.de>
Fri, 23 Feb 2018 21:42:11 +0000 (22:42 +0100)
tools/make/treecopy [new file with mode: 0755]

diff --git a/tools/make/treecopy b/tools/make/treecopy
new file mode 100755 (executable)
index 0000000..761bd87
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# copy all files below <from> ($1), that match <filepattern> ($3)
+# into target <to> ($2)
+
+function fcp
+{
+       rel_path=${3#$1}
+       
+       # create target dir, if necessary
+       rel_dir=${rel_path%/*}
+       mkdir -p $2/$rel_dir
+       cp -a $1/$rel_path $2/$rel_dir
+}
+       
+usage="usage: treecopy <from> <to> <filepattern>|-e"
+
+if [ $# -ne 3 ]
+then
+       echo $usage
+       exit 1
+fi
+if [ $3 == "-e" ]
+then
+       for file in $(find $1 \( -type f -o -type l \) -executable)
+       do
+               fcp $1 $2 $file
+       done
+else   
+       for file in $(find $1 \( -type f -o -type l \) -name "$3")
+       do
+               fcp $1 $2 $file
+       done
+fi