author | wenzelm |
Fri, 07 May 2021 12:43:03 +0200 | |
changeset 73640 | f4778e08dcd7 |
parent 73589 | 479e9b17090e |
child 73705 | ac07f6be27ea |
permissions | -rwxr-xr-x |
73487 | 1 |
#!/usr/bin/env bash |
2 |
# |
|
3 |
# Author: Makarius |
|
4 |
# |
|
73514 | 5 |
# DESCRIPTION: initialize Isabelle repository clone or repository archive |
73487 | 6 |
|
7 |
||
73501
f026a9a0a43f
proper Admin script, outside the settings environment;
wenzelm
parents:
73497
diff
changeset
|
8 |
## environment |
73487 | 9 |
|
73501
f026a9a0a43f
proper Admin script, outside the settings environment;
wenzelm
parents:
73497
diff
changeset
|
10 |
export ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)" |
73487 | 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 |
|
73501
f026a9a0a43f
proper Admin script, outside the settings environment;
wenzelm
parents:
73497
diff
changeset
|
14 |
|
f026a9a0a43f
proper Admin script, outside the settings environment;
wenzelm
parents:
73497
diff
changeset
|
15 |
## diagnostics |
f026a9a0a43f
proper Admin script, outside the settings environment;
wenzelm
parents:
73497
diff
changeset
|
16 |
|
73487 | 17 |
function usage() |
18 |
{ |
|
19 |
echo |
|
73514 | 20 |
echo "Usage: Admin/init [OPTIONS]" |
73487 | 21 |
echo |
22 |
echo " Options are:" |
|
73502 | 23 |
echo " -C force clean working directory (no backup!)" |
73588 | 24 |
echo " -I NAME set \$ISABELLE_HOME/etc/ISABELLE_IDENTIFIER (or reset via -I:)" |
73584 | 25 |
echo " -L local history only: no pull from repository server" |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
26 |
echo " -R version is current official release" |
73515 | 27 |
echo " -U URL Isabelle repository server" |
28 |
echo " (default: \"$ISABELLE_REPOS\")" |
|
73584 | 29 |
echo " -V PATH version is taken from file, or directory" |
30 |
echo " with file \"ISABELLE_VERSION\"" |
|
73502 | 31 |
echo " -c check clean working directory" |
73504 | 32 |
echo " -f fresh build of Isabelle/Scala/jEdit" |
33 |
echo " -n no build of Isabelle/Scala/jEdit" |
|
73584 | 34 |
echo " -r REV version given in Mercurial notation (changeset id or tag)" |
73589 | 35 |
echo " -u update to latest tip" |
73487 | 36 |
echo |
73514 | 37 |
echo " Initialize the current ISABELLE_HOME directory, which needs to be a" |
73487 | 38 |
echo " repository clone (all versions) or repository archive (fixed version)." |
73515 | 39 |
echo " Download required components. Build Isabelle/Scala/jEdit by default." |
73487 | 40 |
echo |
41 |
exit 1 |
|
42 |
} |
|
43 |
||
44 |
function fail() |
|
45 |
{ |
|
46 |
echo "$1" >&2 |
|
47 |
exit 2 |
|
48 |
} |
|
49 |
||
50 |
||
51 |
## process command line |
|
52 |
||
53 |
#options |
|
54 |
||
73504 | 55 |
BUILD_OPTIONS="-b" |
73588 | 56 |
UPDATE_IDENTIFIER="" |
57 |
IDENTIFIER="" |
|
73584 | 58 |
PULL="true" |
73504 | 59 |
|
73502 | 60 |
CLEAN_FORCE="" |
61 |
CLEAN_CHECK="" |
|
73491
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 |
VERSION="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
64 |
VERSION_RELEASE="" |
73487 | 65 |
VERSION_PATH="" |
73488 | 66 |
VERSION_REV="" |
73487 | 67 |
|
73589 | 68 |
while getopts "CI:LRU:V:cfnr:u" OPT |
73487 | 69 |
do |
70 |
case "$OPT" in |
|
73488 | 71 |
C) |
73502 | 72 |
CLEAN_FORCE="--clean" |
73487 | 73 |
;; |
73588 | 74 |
I) |
75 |
UPDATE_IDENTIFIER="true" |
|
76 |
if [ "$OPTARG" = ":" ]; then |
|
77 |
IDENTIFIER="" |
|
78 |
else |
|
79 |
IDENTIFIER="$OPTARG" |
|
80 |
fi |
|
81 |
;; |
|
73584 | 82 |
L) |
83 |
PULL="" |
|
84 |
;; |
|
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
85 |
R) |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
86 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
87 |
VERSION_RELEASE="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
88 |
VERSION_PATH="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
89 |
VERSION_REV="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
90 |
;; |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
91 |
U) |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
92 |
ISABELLE_REPOS="$OPTARG" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
93 |
;; |
73487 | 94 |
V) |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
95 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
96 |
VERSION_RELEASE="" |
73487 | 97 |
VERSION_PATH="$OPTARG" |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
98 |
VERSION_REV="" |
73487 | 99 |
;; |
73502 | 100 |
c) |
101 |
CLEAN_CHECK="--check" |
|
102 |
;; |
|
73504 | 103 |
f) |
104 |
BUILD_OPTIONS="-b -f" |
|
105 |
;; |
|
106 |
n) |
|
107 |
BUILD_OPTIONS="" |
|
108 |
;; |
|
73488 | 109 |
r) |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
110 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
111 |
VERSION_RELEASE="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
112 |
VERSION_PATH="" |
73488 | 113 |
VERSION_REV="$OPTARG" |
114 |
;; |
|
73589 | 115 |
u) |
73492 | 116 |
VERSION="true" |
117 |
VERSION_RELEASE="" |
|
118 |
VERSION_PATH="" |
|
73493 | 119 |
VERSION_REV="tip" |
73492 | 120 |
;; |
73487 | 121 |
\?) |
122 |
usage |
|
123 |
;; |
|
124 |
esac |
|
125 |
done |
|
126 |
||
127 |
shift $(($OPTIND - 1)) |
|
128 |
||
129 |
||
130 |
# args |
|
131 |
||
132 |
[ "$#" -ne 0 ] && usage |
|
133 |
||
134 |
||
135 |
## main |
|
136 |
||
73588 | 137 |
if [ -f "$ISABELLE_HOME/etc/ISABELLE_IDENTIFIER" ]; then |
138 |
OLD_IDENTIFIER="$(cat "$ISABELLE_HOME/etc/ISABELLE_IDENTIFIER")" |
|
139 |
else |
|
140 |
OLD_IDENTIFIER="" |
|
141 |
fi |
|
142 |
||
143 |
if [ -n "$UPDATE_IDENTIFIER" -a "$IDENTIFIER" != "$OLD_IDENTIFIER" ]; then |
|
144 |
OLD_ISABELLE_HOME_USER="$("$ISABELLE_HOME/bin/isabelle" getenv -b ISABELLE_HOME_USER)" |
|
145 |
if [ -n "$IDENTIFIER" ]; then |
|
146 |
echo -n "$IDENTIFIER" > "$ISABELLE_HOME/etc/ISABELLE_IDENTIFIER" |
|
147 |
else |
|
148 |
rm -f "$ISABELLE_HOME/etc/ISABELLE_IDENTIFIER" |
|
149 |
fi |
|
150 |
ISABELLE_HOME_USER="$("$ISABELLE_HOME/bin/isabelle" getenv -b ISABELLE_HOME_USER)" |
|
151 |
echo "Changed \$ISABELLE_HOME/etc/ISABELLE_IDENTIFIER: \"$OLD_IDENTIFIER\" ~> \"$IDENTIFIER\"" |
|
152 |
echo "Changed \$ISABELLE_HOME_USER: \"$OLD_ISABELLE_HOME_USER\" ~> \"$ISABELLE_HOME_USER\"" |
|
153 |
fi |
|
154 |
||
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
155 |
if [ -z "$VERSION" ]; then |
73640 | 156 |
"$ISABELLE_HOME/bin/isabelle" components -I || exit "$?" |
157 |
"$ISABELLE_HOME/bin/isabelle" components -a || exit "$?" |
|
73504 | 158 |
if [ -n "$BUILD_OPTIONS" ]; then |
159 |
"$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS |
|
160 |
fi |
|
73487 | 161 |
elif [ ! -d "$ISABELLE_HOME/.hg" ]; then |
73515 | 162 |
fail "Not a repository clone: cannot switch version" |
73487 | 163 |
else |
164 |
if [ -n "$VERSION_REV" ]; then |
|
165 |
REV="$VERSION_REV" |
|
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
166 |
elif [ -n "$VERSION_RELEASE" ]; then |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
167 |
URL="$ISABELLE_REPOS/raw-file/tip/Admin/Release/official" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
168 |
REV="$(curl -s -f "$URL" | head -n1)" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
169 |
[ -z "$REV" ] && fail "Failed to access \"$URL\"" |
73487 | 170 |
elif [ -f "$VERSION_PATH" ]; then |
171 |
REV="$(cat "$VERSION_PATH")" |
|
172 |
elif [ -d "$VERSION_PATH" ]; then |
|
173 |
if [ -f "$VERSION_PATH/ISABELLE_VERSION" ]; then |
|
174 |
REV="$(cat "$VERSION_PATH/ISABELLE_VERSION")" |
|
175 |
else |
|
176 |
fail "Missing file \"$VERSION_PATH/ISABELLE_VERSION\"" |
|
177 |
fi |
|
178 |
else |
|
179 |
fail "Missing file \"$VERSION_PATH\"" |
|
180 |
fi |
|
181 |
||
73507 | 182 |
"$ISABELLE_HOME/bin/isabelle" components -I || exit "$?" |
183 |
||
73487 | 184 |
export LANG=C |
185 |
export HGPLAIN= |
|
186 |
||
187 |
#Atomic exec: avoid inplace update of running script! |
|
73584 | 188 |
export PULL CLEAN_FORCE CLEAN_CHECK REV ISABELLE_REPOS BUILD_OPTIONS |
73487 | 189 |
exec bash -c ' |
190 |
set -e |
|
73584 | 191 |
if [ -n "$PULL" ]; then |
192 |
"${HG:-hg}" -R "$ISABELLE_HOME" pull -r "$REV" "$ISABELLE_REPOS" |
|
193 |
fi |
|
73502 | 194 |
"${HG:-hg}" -R "$ISABELLE_HOME" update -r "$REV" $CLEAN_FORCE $CLEAN_CHECK |
73501
f026a9a0a43f
proper Admin script, outside the settings environment;
wenzelm
parents:
73497
diff
changeset
|
195 |
"$ISABELLE_HOME/bin/isabelle" components -a |
73504 | 196 |
if [ -n "$BUILD_OPTIONS" ]; then |
197 |
"$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS |
|
198 |
fi |
|
73489 | 199 |
"${HG:-hg}" -R "$ISABELLE_HOME" log -r "$REV" |
73514 | 200 |
if [ ! -f "$ISABELLE_HOME/Admin/init" ]; then |
201 |
echo >&2 "### The Admin/init script has disappeared in this version" |
|
73497 | 202 |
echo >&2 "### (need to invoke \"${HG:-hg} update\" before using it again)" |
73494 | 203 |
fi |
73487 | 204 |
' |
205 |
fi |