1 #!/usr/bin/env bash |
|
2 # |
|
3 # Author: Makarius |
|
4 # |
|
5 # DESCRIPTION: setup for Isabelle repository clone or repository archive |
|
6 |
|
7 |
|
8 ## environment |
|
9 |
|
10 export ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)" |
|
11 |
|
12 ISABELLE_REPOS="https://isabelle.sketis.net/repos/isabelle" |
|
13 |
|
14 |
|
15 ## diagnostics |
|
16 |
|
17 function usage() |
|
18 { |
|
19 echo |
|
20 echo "Usage: Admin/setup [OPTIONS]" |
|
21 echo |
|
22 echo " Options are:" |
|
23 echo " -C force clean working directory (no backup!)" |
|
24 echo " -R version is current official release" |
|
25 echo " -U URL Isabelle repository server (default: \"$ISABELLE_REPOS\")" |
|
26 echo " -V PATH version from explicit file or directory (file \"ISABELLE_VERSION\")" |
|
27 echo " -c check clean working directory" |
|
28 echo " -f fresh build of Isabelle/Scala/jEdit" |
|
29 echo " -n no build of Isabelle/Scala/jEdit" |
|
30 echo " -r REV version according to Mercurial notation" |
|
31 echo " -u version is tip (after pull from Isabelle repository server)" |
|
32 echo |
|
33 echo " Setup the current ISABELLE_HOME directory, which needs to be a" |
|
34 echo " repository clone (all versions) or repository archive (fixed version)." |
|
35 echo " Download required components and build Isabelle/Scala/jEdit (default)." |
|
36 echo |
|
37 exit 1 |
|
38 } |
|
39 |
|
40 function fail() |
|
41 { |
|
42 echo "$1" >&2 |
|
43 exit 2 |
|
44 } |
|
45 |
|
46 |
|
47 ## process command line |
|
48 |
|
49 #options |
|
50 |
|
51 BUILD_OPTIONS="-b" |
|
52 |
|
53 CLEAN_FORCE="" |
|
54 CLEAN_CHECK="" |
|
55 |
|
56 VERSION="" |
|
57 VERSION_RELEASE="" |
|
58 VERSION_PATH="" |
|
59 VERSION_REV="" |
|
60 |
|
61 while getopts "CRU:V:cfnr:u" OPT |
|
62 do |
|
63 case "$OPT" in |
|
64 C) |
|
65 CLEAN_FORCE="--clean" |
|
66 ;; |
|
67 R) |
|
68 VERSION="true" |
|
69 VERSION_RELEASE="true" |
|
70 VERSION_PATH="" |
|
71 VERSION_REV="" |
|
72 ;; |
|
73 U) |
|
74 ISABELLE_REPOS="$OPTARG" |
|
75 ;; |
|
76 V) |
|
77 VERSION="true" |
|
78 VERSION_RELEASE="" |
|
79 VERSION_PATH="$OPTARG" |
|
80 VERSION_REV="" |
|
81 ;; |
|
82 c) |
|
83 CLEAN_CHECK="--check" |
|
84 ;; |
|
85 f) |
|
86 BUILD_OPTIONS="-b -f" |
|
87 ;; |
|
88 n) |
|
89 BUILD_OPTIONS="" |
|
90 ;; |
|
91 r) |
|
92 VERSION="true" |
|
93 VERSION_RELEASE="" |
|
94 VERSION_PATH="" |
|
95 VERSION_REV="$OPTARG" |
|
96 ;; |
|
97 u) |
|
98 VERSION="true" |
|
99 VERSION_RELEASE="" |
|
100 VERSION_PATH="" |
|
101 VERSION_REV="tip" |
|
102 ;; |
|
103 \?) |
|
104 usage |
|
105 ;; |
|
106 esac |
|
107 done |
|
108 |
|
109 shift $(($OPTIND - 1)) |
|
110 |
|
111 |
|
112 # args |
|
113 |
|
114 [ "$#" -ne 0 ] && usage |
|
115 |
|
116 |
|
117 ## main |
|
118 |
|
119 if [ -z "$VERSION" ]; then |
|
120 "$ISABELLE_HOME/bin/isabelle" components -I || exit "?$" |
|
121 "$ISABELLE_HOME/bin/isabelle" components -a || exit "?$" |
|
122 if [ -n "$BUILD_OPTIONS" ]; then |
|
123 "$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS |
|
124 fi |
|
125 elif [ ! -d "$ISABELLE_HOME/.hg" ]; then |
|
126 fail "Not a repository clone: cannot specify version" |
|
127 else |
|
128 if [ -n "$VERSION_REV" ]; then |
|
129 REV="$VERSION_REV" |
|
130 elif [ -n "$VERSION_RELEASE" ]; then |
|
131 URL="$ISABELLE_REPOS/raw-file/tip/Admin/Release/official" |
|
132 REV="$(curl -s -f "$URL" | head -n1)" |
|
133 [ -z "$REV" ] && fail "Failed to access \"$URL\"" |
|
134 elif [ -f "$VERSION_PATH" ]; then |
|
135 REV="$(cat "$VERSION_PATH")" |
|
136 elif [ -d "$VERSION_PATH" ]; then |
|
137 if [ -f "$VERSION_PATH/ISABELLE_VERSION" ]; then |
|
138 REV="$(cat "$VERSION_PATH/ISABELLE_VERSION")" |
|
139 else |
|
140 fail "Missing file \"$VERSION_PATH/ISABELLE_VERSION\"" |
|
141 fi |
|
142 else |
|
143 fail "Missing file \"$VERSION_PATH\"" |
|
144 fi |
|
145 |
|
146 "$ISABELLE_HOME/bin/isabelle" components -I || exit "$?" |
|
147 |
|
148 export LANG=C |
|
149 export HGPLAIN= |
|
150 |
|
151 #Atomic exec: avoid inplace update of running script! |
|
152 export CLEAN_FORCE CLEAN_CHECK REV ISABELLE_REPOS BUILD_OPTIONS |
|
153 exec bash -c ' |
|
154 set -e |
|
155 "${HG:-hg}" -R "$ISABELLE_HOME" pull -r "$REV" "$ISABELLE_REPOS" |
|
156 "${HG:-hg}" -R "$ISABELLE_HOME" update -r "$REV" $CLEAN_FORCE $CLEAN_CHECK |
|
157 "$ISABELLE_HOME/bin/isabelle" components -a |
|
158 if [ -n "$BUILD_OPTIONS" ]; then |
|
159 "$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS |
|
160 fi |
|
161 "${HG:-hg}" -R "$ISABELLE_HOME" log -r "$REV" |
|
162 if [ ! -f "$ISABELLE_HOME/Admin/setup" ]; then |
|
163 echo >&2 "### The Admin/setup script has disappeared in this version" |
|
164 echo >&2 "### (need to invoke \"${HG:-hg} update\" before using it again)" |
|
165 fi |
|
166 ' |
|
167 fi |
|