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