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 | --preserve ] 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 39 Specifying --preserve preserves files and directories in locations used by this 40 distribution that are not (or are no longer) part of this distribution. 41 EOF 42 exit 1 43 fi 44 45 # Test for a directory argument and whether it exists. 46 47 if [ ! "$1" ] || [ ! -e "$1" ] ; then 48 cat 1>&2 <<EOF 49 Please indicate the l4 directory containing a pkg directory hierarchy. 50 EOF 51 exit 1 52 fi 53 54 # Test for an appropriate directory. 55 56 if [ ! -e "$1/pkg" ] ; then 57 cat 1>&2 <<EOF 58 The indicated directory does not appear to contain a pkg directory hierarchy. 59 EOF 60 exit 1 61 fi 62 63 L4DIR=$1 64 CLEAN= 65 PRESERVE= 66 67 # Determine the mode. 68 69 if [ "$2" = '--clean' ] ; then 70 CLEAN=$2 71 elif [ "$2" = '--preserve' ] ; then 72 PRESERVE=$2 73 fi 74 75 # Check the configuration, if possible. 76 77 "$THISDIR/checkconfig.sh" -q "$L4DIR" 78 79 # Generate binaries if appropriate. 80 81 if [ ! "$CLEAN" ] ; then 82 if ! "$THISDIR/makefonts.sh" -q ; then 83 cat 1>&2 <<EOF 84 85 Install halted due to font generation problem. 86 EOF 87 exit 1 88 fi 89 fi 90 91 # Copy (or remove) each of the objects. 92 93 for OBJTYPE in 'conf' 'pkg' ; do 94 TARGETDIR=$(readlink -f "$L4DIR")/$OBJTYPE 95 SOURCEDIR="$DIRNAME/$OBJTYPE" 96 97 # If cleaning, remove all objects. 98 99 if [ "$CLEAN" ] ; then 100 for OBJECT in "$SOURCEDIR/"* ; do 101 OBJNAME=$(basename "$OBJECT") 102 ORIGIN=$(readlink -f "$OBJECT") 103 TARGET="$TARGETDIR/$OBJNAME" 104 105 if [ -d "$TARGET" ] ; then 106 rm -r --one-file-system "$TARGET" 107 else 108 rm "$TARGET" 109 fi 110 done 111 112 continue 113 fi 114 115 # Make directories. 116 117 for OBJECT in $(find "$SOURCEDIR" -type d -print) ; do 118 ORIGIN=$(readlink -f "$OBJECT") 119 RELPATH=${ORIGIN#$SOURCEDIR/} 120 121 # Skip top-level directories. 122 123 if [ "$RELPATH" = "$ORIGIN" ]; then 124 continue 125 fi 126 127 TARGET="$TARGETDIR/$RELPATH" 128 129 if [ ! -e "$TARGET" ]; then 130 mkdir "$TARGET" 131 fi 132 done 133 134 # Copy new files. 135 136 for OBJECT in $(find "$SOURCEDIR" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print) ; do 137 ORIGIN=$(readlink -f "$OBJECT") 138 RELPATH=${ORIGIN#$SOURCEDIR/} 139 TARGET="$TARGETDIR/$RELPATH" 140 141 if [ ! -e "$TARGET" ] || [ "$ORIGIN" -nt "$TARGET" ] ; then 142 cp "$ORIGIN" "$TARGET" 143 fi 144 done 145 146 # Remove obsolete files. 147 148 if [ "$PRESERVE" ] ; then 149 continue 150 fi 151 152 for OBJECT in "$SOURCEDIR/"* ; do 153 OBJNAME=$(basename "$OBJECT") 154 ORIGIN=$(readlink -f "$OBJECT") 155 156 # Examine the target object directory for files that are not provided 157 # by the distribution. 158 159 TARGET="$TARGETDIR/$OBJNAME" 160 161 for FILENAME in $(find "$TARGET" -type f -not -name '.*' -not -name '*.orig' -not -name '*.rej' -print) ; do 162 PATHNAME=$(readlink -f "$FILENAME") 163 RELPATH=${PATHNAME#$TARGET} 164 SOURCE="$ORIGIN/$RELPATH" 165 166 if [ ! -e "$SOURCE" ] ; then 167 rm "$PATHNAME" 168 fi 169 done 170 171 # Remove obsolete directories. 172 173 for FILENAME in $(find "$TARGET" -depth -type d -print) ; do 174 PATHNAME=$(readlink -f "$FILENAME") 175 RELPATH=${PATHNAME#$TARGET} 176 SOURCE="$ORIGIN/$RELPATH" 177 178 if [ ! -e "$SOURCE" ] ; then 179 rmdir "$PATHNAME" 180 fi 181 done 182 done 183 done 184 185 # vim: tabstop=4 expandtab shiftwidth=4