author | wenzelm |
Fri, 16 Apr 2021 21:50:47 +0200 | |
changeset 73584 | 1d4c9fa00821 |
parent 73517 | d3f2038198ae |
child 73588 | a96de8bbe8a3 |
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!)" |
73584 | 24 |
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
|
25 |
echo " -R version is current official release" |
73515 | 26 |
echo " -U URL Isabelle repository server" |
27 |
echo " (default: \"$ISABELLE_REPOS\")" |
|
73584 | 28 |
echo " -V PATH version is taken from file, or directory" |
29 |
echo " with file \"ISABELLE_VERSION\"" |
|
73502 | 30 |
echo " -c check clean working directory" |
73504 | 31 |
echo " -f fresh build of Isabelle/Scala/jEdit" |
32 |
echo " -n no build of Isabelle/Scala/jEdit" |
|
73584 | 33 |
echo " -r REV version given in Mercurial notation (changeset id or tag)" |
34 |
echo " -t version is latest tip" |
|
73487 | 35 |
echo |
73514 | 36 |
echo " Initialize the current ISABELLE_HOME directory, which needs to be a" |
73487 | 37 |
echo " repository clone (all versions) or repository archive (fixed version)." |
73515 | 38 |
echo " Download required components. Build Isabelle/Scala/jEdit by default." |
73487 | 39 |
echo |
40 |
exit 1 |
|
41 |
} |
|
42 |
||
43 |
function fail() |
|
44 |
{ |
|
45 |
echo "$1" >&2 |
|
46 |
exit 2 |
|
47 |
} |
|
48 |
||
49 |
||
50 |
## process command line |
|
51 |
||
52 |
#options |
|
53 |
||
73504 | 54 |
BUILD_OPTIONS="-b" |
73584 | 55 |
PULL="true" |
73504 | 56 |
|
73502 | 57 |
CLEAN_FORCE="" |
58 |
CLEAN_CHECK="" |
|
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
59 |
|
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
60 |
VERSION="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
61 |
VERSION_RELEASE="" |
73487 | 62 |
VERSION_PATH="" |
73488 | 63 |
VERSION_REV="" |
73487 | 64 |
|
73584 | 65 |
while getopts "CLRU:V:cfnr:t" OPT |
73487 | 66 |
do |
67 |
case "$OPT" in |
|
73488 | 68 |
C) |
73502 | 69 |
CLEAN_FORCE="--clean" |
73487 | 70 |
;; |
73584 | 71 |
L) |
72 |
PULL="" |
|
73 |
;; |
|
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
74 |
R) |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
75 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
76 |
VERSION_RELEASE="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
77 |
VERSION_PATH="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
78 |
VERSION_REV="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
79 |
;; |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
80 |
U) |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
81 |
ISABELLE_REPOS="$OPTARG" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
82 |
;; |
73487 | 83 |
V) |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
84 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
85 |
VERSION_RELEASE="" |
73487 | 86 |
VERSION_PATH="$OPTARG" |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
87 |
VERSION_REV="" |
73487 | 88 |
;; |
73502 | 89 |
c) |
90 |
CLEAN_CHECK="--check" |
|
91 |
;; |
|
73504 | 92 |
f) |
93 |
BUILD_OPTIONS="-b -f" |
|
94 |
;; |
|
95 |
n) |
|
96 |
BUILD_OPTIONS="" |
|
97 |
;; |
|
73488 | 98 |
r) |
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
99 |
VERSION="true" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
100 |
VERSION_RELEASE="" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
101 |
VERSION_PATH="" |
73488 | 102 |
VERSION_REV="$OPTARG" |
103 |
;; |
|
73584 | 104 |
t) |
73492 | 105 |
VERSION="true" |
106 |
VERSION_RELEASE="" |
|
107 |
VERSION_PATH="" |
|
73493 | 108 |
VERSION_REV="tip" |
73492 | 109 |
;; |
73487 | 110 |
\?) |
111 |
usage |
|
112 |
;; |
|
113 |
esac |
|
114 |
done |
|
115 |
||
116 |
shift $(($OPTIND - 1)) |
|
117 |
||
118 |
||
119 |
# args |
|
120 |
||
121 |
[ "$#" -ne 0 ] && usage |
|
122 |
||
123 |
||
124 |
## main |
|
125 |
||
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
126 |
if [ -z "$VERSION" ]; then |
73504 | 127 |
"$ISABELLE_HOME/bin/isabelle" components -I || exit "?$" |
128 |
"$ISABELLE_HOME/bin/isabelle" components -a || exit "?$" |
|
129 |
if [ -n "$BUILD_OPTIONS" ]; then |
|
130 |
"$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS |
|
131 |
fi |
|
73487 | 132 |
elif [ ! -d "$ISABELLE_HOME/.hg" ]; then |
73515 | 133 |
fail "Not a repository clone: cannot switch version" |
73487 | 134 |
else |
135 |
if [ -n "$VERSION_REV" ]; then |
|
136 |
REV="$VERSION_REV" |
|
73491
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
137 |
elif [ -n "$VERSION_RELEASE" ]; then |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
138 |
URL="$ISABELLE_REPOS/raw-file/tip/Admin/Release/official" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
139 |
REV="$(curl -s -f "$URL" | head -n1)" |
dbe5bbc2331e
clarified treatment of multiple versions: last one counts;
wenzelm
parents:
73490
diff
changeset
|
140 |
[ -z "$REV" ] && fail "Failed to access \"$URL\"" |
73487 | 141 |
elif [ -f "$VERSION_PATH" ]; then |
142 |
REV="$(cat "$VERSION_PATH")" |
|
143 |
elif [ -d "$VERSION_PATH" ]; then |
|
144 |
if [ -f "$VERSION_PATH/ISABELLE_VERSION" ]; then |
|
145 |
REV="$(cat "$VERSION_PATH/ISABELLE_VERSION")" |
|
146 |
else |
|
147 |
fail "Missing file \"$VERSION_PATH/ISABELLE_VERSION\"" |
|
148 |
fi |
|
149 |
else |
|
150 |
fail "Missing file \"$VERSION_PATH\"" |
|
151 |
fi |
|
152 |
||
73507 | 153 |
"$ISABELLE_HOME/bin/isabelle" components -I || exit "$?" |
154 |
||
73487 | 155 |
export LANG=C |
156 |
export HGPLAIN= |
|
157 |
||
158 |
#Atomic exec: avoid inplace update of running script! |
|
73584 | 159 |
export PULL CLEAN_FORCE CLEAN_CHECK REV ISABELLE_REPOS BUILD_OPTIONS |
73487 | 160 |
exec bash -c ' |
161 |
set -e |
|
73584 | 162 |
if [ -n "$PULL" ]; then |
163 |
"${HG:-hg}" -R "$ISABELLE_HOME" pull -r "$REV" "$ISABELLE_REPOS" |
|
164 |
fi |
|
73502 | 165 |
"${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
|
166 |
"$ISABELLE_HOME/bin/isabelle" components -a |
73504 | 167 |
if [ -n "$BUILD_OPTIONS" ]; then |
168 |
"$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS |
|
169 |
fi |
|
73489 | 170 |
"${HG:-hg}" -R "$ISABELLE_HOME" log -r "$REV" |
73514 | 171 |
if [ ! -f "$ISABELLE_HOME/Admin/init" ]; then |
172 |
echo >&2 "### The Admin/init script has disappeared in this version" |
|
73497 | 173 |
echo >&2 "### (need to invoke \"${HG:-hg} update\" before using it again)" |
73494 | 174 |
fi |
73487 | 175 |
' |
176 |
fi |