Bug 765: use load_uri to load the old tab's document to avoid crash
[elinks/miciah.git] / contrib / mkdist
blob0c8d8d1dbfa4fbdcda3d1ec85dd3b04c1c04bf86
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 echo "-------------------------------------------------"
24 echo "Date: $(date)"
25 echo "Args: $*"
26 echo "-------------------------------------------------"
28 # Variables used in this script:
29 # $GIT_DIR = option -g GIT_DIR; passed in environment to Git
30 # $OPTARG = Bash special: argument of the option being parsed
31 # $OPTIND = Bash special: index of argument to be parsed next
32 # $commit = commit ID corresponding to $rev
33 # $docdir = option -d DOCDIR
34 # $label = option -l LABEL
35 # $opt = option letter being parsed, or '?' on error
36 # $outdir = option -o OUTDIR
37 # $rev = option -r REVISION
38 # $snap = option -s
39 # $tarbasename = name of the tar file without .tar.* extensions
40 # $tartopdir = name of the top directory within the tar file
41 # $tmpdir = temporary directory created by this script
43 rev=
44 label=
45 snap=
46 docdir=
47 outdir=.
48 while getopts "g:r:l:sd:o:" opt
50 case "$opt" in
51 (g) GIT_DIR=$OPTARG ;;
52 (r) rev=$OPTARG ;;
53 (l) label=$OPTARG ;;
54 (s) snap=1 ;;
55 (d) docdir=$OPTARG ;;
56 (o) outdir=$OPTARG ;;
57 ("?") exit 1 ;;
58 (*) echo >&2 "$0:$LINENO: bug found"
59 exit 1 ;;
60 esac
61 done
63 if [ $OPTIND -le $# ]
64 then
65 echo >&2 "$0: too many non-option arguments"
66 exit 1
69 if [ -z "$GIT_DIR" ]
70 then
71 echo >&2 "$0: Must specify -g GIT_DIR option"
72 exit 1
74 if [ -z "$outdir" ]
75 then
76 echo >&2 "$0: Must specify -o OUTDIR option"
77 exit 1
79 if [ -z "$rev" ]
80 then
81 echo >&2 "$0: Must specify -r REVISION option"
82 exit 1
84 if [ -z "$label" ]
85 then
86 label=$rev
89 commit=$(GIT_DIR=$GIT_DIR cg-object-id -c "$rev") || exit 1
91 if [ "$snap" ]
92 then
93 tartopdir=elinks-$label-$(date +%Y%m%d)
94 tarbasename=elinks-current-$label
95 else
96 tartopdir=elinks-$label
97 tarbasename=elinks-$label
100 tmpdir=$(mktemp -d -t elinks-dist-XXXXXXXX) || exit 1
102 # To make it easier to compare build logs, put the source first in an
103 # "elinks" directory, and only move to "$tartopdir" when finished.
105 GIT_DIR=$GIT_DIR cg-export -r "$rev" -- "$tmpdir/elinks"
106 mkdir -- "$tmpdir/elinks/.git"
107 printf "%s\n" "$commit" > "$tmpdir/elinks/.git/HEAD"
109 (set -e
110 cd -- "$tmpdir/elinks"
111 ./autogen.sh
112 mkdir build
113 cd build
114 ../configure
115 make -C po
116 mv po/*.gmo ../po/
117 mv contrib/elinks.spec ../contrib/
118 ) || exit 1
120 if [ -n "$docdir" ]; then
121 mkdir -- "$tmpdir/elinks/doc/html"
122 cp -r -- "$docdir"/*.html* "$tmpdir/elinks/doc/html/"
123 # mkdir doc/pdf
124 # cp "$docdir"/*.pdf doc/pdf
127 rm -rf -- "$tmpdir/elinks/build"
128 mv -- "$tmpdir/elinks" "$tmpdir/$tartopdir"
130 (set -e
131 cd -- "$tmpdir"
132 tar cf "$tarbasename.tar" "$tartopdir"
133 md5sum --binary -- "$tarbasename.tar" > "$tarbasename.md5"
134 bzip2 --keep -- "$tarbasename.tar"
135 gzip -9 -- "$tarbasename.tar"
136 md5sum --binary -- "$tarbasename.tar.gz" "$tarbasename.tar.bz2" >> "$tarbasename.md5"
137 ) || exit 1
139 mv -- "$tmpdir/$tarbasename.tar.gz" "$outdir"
140 mv -- "$tmpdir/$tarbasename.tar.bz2" "$outdir"
141 mv -- "$tmpdir/$tarbasename.md5" "$outdir"
142 rm -rf -- "$tmpdir"