Lichen

Annotated docs/tools/make_pages.sh

848:6c46f552abec
2018-07-11 Paul Boddie Made use of all the native comparison functions.
paul@810 1
#!/bin/sh
paul@810 2
paul@810 3
DIRNAME=`dirname $0`
paul@810 4
PROGNAME=`basename $0`
paul@810 5
OUTDIR=$1
paul@810 6
paul@810 7
if [ ! "$OUTDIR" ] || [ "$1" = '--help' ] ; then
paul@810 8
    cat 1>&2 <<EOF
paul@810 9
Usage: $PROGNAME <output directory> [ <page prefix> ] [ --releases [ --sign ] ]
paul@810 10
EOF
paul@810 11
    exit 1
paul@810 12
fi
paul@810 13
paul@810 14
if [ -e "$OUTDIR" ]; then
paul@810 15
    echo "Please remove $OUTDIR before generating a new package." 1>&2
paul@810 16
    exit 1
paul@810 17
fi
paul@810 18
paul@810 19
if [ "$2" = '--releases' ]; then
paul@810 20
    PREFIX=
paul@810 21
    RELEASES=$2
paul@810 22
    SIGN=$3
paul@810 23
else
paul@810 24
    PREFIX=$2
paul@810 25
    RELEASES=$3
paul@810 26
    SIGN=$4
paul@810 27
fi
paul@810 28
paul@810 29
# Generate release archives. These are held in a separate, semi-permanent
paul@810 30
# place so that archives and signatures are not regenerated unnecessarily.
paul@810 31
paul@810 32
if [ "$RELEASES" ]; then
paul@810 33
    "$DIRNAME/make_releases.sh" releases
paul@810 34
fi
paul@810 35
paul@810 36
if [ "$SIGN" ]; then
paul@810 37
    "$DIRNAME/sign_releases.sh" releases
paul@810 38
fi
paul@810 39
paul@810 40
# Generate a manifest for the page package.
paul@810 41
paul@810 42
MANIFEST="$OUTDIR/MOIN_PACKAGE"
paul@810 43
paul@810 44
mkdir "$OUTDIR"
paul@810 45
cat > "$MANIFEST" <<EOF
paul@810 46
MoinMoinPackage|1
paul@810 47
EOF
paul@810 48
paul@810 49
# Add the pages to the manifest.
paul@810 50
paul@810 51
DOCS="$DIRNAME/../wiki"
paul@810 52
paul@810 53
cp "$DOCS/"* "$OUTDIR"
paul@810 54
paul@810 55
for FILENAME in "$DOCS/"* ; do
paul@810 56
    BASENAME=`basename "$FILENAME"`
paul@810 57
    PAGENAME=`echo "$BASENAME" | sed 's/--/\//g'`
paul@810 58
    if [ "$PREFIX" ]; then
paul@810 59
        if [ "$PAGENAME" = "FrontPage" ]; then
paul@810 60
            PAGENAME="$PREFIX"
paul@810 61
        else
paul@810 62
            PAGENAME="$PREFIX/$PAGENAME"
paul@810 63
        fi
paul@810 64
    fi
paul@810 65
    echo "AddRevision|$BASENAME|$PAGENAME" >> "$MANIFEST"
paul@810 66
done
paul@810 67
paul@810 68
if [ ! -e "releases" ]; then
paul@810 69
    echo "No releases to add to the page package!" 1>&2
paul@810 70
else
paul@810 71
    # Combine the releases with the pages.
paul@810 72
paul@810 73
    ATTACHMENT="attachment_"
paul@810 74
paul@810 75
    for FILENAME in releases/* ; do
paul@810 76
        BASENAME=`basename "$FILENAME"`
paul@810 77
        cp "$FILENAME" "$OUTDIR/$ATTACHMENT$BASENAME"
paul@810 78
    done
paul@810 79
paul@810 80
    # Add the releases to the manifest.
paul@810 81
paul@810 82
    for FILENAME in releases/* ; do
paul@810 83
        BASENAME=`basename "$FILENAME"`
paul@810 84
        PAGENAME="Downloads"
paul@810 85
        if [ "$PREFIX" ]; then
paul@810 86
            PAGENAME="$PREFIX/$PAGENAME"
paul@810 87
        fi
paul@810 88
        echo "AddAttachment|$ATTACHMENT$BASENAME|$BASENAME|$PAGENAME" >> "$MANIFEST"
paul@810 89
    done
paul@810 90
fi
paul@810 91
paul@810 92
zip -j "$OUTDIR" "$OUTDIR/"*