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