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