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