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 if ! "$THISDIR/makefonts.sh" -q ; then 60 cat 1>&2 <<EOF 61 62 Install halted due to font generation problem. 63 EOF 64 exit 1 65 fi 66 fi 67 68 # Copy (or remove) each of the objects. 69 70 for OBJTYPE in 'conf' 'pkg' ; do 71 TARGETDIR=`realpath "$L4DIR"`/$OBJTYPE 72 SOURCEDIR="$DIRNAME/$OBJTYPE" 73 74 # If cleaning, remove all objects. 75 76 if [ "$CLEAN" ] ; then 77 for OBJECT in "$SOURCEDIR/"* ; do 78 OBJNAME=`basename "$OBJECT"` 79 ORIGIN=`realpath "$OBJECT"` 80 TARGET="$TARGETDIR/$OBJNAME" 81 82 if [ -d "$TARGET" ] ; then 83 rm -r --one-file-system "$TARGET" 84 else 85 rm "$TARGET" 86 fi 87 done 88 89 continue 90 fi 91 92 # Make directories. 93 94 for OBJECT in `find "$SOURCEDIR" -type d -print` ; do 95 ORIGIN=`realpath "$OBJECT"` 96 RELPATH=${ORIGIN#$SOURCEDIR/} 97 98 # Skip top-level directories. 99 100 if [ "$RELPATH" = "$ORIGIN" ]; then 101 continue 102 fi 103 104 TARGET="$TARGETDIR/$RELPATH" 105 106 if [ ! -e "$TARGET" ]; then 107 mkdir "$TARGET" 108 fi 109 done 110 111 # Copy new files. 112 113 for OBJECT in `find "$SOURCEDIR" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print` ; do 114 ORIGIN=`realpath "$OBJECT"` 115 RELPATH=${ORIGIN#$SOURCEDIR/} 116 TARGET="$TARGETDIR/$RELPATH" 117 118 if [ ! -e "$TARGET" ] || [ "$ORIGIN" -nt "$TARGET" ] ; then 119 cp "$ORIGIN" "$TARGET" 120 fi 121 done 122 123 # Remove obsolete files. 124 125 for OBJECT in "$SOURCEDIR/"* ; do 126 OBJNAME=`basename "$OBJECT"` 127 ORIGIN=`realpath "$OBJECT"` 128 129 # Examine the target object directory for files that are not provided 130 # by the distribution. 131 132 TARGET="$TARGETDIR/$OBJNAME" 133 134 for FILENAME in `find "$TARGET" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print` ; do 135 PATHNAME=`realpath "$FILENAME"` 136 RELPATH=${PATHNAME#$TARGET} 137 SOURCE="$ORIGIN/$RELPATH" 138 139 if [ ! -e "$SOURCE" ] ; then 140 rm "$PATHNAME" 141 fi 142 done 143 144 # Remove obsolete directories. 145 146 for FILENAME in `find "$TARGET" -depth -type d -print` ; do 147 PATHNAME=`realpath "$FILENAME"` 148 RELPATH=${PATHNAME#$TARGET} 149 SOURCE="$ORIGIN/$RELPATH" 150 151 if [ ! -e "$SOURCE" ] ; then 152 rmdir "$PATHNAME" 153 fi 154 done 155 done 156 done