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