summaryrefslogtreecommitdiff
path: root/admin/upload-manuals
blob: 6f44456efb86b84d0a6568fb1ccc9bc8a1baf97a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/bash

### upload-manuals - upload the Emacs manuals to the gnu.org website

## Copyright 2018-2023 Free Software Foundation, Inc.

## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: emacs-devel@gnu.org

## This file is part of GNU Emacs.

## GNU Emacs is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.

## GNU Emacs is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

### Commentary:

## Run this on the output of make-manuals.

## We assume you have already checked out a local copy of the website
## following the instructions at
## https://savannah.gnu.org/cvs/?group=emacs

## Usage:
## Call from the manual/ directory created by make-manual.
## upload-manuals /path/to/cvs/checkout

### Code:

source "${0%/*}/emacs-shell-lib"

usage ()
{
    cat 1>&2 <<EOF
Usage: ${PN} [-m message] [-n] /path/to/cvs/checkout
Upload the Emacs manuals to the gnu.org website.
Call this script from the manual/ directory created by make-manuals.
This script destructively modifies the source directory.
Options:
-m: commit message to use (default "$message")
-n: dry-run (do not commit files)
EOF
    exit 1
}


## Parameters
version=$(gunzip -c info/emacs.info.gz 2> /dev/null | sed -n '0,/updated for Emacs version/s/.*updated for Emacs version \([0-9.]*\).*\.$/\1/p')

## Defaults
cvs=cvs
message="Regenerate manuals for Emacs $version"
umessage=

while getopts ":hm:n" option ; do
    case $option in
        (h) usage ;;

        (m) umessage=t ; message="$OPTARG" ;;

        (n) cvs="echo $cvs" ;;

        (\?) die "Bad option -$OPTARG" ;;

        (:) die "Option -$OPTARG requires an argument" ;;

        (*) die "getopts error" ;;
    esac
done
shift $(( --OPTIND ))
OPTIND=1

[ $# -eq 1 ] || usage

[ -e html_mono/emacs.html ] && [ -e html_node/emacs/index.html ] || \
    die "Current directory does not look like the manual/ directory"

[ "$version$umessage" ] || \
    die "Could not get version to use for commit message"

webdir=$1

[ -e $webdir/CVS/Entries ] && [ -e $webdir/refcards/pdf/refcard.pdf ] || \
    die "$webdir does not look like a checkout of the Emacs webpages"


echo "Doing refcards..."

mv refcards/emacs-refcards.tar.gz $webdir/refcards/
(
    cd $webdir/refcards
    $cvs commit -m "$message" emacs-refcards.tar.gz || die "commit error"
)

## For refcards, we assume a missing file is due to a tex failure,
## rather than a refcard that should be deleted.
for fmt in pdf ps.gz; do

    clist=

    for f in $webdir/refcards/${fmt%.gz}/*.$fmt; do

        s=${f#$webdir/}

        if [ -e $s ]; then
            mv $s $f
            clist="$clist ${f##*/}"
        else
            echo "$s seems to be missing"
        fi
    done


    ## Check for new files.
    new=
    for f in refcards/${fmt%.gz}/*.$fmt; do
        [ -e $f ] || break
        new="$new $f"
        clist="$clist ${f##*/}"
    done

    [ "$new" ] && mv $new $webdir/refcards/${fmt%.gz}/

    [ "$clist" ] && (
        cd $webdir
        [ "$new" ] && {
            echo "Adding new files: $new"
            $cvs add -kb $new || die "add error"
            echo "Remember to add new refcards to refcards/index.html"
        }
        cd refcards/${fmt%.gz}
        $cvs commit -m "$message" $clist || die "commit error"
    )

done                            # $fmt


echo "Doing non-html manuals..."

for fmt in info pdf ps texi; do

    clist=

    for f in $webdir/manual/$fmt/*; do

        [ ${f##*/} = CVS ] && continue

        s=$fmt/${f##*/}

        if [ -e $s ]; then
            mv $s $f
            clist="$clist ${f##*/}"
        else
            case ${f##*/} in
                *_7x9*.pdf) continue ;;
            esac

            echo "$s seems to be missing"
        fi
    done

    ## Check for new files.
    new=
    for f in $fmt/*.$fmt*; do
        [ -e $f ] || break
        new="$new $f"
        clist="$clist ${f##*/}"
    done

    [ "$new" ] && mv $new $webdir/manual/$fmt/

    [ "$clist" ] && (
        cd $webdir/manual
        [ "$new" ] && {
            echo "Adding new files: $new"
            $cvs add $new || die "add error"
            echo "Remember to add new files to the appropriate index pages"
        }
        cd $fmt
        $cvs commit -m "$message" $clist || die "commit error"
    )

done


echo "Doing tarred html..."

clist=

for f in $webdir/manual/*html*.tar*; do

    s=${f##*/}

    if [ -e $s ]; then
        mv $s $f
        clist="$clist ${f##*/}"
    else
        echo "$s seems to be missing"
    fi
done

## Check for new files.
new=
for f in *html*.tar*; do
    [ -e $f ] || break
    new="$new $f"
    clist="$clist ${f##*/}"
done

[ "$new" ] && mv $new $webdir/manual

[ "$clist" ] && (
    cd $webdir/manual
    [ "$new" ] && {
        echo "Adding new files: $new"
        $cvs add -kb $new || die "add error"
        echo "Remember to add new files to the appropriate index pages"
    }
    $cvs commit -m "$message" $clist || die "commit error"
)


## This happens so rarely it would be less effort to do by hand...
new_manual () {
    local t=eww
    local i=$webdir/manual/$t.html # template

    [ -r $i ] || die "Cannot read template $i"

    local name o mono title

    for name; do

        name=${name##*/}
        name=${name%.html}

        o=$webdir/manual/$name.html

        [ -e $o ] && die "$o already exists"

        mono=$webdir/manual/html_mono/$name.html

        [ -r $mono ] || die "Cannot read $mono"

        title=$(sed -n 's|^<title>\(.*\)</title>|\1|p' $mono)

        : ${title:?}

        echo "$title" | grep -qi "Emacs" || title="Emacs $title"
        echo "$title" | grep -qi "manual" || title="$title Manual"

        ## It is a pain to extract and insert a good "documenting...".
        ## Improve it by hand if you care.
        sed -e "s|^<title>.*\( - GNU Project\)|<title>$title\1|" \
            -e "s|^<h2>.*|<h2>$title</h2>|" \
            -e "s/^documenting.*/documenting \"$title\"./" \
            -e "s/$t/$name/" \
            -e "s/&copy;.* Free/\&copy; $(date +%Y) Free/" $i > $o

        (
            cd $webdir/manual
            $cvs add ${o##*/} || die "add error for $o"
        )
    done

    return 0
}


echo "Doing html_mono..."

clist=

for f in $webdir/manual/html_mono/*.html; do

    s=${f##*manual/}

    if [ -e $s ]; then
        mv $s $f
        clist="$clist ${f##*/}"
    else
        echo "$s seems to be missing"
    fi
done

## Check for new files.
new=
for f in html_mono/*.html; do
    [ -e $f ] || break
    new="$new $f"
    clist="$clist ${f##*/}"
done

[ "$new" ] && mv $new $webdir/manual/html_mono/

## TODO: check for removed manuals.

[ "$clist" ] && (
    cd $webdir/manual/html_mono
    [ "$new" ] && {
        echo "Adding new files: $new"
        $cvs add $new || die "add error"
        new_manual $new || die
        echo "Remember to add new entries to manual/index.html"
    }
    $cvs commit -m "$message" $clist || die "commit error"
)


echo "Doing html_node..."

for d in html_node/*; do

    [ -e $d ] || break

    echo "Doing $d..."

    [ -e $webdir/manual/$d ] || {
        echo "New directory: $d"
        mkdir $webdir/manual/$d
        (
            cd $webdir/manual
            $cvs add $d || die "add error"
        )
    }

    new=
    for f in $d/*.html; do
        [ -e $webdir/manual/$f ] || new="$new ${f##*/}"
    done

    stale=
    for f in $webdir/manual/$d/*.html; do
        [ -e ${f#$webdir/manual/} ] || stale="$stale ${f##*/}"
    done

    mv $d/*.html $webdir/manual/$d/

    (
        cd $webdir/manual/$d
        [ "$new" ] && {
            echo "Adding new files: $new"
            $cvs add $new || die "add error"
        }

        [ "$stale" ] && {
            echo "Removing stale files: $stale"
            $cvs remove -f $stale || die "remove error"
        }

        ## -f: create a new revision even if no change.
        $cvs commit -f -m "$message" *.html $stale || die "commit error"
    )

done


echo "Checking for stray files..."
find -type f


echo "Finished"

exit 0