chg: mention CVE for 3.97.1
[exim-website.git] / script / build
1 #!/bin/bash
2 # Usage: [TARGET=…] $0 [ref]
3 # - Build from either the ref (or refs/heads/master) or from the current working directory
4 # - Can be used as a post-update hook
5
6 set -eu
7 shopt -s extglob
8
9 tmp=$(mktemp -d)
10 trap "rm -rf '$tmp'" EXIT INT
11
12 staging="$tmp/staging"                          # the temporary build dir
13 pubdir=${TARGET:-/srv/www/vhosts/www.exim.org}  # publish here
14
15 if [[ $(git rev-parse --is-inside-work-tree) != true ]]
16 then
17   workdir=$tmp/workdir
18   install -d "$workdir"
19   git --work-tree="$workdir" checkout -f refs/heads/master      # FIXME: use the receiving branch
20   cd "$workdir"
21 fi
22
23 if ! test -d "$pubdir"
24 then
25         echo "Warning: $pubdir does not exist. Did you forget to set the TARGET env in \"local\" mode?" >&2
26         exit 1
27 fi
28
29
30 if getent group eximdev
31 then install -m 02775 -g eximdev -d "$staging"
32 else install -d "$staging"
33 fi
34
35 cp -r --preserve=timestamps "$pubdir"/exim-+(html|pdf)-* "$staging/" ||:
36
37 # start working
38 latest=$(cd docbook && compgen -G '[45].*' | sort -V | tail -n1)
39
40 script/gen \
41   --web \
42   --spec docbook/[45]*/spec.xml \
43   --filter  docbook/[45]*/filter.xml \
44   --tmpl templates \
45   --latest "$latest" \
46   --docroot "$staging"
47
48 mv "$staging" "$pubdir.$$"              # may take some time (tmp -> data volume)
49 mv "$pubdir" "$pubdir.$(date -Isecond)" # backup
50 mv "$pubdir.$$" "$pubdir"               # should be fast
51
52 echo "*** updated into $pubdir"