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