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