73487
|
1 |
#!/usr/bin/env bash
|
|
2 |
#
|
|
3 |
# Author: Makarius
|
|
4 |
#
|
|
5 |
# DESCRIPTION: setup for Isabelle repository clone or repository archive
|
|
6 |
|
|
7 |
|
|
8 |
## diagnostics
|
|
9 |
|
|
10 |
PRG="$(basename "$0")"
|
|
11 |
|
|
12 |
function usage()
|
|
13 |
{
|
|
14 |
echo
|
|
15 |
echo "Usage: isabelle $PRG [OPTIONS]"
|
|
16 |
echo
|
|
17 |
echo " Options are:"
|
|
18 |
echo " -r REV explicit Mercurial version"
|
73488
|
19 |
echo " -C enforce clean update of working directory (no backup!)"
|
73487
|
20 |
echo " -V PATH version from explicit file or directory (file \"ISABELLE_VERSION\")"
|
|
21 |
echo
|
|
22 |
echo " Setup the current ISABELLE_HOME directory, which needs to be a"
|
|
23 |
echo " repository clone (all versions) or repository archive (fixed version)."
|
|
24 |
echo
|
|
25 |
exit 1
|
|
26 |
}
|
|
27 |
|
|
28 |
function fail()
|
|
29 |
{
|
|
30 |
echo "$1" >&2
|
|
31 |
exit 2
|
|
32 |
}
|
|
33 |
|
|
34 |
|
|
35 |
## process command line
|
|
36 |
|
|
37 |
#options
|
|
38 |
|
73488
|
39 |
CLEAN=""
|
73487
|
40 |
VERSION_PATH=""
|
73488
|
41 |
VERSION_REV=""
|
73487
|
42 |
|
73488
|
43 |
while getopts "CV:r:" OPT
|
73487
|
44 |
do
|
|
45 |
case "$OPT" in
|
73488
|
46 |
C)
|
|
47 |
CLEAN="--clean"
|
73487
|
48 |
;;
|
|
49 |
V)
|
|
50 |
VERSION_PATH="$OPTARG"
|
|
51 |
;;
|
73488
|
52 |
r)
|
|
53 |
VERSION_REV="$OPTARG"
|
|
54 |
;;
|
73487
|
55 |
\?)
|
|
56 |
usage
|
|
57 |
;;
|
|
58 |
esac
|
|
59 |
done
|
|
60 |
|
|
61 |
shift $(($OPTIND - 1))
|
|
62 |
|
|
63 |
|
|
64 |
# args
|
|
65 |
|
|
66 |
[ "$#" -ne 0 ] && usage
|
|
67 |
|
|
68 |
|
|
69 |
## main
|
|
70 |
|
|
71 |
if [ -z "$VERSION_REV" -a -z "$VERSION_PATH" ]; then
|
|
72 |
isabelle components -I && isabelle components -a
|
|
73 |
elif [ -n "$VERSION_REV" -a -n "$VERSION_PATH" ]; then
|
|
74 |
fail "Duplicate version specification (options -r and -V)"
|
|
75 |
elif [ ! -d "$ISABELLE_HOME/.hg" ]; then
|
|
76 |
fail "Not a repository clone: cannot specify version"
|
|
77 |
else
|
|
78 |
export REV=""
|
|
79 |
if [ -n "$VERSION_REV" ]; then
|
|
80 |
REV="$VERSION_REV"
|
|
81 |
elif [ -f "$VERSION_PATH" ]; then
|
|
82 |
REV="$(cat "$VERSION_PATH")"
|
|
83 |
elif [ -d "$VERSION_PATH" ]; then
|
|
84 |
if [ -f "$VERSION_PATH/ISABELLE_VERSION" ]; then
|
|
85 |
REV="$(cat "$VERSION_PATH/ISABELLE_VERSION")"
|
|
86 |
else
|
|
87 |
fail "Missing file \"$VERSION_PATH/ISABELLE_VERSION\""
|
|
88 |
fi
|
|
89 |
else
|
|
90 |
fail "Missing file \"$VERSION_PATH\""
|
|
91 |
fi
|
|
92 |
|
|
93 |
export LANG=C
|
|
94 |
export HGPLAIN=
|
|
95 |
|
|
96 |
if "${HG:-hg}" id -r "$REV" >/dev/null 2>/dev/null
|
|
97 |
then
|
73488
|
98 |
PULL=""
|
73487
|
99 |
else
|
73488
|
100 |
PULL=true
|
73487
|
101 |
fi
|
|
102 |
|
|
103 |
isabelle components -I
|
|
104 |
|
|
105 |
#Atomic exec: avoid inplace update of running script!
|
73488
|
106 |
export CLEAN PULL
|
73487
|
107 |
exec bash -c '
|
|
108 |
set -e
|
|
109 |
if [ -n "$PULL" ]; then
|
|
110 |
"${HG:-hg}" pull -r "$REV"
|
|
111 |
fi
|
73488
|
112 |
"${HG:-hg}" update -r "$REV" $CLEAN
|
|
113 |
isabelle components -a
|
73487
|
114 |
"${HG:-hg}" log -r "$REV"
|
|
115 |
'
|
|
116 |
fi
|