author | wenzelm |
Sat, 27 Mar 2021 22:09:49 +0100 | |
changeset 73492 | 8c93418ea257 |
parent 73491 | dbe5bbc2331e |
child 73493 | 827f53095f1c |
permissions | -rwxr-xr-x |
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 |
||
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
12 |
ISABELLE_REPOS="https://isabelle.sketis.net/repos/isabelle" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
13 |
|
73487 | 14 |
function usage() |
15 |
{ |
|
16 |
echo |
|
17 |
echo "Usage: isabelle $PRG [OPTIONS]" |
|
18 |
echo |
|
19 |
echo " Options are:" |
|
73488 | 20 |
echo " -C enforce clean update of working directory (no backup!)" |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
21 |
echo " -R version is current official release" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
22 |
echo " -U URL Isabelle repository server (default: \"$ISABELLE_REPOS\")" |
73487 | 23 |
echo " -V PATH version from explicit file or directory (file \"ISABELLE_VERSION\")" |
73492 | 24 |
echo " -r REV version according to Mercurial notation, or \".\" for remote tip" |
25 |
echo " -u version is remote tip" |
|
73487 | 26 |
echo |
27 |
echo " Setup the current ISABELLE_HOME directory, which needs to be a" |
|
28 |
echo " repository clone (all versions) or repository archive (fixed version)." |
|
29 |
echo |
|
30 |
exit 1 |
|
31 |
} |
|
32 |
||
33 |
function fail() |
|
34 |
{ |
|
35 |
echo "$1" >&2 |
|
36 |
exit 2 |
|
37 |
} |
|
38 |
||
39 |
||
40 |
## process command line |
|
41 |
||
42 |
#options |
|
43 |
||
73488 | 44 |
CLEAN="" |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
45 |
|
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
46 |
VERSION="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
47 |
VERSION_RELEASE="" |
73487 | 48 |
VERSION_PATH="" |
73488 | 49 |
VERSION_REV="" |
73487 | 50 |
|
73492 | 51 |
while getopts "CRU:V:r:u" OPT |
73487 | 52 |
do |
53 |
case "$OPT" in |
|
73488 | 54 |
C) |
55 |
CLEAN="--clean" |
|
73487 | 56 |
;; |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
57 |
R) |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
58 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
59 |
VERSION_RELEASE="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
60 |
VERSION_PATH="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
61 |
VERSION_REV="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
62 |
;; |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
63 |
U) |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
64 |
ISABELLE_REPOS="$OPTARG" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
65 |
;; |
73487 | 66 |
V) |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
67 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
68 |
VERSION_RELEASE="" |
73487 | 69 |
VERSION_PATH="$OPTARG" |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
70 |
VERSION_REV="" |
73487 | 71 |
;; |
73488 | 72 |
r) |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
73 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
74 |
VERSION_RELEASE="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
75 |
VERSION_PATH="" |
73488 | 76 |
VERSION_REV="$OPTARG" |
77 |
;; |
|
73492 | 78 |
u) |
79 |
VERSION="true" |
|
80 |
VERSION_RELEASE="" |
|
81 |
VERSION_PATH="" |
|
82 |
VERSION_REV="." |
|
83 |
;; |
|
73487 | 84 |
\?) |
85 |
usage |
|
86 |
;; |
|
87 |
esac |
|
88 |
done |
|
89 |
||
90 |
shift $(($OPTIND - 1)) |
|
91 |
||
92 |
||
93 |
# args |
|
94 |
||
95 |
[ "$#" -ne 0 ] && usage |
|
96 |
||
97 |
||
98 |
## main |
|
99 |
||
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
100 |
if [ -z "$VERSION" ]; then |
73487 | 101 |
isabelle components -I && isabelle components -a |
102 |
elif [ ! -d "$ISABELLE_HOME/.hg" ]; then |
|
103 |
fail "Not a repository clone: cannot specify version" |
|
104 |
else |
|
105 |
if [ -n "$VERSION_REV" ]; then |
|
106 |
REV="$VERSION_REV" |
|
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
107 |
elif [ -n "$VERSION_RELEASE" ]; then |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
108 |
URL="$ISABELLE_REPOS/raw-file/tip/Admin/Release/official" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
109 |
REV="$(curl -s -f "$URL" | head -n1)" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
110 |
[ -z "$REV" ] && fail "Failed to access \"$URL\"" |
73487 | 111 |
elif [ -f "$VERSION_PATH" ]; then |
112 |
REV="$(cat "$VERSION_PATH")" |
|
113 |
elif [ -d "$VERSION_PATH" ]; then |
|
114 |
if [ -f "$VERSION_PATH/ISABELLE_VERSION" ]; then |
|
115 |
REV="$(cat "$VERSION_PATH/ISABELLE_VERSION")" |
|
116 |
else |
|
117 |
fail "Missing file \"$VERSION_PATH/ISABELLE_VERSION\"" |
|
118 |
fi |
|
119 |
else |
|
120 |
fail "Missing file \"$VERSION_PATH\"" |
|
121 |
fi |
|
122 |
||
123 |
export LANG=C |
|
124 |
export HGPLAIN= |
|
125 |
||
73492 | 126 |
if [ "$REV" = "." ]; then |
127 |
REV="tip" |
|
128 |
PULL="true" |
|
129 |
PULL_REV="" |
|
73487 | 130 |
else |
73492 | 131 |
PULL_REV="true" |
132 |
if "${HG:-hg}" -R "$ISABELLE_HOME" id -r "$REV" >/dev/null 2>/dev/null |
|
133 |
then |
|
134 |
PULL="" |
|
135 |
else |
|
136 |
PULL=true |
|
137 |
fi |
|
73487 | 138 |
fi |
139 |
||
73490 | 140 |
isabelle components -I || exit "$?" |
73487 | 141 |
|
142 |
#Atomic exec: avoid inplace update of running script! |
|
73492 | 143 |
export CLEAN PULL PULL_REV REV |
73487 | 144 |
exec bash -c ' |
145 |
set -e |
|
146 |
if [ -n "$PULL" ]; then |
|
73492 | 147 |
if [ -n "$PULL_REV" ]; then |
148 |
"${HG:-hg}" -R "$ISABELLE_HOME" pull -r "$REV" "$ISABELLE_REPOS" |
|
149 |
else |
|
150 |
"${HG:-hg}" -R "$ISABELLE_HOME" pull "$ISABELLE_REPOS" |
|
151 |
fi |
|
73487 | 152 |
fi |
73489 | 153 |
"${HG:-hg}" -R "$ISABELLE_HOME" update -r "$REV" $CLEAN |
73488 | 154 |
isabelle components -a |
73489 | 155 |
"${HG:-hg}" -R "$ISABELLE_HOME" log -r "$REV" |
73487 | 156 |
' |
157 |
fi |