| author | wenzelm |
| Fri, 17 Aug 2012 11:18:26 +0200 | |
| changeset 48833 | 10584ca5785f |
| parent 48817 | 01d1734f779d |
| permissions | -rwxr-xr-x |
| 48593 | 1 |
#!/usr/bin/env bash |
2 |
# |
|
3 |
# Author: Florian Haftmann |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
4 |
# Author: Tjark Weber |
| 48593 | 5 |
# |
| 48817 | 6 |
# DESCRIPTION: download Isabelle components |
| 48593 | 7 |
|
8 |
shopt -s -o errexit |
|
9 |
shopt -s -o nounset |
|
10 |
||
| 48817 | 11 |
## directory layout |
12 |
||
13 |
: ${TMPDIR:="/tmp"}
|
|
14 |
||
15 |
LOCAL="${ISABELLE_HOME_USER}/contrib"
|
|
16 |
||
17 |
REMOTE="http://isabelle.in.tum.de/components" |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
18 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
19 |
## diagnostics |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
20 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
21 |
PRG="$(basename "$0")" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
22 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
23 |
trap 'echo "Error in ${PRG}" >&2' ERR
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
24 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
25 |
function usage() |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
26 |
{
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
27 |
cat <<EOF |
| 48593 | 28 |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
29 |
Usage: ${PRG} [OPTIONS] [COMPONENTS ...]
|
| 48593 | 30 |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
31 |
Options are: |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
32 |
-c Download current components (as listed in Admin/components). |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
33 |
-q Quiet (do not output diagnostic messages). |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
34 |
-r Replace components already present (default is to skip). |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
35 |
-x Exit on failed download (default is to ignore). |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
36 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
37 |
Download and unpack Isabelle components from central component store |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
38 |
(${REMOTE}/).
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
39 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
40 |
EOF |
| 48593 | 41 |
exit 1 |
42 |
} |
|
43 |
||
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
44 |
function fail() |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
45 |
{
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
46 |
echo "$1" >&2 |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
47 |
exit 2 |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
48 |
} |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
49 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
50 |
## process command line |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
51 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
52 |
# options |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
53 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
54 |
DOWNLOAD_CURRENT="" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
55 |
ECHO="echo" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
56 |
REPLACE_EXISTING="" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
57 |
EXIT_ON_FAILED_DOWNLOAD="" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
58 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
59 |
function getoptions() |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
60 |
{
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
61 |
OPTIND=1 |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
62 |
while getopts "cqrx" OPT |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
63 |
do |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
64 |
case "$OPT" in |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
65 |
c) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
66 |
DOWNLOAD_CURRENT=true |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
67 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
68 |
q) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
69 |
ECHO=":" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
70 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
71 |
r) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
72 |
REPLACE_EXISTING=true |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
73 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
74 |
x) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
75 |
EXIT_ON_FAILED_DOWNLOAD=true |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
76 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
77 |
\?) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
78 |
usage |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
79 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
80 |
esac |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
81 |
done |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
82 |
} |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
83 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
84 |
getoptions "$@" |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
85 |
shift $(($OPTIND - 1)) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
86 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
87 |
## download (and unpack) components |
| 48593 | 88 |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
89 |
function download() |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
90 |
{
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
91 |
if [ -e "${LOCAL}/${COMPONENT}" -a -z "${REPLACE_EXISTING}" ]; then
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
92 |
"${ECHO}" "Skipping existing component ${COMPONENT}"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
93 |
else |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
94 |
"${ECHO}" "${COMPONENT}"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
95 |
ARCHIVE="${COMPONENT}.tar.gz"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
96 |
if curl -s `"${ECHO}" --no-silent` -f -o "${TMPDIR}/${ARCHIVE}" "${REMOTE}/${ARCHIVE}"; then
|
| 48817 | 97 |
if [ -n "${REPLACE_EXISTING}" ]; then
|
98 |
tar -xzf "${TMPDIR}/${ARCHIVE}" -C "${LOCAL}" --recursive-unlink
|
|
99 |
else |
|
100 |
tar -xzf "${TMPDIR}/${ARCHIVE}" -C "${LOCAL}"
|
|
101 |
fi |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
102 |
else |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
103 |
if [ -n "${EXIT_ON_FAILED_DOWNLOAD}" ]; then
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
104 |
fail "Error downloading component ${COMPONENT} (non-free?)"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
105 |
else |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
106 |
"${ECHO}" "Error downloading component ${COMPONENT} (non-free?)"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
107 |
fi |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
108 |
fi |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
109 |
fi |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
110 |
} |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
111 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
112 |
"${ECHO}" "Unpacking components into ${LOCAL}/"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
113 |
|
| 48817 | 114 |
mkdir -p "${LOCAL}"
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
115 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
116 |
# process Admin/components |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
117 |
if [ -n "${DOWNLOAD_CURRENT}" ]; then
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
118 |
while { unset REPLY; read -r; test "$?" = 0 -o -n "${REPLY}"; }
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
119 |
do |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
120 |
case "${REPLY}" in
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
121 |
\#* | "") |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
122 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
123 |
*) |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
124 |
COMPONENT="$(basename "${REPLY}")"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
125 |
download "${COMPONENT}"
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
126 |
;; |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
127 |
esac |
| 48817 | 128 |
done < "${ISABELLE_HOME}/Admin/components"
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
129 |
fi |
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
130 |
|
|
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
131 |
# process args |
| 48593 | 132 |
for COMPONENT in "$@" |
133 |
do |
|
|
48809
2db8aa3459d4
Added various options, notably -c to download components listed in Admin/components. Also, curl instead of wget.
webertj
parents:
48788
diff
changeset
|
134 |
download "${COMPONENT}"
|
| 48593 | 135 |
done |