blob: e5e3fc265ee972de14e6124e6cf9183aac129f7f [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001#!/bin/sh
2
3if [ $# -lt 2 ]; then
4 cat - <<EOF
5$0 FROM-DIR TO-DIR ENVIRONMENT
6
7Copies files from one directory to another with possible
8transformations.
9
10Files named FILE.spp will be transformed via the spp preprocessor
11subject to environment definitions. Source FILE.copyimgspp results in
12destination file FILE in the corresponding destination directory.
13
14Files named FILE.copyimgsh are run as shell scripts in (i.e. via chdir)
15the corresponding destination directory (and not copied).
16
17First regular files are copied. Then transformations are preformed.
18Finally, shell scripts are run.
19EOF
20 exit 1;
21fi
22
23FROM_DIR=$1
24TO_DIR=$2
25
26FILTER=" -and -not -name '*~'";
27FILTER="${FILTER} -and -not -name '.*~'";
28FILTER="$FILTER -and -not -path '*/.git*'";
29FILTER="$FILTER -and -not -path '*/.svn*'";
30FILTER="$FILTER -and -not -path '*/.CVS*'";
31
32FROM_FILES=`(cd $FROM_DIR; eval "find . -not -type d $FILTER")`;
33 FROM_DIRS=`(cd $FROM_DIR; eval "find . -type d $FILTER")`;
34
35COPY_FILES=
36SPP_FILES=
37SH_FILES=
38for f in $FROM_FILES; do
39 case $f in
40 *.copyimgspp) SPP_FILES="$SPP_FILES $f" ;;
41 *.copyimgsh) SH_FILES="$SH_FILES $f" ;;
42 *) COPY_FILES="$COPY_FILES $f";;
43 esac
44done
45
46# Make destination directories.
47mkdir -p $TO_DIR;
48if [ "$FROM_DIRS" != "" ]; then
49 for d in $FROM_DIRS; do
50 mkdir -p $TO_DIR/$d;
51 done
52fi
53
54# Copy files
55if [ "$COPY_FILES" != "" ]; then
56 tar -cf - -C $FROM_DIR $COPY_FILES | tar --preserve-permissions -xf - -C $TO_DIR;
57fi
58
59# Use spp to transform any spp files
60if [ "$SPP_FILES" != "" ]; then
61 for f in $SPP_FILES; do
62 d=`dirname $f`;
63 b=`basename $f .copyimgspp`;
64 mkdir -p $TO_DIR/$d;
65 t=$TO_DIR/$d/$b;
66 spp -o $TO_DIR/$d/$b $FROM_DIR/$f || exit 1;
67 done;
68fi
69
70# Now that all files have been copied/created we run any shell scripts
71ABS_FROM_DIR=`(cd $FROM_DIR; pwd)`;
72if [ "$SH_FILES" != "" ]; then
73 # Allow directory to define some functions
74 if [ -f $FROM_DIR/copyimgsh-functions.sh ]; then
75 . $FROM_DIR/copyimgsh-functions.sh ;
76 fi ;
77 for f in $SH_FILES; do
78 d=`dirname $f`;
79 b=`basename $f`;
80 mkdir -p $TO_DIR/$d;
81 (cd $TO_DIR/$d; . $ABS_FROM_DIR/$d/$b) || exit 1;
82 done;
83fi;