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