1 #!/bin/sh 2 3 THISDIR=`dirname "$0"` 4 DIRNAME=`realpath "$THISDIR/.."` 5 PROGNAME=`basename "$0"` 6 7 if [ "$1" = '--help' ]; then 8 cat 1>&2 <<EOF 9 Usage: $PROGNAME <l4-directory> [ --clean ] 10 11 Copy the distributed packages into the "pkg" hierarchy found within the 12 specified directory. Also copy the distributed configuration examples into the 13 "conf" hierarchy. 14 15 The indicated directory need not be called "l4", but it must at least have a 16 "conf" directory and a "pkg" directory inside it. 17 18 Specifying --clean removes copied objects. 19 EOF 20 exit 1 21 fi 22 23 # Test for a directory argument and whether it exists. 24 25 if [ ! "$1" ] || [ ! -e "$1" ] ; then 26 cat 1>&2 <<EOF 27 Please indicate the l4 directory containing a pkg directory hierarchy. 28 EOF 29 exit 1 30 fi 31 32 # Test for an appropriate directory. 33 34 if [ ! -e "$1/pkg" ] ; then 35 cat 1>&2 <<EOF 36 The indicated directory does not appear to contain a pkg directory hierarchy. 37 EOF 38 exit 1 39 fi 40 41 L4DIR=$1 42 43 # Copy (or remove) each of the objects. 44 45 if [ "$2" = '--clean' ] ; then 46 CLEAN=$2 47 else 48 CLEAN= 49 fi 50 51 for OBJTYPE in 'conf' 'pkg' ; do 52 TARGETDIR=`realpath "$L4DIR"`/$OBJTYPE 53 SOURCEDIR="$DIRNAME/$OBJTYPE" 54 55 # If cleaning, remove all objects. 56 57 if [ "$CLEAN" ] ; then 58 for OBJECT in "$SOURCEDIR/"* ; do 59 OBJNAME=`basename "$OBJECT"` 60 ORIGIN=`realpath "$OBJECT"` 61 TARGET="$TARGETDIR/$OBJNAME" 62 63 if [ -d "$TARGET" ] ; then 64 rm -r --one-file-system "$TARGET" 65 else 66 rm "$TARGET" 67 fi 68 done 69 70 continue 71 fi 72 73 # Make directories. 74 75 for OBJECT in `find "$SOURCEDIR" -type d -print` ; do 76 ORIGIN=`realpath "$OBJECT"` 77 RELPATH=${ORIGIN#$SOURCEDIR/} 78 79 # Skip top-level directories. 80 81 if [ "$RELPATH" = "$ORIGIN" ]; then 82 continue 83 fi 84 85 TARGET="$TARGETDIR/$RELPATH" 86 87 if [ ! -e "$TARGET" ]; then 88 mkdir "$TARGET" 89 fi 90 done 91 92 # Copy new files. 93 94 for OBJECT in `find "$SOURCEDIR" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print` ; do 95 ORIGIN=`realpath "$OBJECT"` 96 RELPATH=${ORIGIN#$SOURCEDIR/} 97 TARGET="$TARGETDIR/$RELPATH" 98 99 if [ ! -e "$TARGET" ] || [ "$ORIGIN" -nt "$TARGET" ] ; then 100 cp "$ORIGIN" "$TARGET" 101 fi 102 done 103 104 # Remove obsolete files. 105 106 for OBJECT in "$SOURCEDIR/"* ; do 107 OBJNAME=`basename "$OBJECT"` 108 ORIGIN=`realpath "$OBJECT"` 109 110 # Examine the target object directory for files that are not provided 111 # by the distribution. 112 113 TARGET="$TARGETDIR/$OBJNAME" 114 115 for FILENAME in `find "$TARGET" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print` ; do 116 PATHNAME=`realpath "$FILENAME"` 117 RELPATH=${PATHNAME#$TARGET} 118 SOURCE="$ORIGIN/$RELPATH" 119 120 if [ ! -e "$SOURCE" ] ; then 121 rm "$PATHNAME" 122 fi 123 done 124 125 # Remove obsolete directories. 126 127 for FILENAME in `find "$TARGET" -depth -type d -print` ; do 128 PATHNAME=`realpath "$FILENAME"` 129 RELPATH=${PATHNAME#$TARGET} 130 SOURCE="$ORIGIN/$RELPATH" 131 132 if [ ! -e "$SOURCE" ] ; then 133 rmdir "$PATHNAME" 134 fi 135 done 136 done 137 done