3 # Copyright (c) 2015 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 $0 FROM-DIR TO-DIR ENVIRONMENT
21 Copies files from one directory to another with possible
24 Files named FILE.spp will be transformed via the spp preprocessor
25 subject to environment definitions. Source FILE.copyimgspp results in
26 destination file FILE in the corresponding destination directory.
28 Files named FILE.copyimgsh are run as shell scripts in (i.e. via chdir)
29 the corresponding destination directory (and not copied).
31 First regular files are copied. Then transformations are preformed.
32 Finally, shell scripts are run.
40 FILTER=" -and -not -name '*~'";
41 FILTER="${FILTER} -and -not -name '.*~'";
42 FILTER="$FILTER -and -not -path '*/.git*'";
43 FILTER="$FILTER -and -not -path '*/.svn*'";
44 FILTER="$FILTER -and -not -path '*/.CVS*'";
46 FROM_FILES=`(cd $FROM_DIR; eval "find . -not -type d $FILTER")`;
47 FROM_DIRS=`(cd $FROM_DIR; eval "find . -type d $FILTER")`;
52 for f in $FROM_FILES; do
54 *.copyimgspp) SPP_FILES="$SPP_FILES $f" ;;
55 *.copyimgsh) SH_FILES="$SH_FILES $f" ;;
56 *) COPY_FILES="$COPY_FILES $f";;
60 # Make destination directories.
62 if [ "$FROM_DIRS" != "" ]; then
63 for d in $FROM_DIRS; do
69 if [ "$COPY_FILES" != "" ]; then
70 tar -cf - -C $FROM_DIR $COPY_FILES | tar --preserve-permissions -xf - -C $TO_DIR;
73 # Use spp to transform any spp files
74 if [ "$SPP_FILES" != "" ]; then
75 for f in $SPP_FILES; do
77 b=`basename $f .copyimgspp`;
80 spp -o $TO_DIR/$d/$b $FROM_DIR/$f || exit 1;
84 # Now that all files have been copied/created we run any shell scripts
85 ABS_FROM_DIR=`(cd $FROM_DIR; pwd)`;
86 if [ "$SH_FILES" != "" ]; then
87 # Allow directory to define some functions
88 if [ -f $FROM_DIR/copyimgsh-functions.sh ]; then
89 . $FROM_DIR/copyimgsh-functions.sh ;
91 for f in $SH_FILES; do
95 (cd $TO_DIR/$d; . $ABS_FROM_DIR/$d/$b) || exit 1;