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@0 | 52 | OBJDIR=`realpath "$L4DIR"`/$OBJTYPE |
paul@0 | 53 | |
paul@0 | 54 | for OBJECT in "$DIRNAME/$OBJTYPE/"* ; do |
paul@0 | 55 | OBJNAME=`basename "$OBJECT"` |
paul@0 | 56 | ORIGIN=`realpath "$OBJECT"` |
paul@0 | 57 | TARGET="$OBJDIR/$OBJNAME" |
paul@0 | 58 | |
paul@0 | 59 | if [ "$CLEAN" ] ; then |
paul@0 | 60 | if [ -d "$TARGET" ]; then |
paul@0 | 61 | rm -r --one-file-system "$TARGET" |
paul@0 | 62 | else |
paul@0 | 63 | rm "$TARGET" |
paul@0 | 64 | fi |
paul@0 | 65 | else |
paul@0 | 66 | if [ -d "$ORIGIN" ]; then |
paul@0 | 67 | cp -R "$ORIGIN" "$TARGET" |
paul@0 | 68 | else |
paul@0 | 69 | cp "$ORIGIN" "$TARGET" |
paul@0 | 70 | fi |
paul@0 | 71 | fi |
paul@0 | 72 | done |
paul@0 | 73 | done |