1 #!/bin/sh 2 3 # Install the software in the L4Re source hierarchy. 4 # 5 # Copyright (C) 2018, 2023 Paul Boddie <paul@boddie.org.uk> 6 # 7 # This program is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License as 9 # published by the Free Software Foundation; either version 2 of 10 # the License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 # Boston, MA 02110-1301, USA 21 22 THISDIR=$(dirname "$0") 23 DIRNAME=$(readlink -f "$THISDIR/..") 24 PROGNAME=$(basename "$0") 25 26 if [ "$1" = '--help' ]; then 27 cat 1>&2 <<EOF 28 Usage: $PROGNAME <l4-directory> [ --clean ] 29 30 Copy the distributed packages into the "pkg" hierarchy found within the 31 specified directory. Also copy the distributed configuration examples into the 32 "conf" hierarchy. 33 34 The indicated directory need not be called "l4", but it must at least have a 35 "conf" directory and a "pkg" directory inside it. 36 37 Specifying --clean removes copied objects. 38 EOF 39 exit 1 40 fi 41 42 # Test for a directory argument and whether it exists. 43 44 if [ ! "$1" ] || [ ! -e "$1" ] ; then 45 cat 1>&2 <<EOF 46 Please indicate the l4 directory containing a pkg directory hierarchy. 47 EOF 48 exit 1 49 fi 50 51 # Test for an appropriate directory. 52 53 if [ ! -e "$1/pkg" ] ; then 54 cat 1>&2 <<EOF 55 The indicated directory does not appear to contain a pkg directory hierarchy. 56 EOF 57 exit 1 58 fi 59 60 L4DIR=$1 61 62 # Determine the mode. 63 64 if [ "$2" = '--clean' ] ; then 65 CLEAN=$2 66 else 67 CLEAN= 68 fi 69 70 # Check the configuration, if possible. 71 72 "$THISDIR/checkconfig.sh" -q "$L4DIR" 73 74 # Generate binaries if appropriate. 75 76 if [ ! "$CLEAN" ] ; then 77 if ! "$THISDIR/makefonts.sh" -q ; then 78 cat 1>&2 <<EOF 79 80 Install halted due to font generation problem. 81 EOF 82 exit 1 83 fi 84 fi 85 86 # Copy (or remove) each of the objects. 87 88 for OBJTYPE in 'conf' 'pkg' ; do 89 TARGETDIR=$(readlink -f "$L4DIR")/$OBJTYPE 90 SOURCEDIR="$DIRNAME/$OBJTYPE" 91 92 # If cleaning, remove all objects. 93 94 if [ "$CLEAN" ] ; then 95 for OBJECT in "$SOURCEDIR/"* ; do 96 OBJNAME=$(basename "$OBJECT") 97 ORIGIN=$(readlink -f "$OBJECT") 98 TARGET="$TARGETDIR/$OBJNAME" 99 100 if [ -d "$TARGET" ] ; then 101 rm -r --one-file-system "$TARGET" 102 else 103 rm "$TARGET" 104 fi 105 done 106 107 continue 108 fi 109 110 # Make directories. 111 112 for OBJECT in $(find "$SOURCEDIR" -type d -print) ; do 113 ORIGIN=$(readlink -f "$OBJECT") 114 RELPATH=${ORIGIN#$SOURCEDIR/} 115 116 # Skip top-level directories. 117 118 if [ "$RELPATH" = "$ORIGIN" ]; then 119 continue 120 fi 121 122 TARGET="$TARGETDIR/$RELPATH" 123 124 if [ ! -e "$TARGET" ]; then 125 mkdir "$TARGET" 126 fi 127 done 128 129 # Copy new files. 130 131 for OBJECT in $(find "$SOURCEDIR" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print) ; do 132 ORIGIN=$(readlink -f "$OBJECT") 133 RELPATH=${ORIGIN#$SOURCEDIR/} 134 TARGET="$TARGETDIR/$RELPATH" 135 136 if [ ! -e "$TARGET" ] || [ "$ORIGIN" -nt "$TARGET" ] ; then 137 cp "$ORIGIN" "$TARGET" 138 fi 139 done 140 141 # Remove obsolete files. 142 143 for OBJECT in "$SOURCEDIR/"* ; do 144 OBJNAME=$(basename "$OBJECT") 145 ORIGIN=$(readlink -f "$OBJECT") 146 147 # Examine the target object directory for files that are not provided 148 # by the distribution. 149 150 TARGET="$TARGETDIR/$OBJNAME" 151 152 for FILENAME in $(find "$TARGET" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print) ; do 153 PATHNAME=$(readlink -f "$FILENAME") 154 RELPATH=${PATHNAME#$TARGET} 155 SOURCE="$ORIGIN/$RELPATH" 156 157 if [ ! -e "$SOURCE" ] ; then 158 rm "$PATHNAME" 159 fi 160 done 161 162 # Remove obsolete directories. 163 164 for FILENAME in $(find "$TARGET" -depth -type d -print) ; do 165 PATHNAME=$(readlink -f "$FILENAME") 166 RELPATH=${PATHNAME#$TARGET} 167 SOURCE="$ORIGIN/$RELPATH" 168 169 if [ ! -e "$SOURCE" ] ; then 170 rmdir "$PATHNAME" 171 fi 172 done 173 done 174 done 175 176 # vim: tabstop=4 expandtab shiftwidth=4