bug 771: Remember whether navigation was requested by user
[elinks/kon.git] / contrib / mkdist
blob3491403523288b255d9b3bf5efee044a347732d5
1 #!/bin/bash
3 # This script can be used by a cron to generate snapshots.
4 # For example, use:
5 # 35 0 * * * mkdist -r elinks-0.11 -l 0.11 -s >>mkdist.log 2>&1
6 # 40 0 * * * mkdist -r HEAD -l 0.12 -s >>mkdist.log 2>&1
8 # Options:
9 # -g GIT_DIR Git repository from which this script exports ELinks.
10 # May be given in the environment instead.
11 # -r REVISION Git revision to be exported from the repository.
12 # -l LABEL User-friendly name of the branch or release.
13 # This ends up in the name of the tar file, and in the
14 # name of the directory it contains.
15 # -s Generate a snapshot (which has a date in the top-level
16 # directory).
17 # -d DOCDIR Copy prebuilt documentation from DOCDIR.
18 # -o OUTDIR Place the output files in OUTDIR. Defaults to the
19 # current directory.
21 # set -x
23 cat <<EOF
24 -------------------------------------------------
25 Date: $(date)
26 Args: $*
27 -------------------------------------------------
28 EOF
30 # Variables used in this script:
31 # $GIT_DIR = option -g GIT_DIR; passed in environment to Git
32 # $OPTARG = Bash special: argument of the option being parsed
33 # $OPTIND = Bash special: index of argument to be parsed next
34 # $commit = commit ID corresponding to $rev
35 # $docdir = option -d DOCDIR
36 # $label = option -l LABEL
37 # $opt = option letter being parsed, or '?' on error
38 # $outdir = option -o OUTDIR
39 # $rev = option -r REVISION
40 # $snap = option -s
41 # $tarbasename = name of the tar file without .tar.* extensions
42 # $tartopdir = name of the top directory within the tar file
43 # $tmpdir = temporary directory created by this script
45 rev=
46 label=
47 snap=
48 docdir=
49 outdir=.
50 while getopts "g:r:l:sd:o:" opt
52 case "$opt" in
53 (g) GIT_DIR=$OPTARG ;;
54 (r) rev=$OPTARG ;;
55 (l) label=$OPTARG ;;
56 (s) snap=1 ;;
57 (d) docdir=$OPTARG ;;
58 (o) outdir=$OPTARG ;;
59 ("?") exit 1 ;;
60 (*) printf >&2 "%s:%d: bug found\n" "$0" "$LINENO"
61 exit 1 ;;
62 esac
63 done
65 if [ $OPTIND -le $# ]
66 then
67 printf >&2 "%s: too many non-option arguments\n" "$0"
68 exit 1
71 if [ -z "$GIT_DIR" ]
72 then
73 printf >&2 "%s: Must specify -g GIT_DIR option\n" "$0"
74 exit 1
76 if [ -z "$outdir" ]
77 then
78 printf >&2 "%s: Must specify -o OUTDIR option\n" "$0"
79 exit 1
81 if [ -z "$rev" ]
82 then
83 printf >&2 "%s: Must specify -r REVISION option\n" "$0"
84 exit 1
86 if [ -z "$label" ]
87 then
88 label=$rev
91 commit=$(git --git-dir="$GIT_DIR" rev-parse --verify "$rev^{commit}") || exit 1
93 if [ "$snap" ]
94 then
95 tartopdir=elinks-$label-$(date +%Y%m%d)
96 tarbasename=elinks-current-$label
97 else
98 tartopdir=elinks-$label
99 tarbasename=elinks-$label
102 tmpdir=$(mktemp -d -t elinks-dist-XXXXXXXX) || exit 1
104 # To make it easier to compare build logs, put the source first in an
105 # "elinks" directory, and only move to "$tartopdir" when finished.
107 git --git-dir="$GIT_DIR" archive --format=tar --prefix="elinks/" "$rev" |
108 (cd -- "$tmpdir" && tar -xf -)
109 printf "%s\n" "$commit" > "$tmpdir/elinks/git-commit-id"
111 (set -e
112 cd -- "$tmpdir/elinks"
113 ./autogen.sh
114 mkdir build
115 cd build
116 # Enable lots of features so that their options will appear in elinks
117 # --config-help and doc/html/elinks.conf.5.html.
118 ../configure --enable-bittorrent --enable-cgi --enable-fsp --enable-nntp
119 make -C po
120 mv po/*.gmo ../po/
121 mv contrib/elinks.spec ../contrib/
122 ) || exit 1
124 if [ -n "$docdir" ]; then
125 mkdir -- "$tmpdir/elinks/doc/html"
126 cp -r -- "$docdir"/*.html* "$tmpdir/elinks/doc/html/"
127 # mkdir doc/pdf
128 # cp "$docdir"/*.pdf doc/pdf
129 else
130 make -C "$tmpdir/elinks/build"
131 make -C "$tmpdir/elinks/build/doc" html
132 mkdir -- "$tmpdir/elinks/doc/html"
133 mv -- "$tmpdir/elinks/build/doc"/*.html* "$tmpdir/elinks/doc/html/"
134 # <http://translationproject.org/html/maintainers.html>:
135 # "this tarball should contain an up to date POT file."
136 # Build that here. The Makefile also creates potfiles.list
137 # in the source directory; that one we don't need.
138 # Use rm -f so it's not an error if the file is not there.
139 make -C "$tmpdir/elinks/build/po" ../../po/elinks.pot
140 rm -f -- "$tmpdir/elinks/po/potfiles.list"
143 rm -rf -- "$tmpdir/elinks/build"
144 mv -- "$tmpdir/elinks" "$tmpdir/$tartopdir"
146 (set -e
147 cd -- "$tmpdir"
148 tar cf "$tarbasename.tar" "$tartopdir"
149 bzip2 --keep -- "$tarbasename.tar"
150 gzip -9 -- "$tarbasename.tar"
151 md5sum --binary -- "$tarbasename.tar.gz" > "$tarbasename.tar.gz.md5"
152 md5sum --binary -- "$tarbasename.tar.bz2" > "$tarbasename.tar.bz2.md5"
153 ) || exit 1
155 mv -- "$tmpdir/$tarbasename.tar.gz" "$outdir"
156 mv -- "$tmpdir/$tarbasename.tar.bz2" "$outdir"
157 mv -- "$tmpdir/$tarbasename.tar.gz.md5" "$outdir"
158 mv -- "$tmpdir/$tarbasename.tar.bz2.md5" "$outdir"
159 rm -rf -- "$tmpdir"