48840
|
1 |
#!/usr/bin/env bash
|
|
2 |
#
|
|
3 |
# Author: Makarius
|
|
4 |
#
|
|
5 |
# DESCRIPTION: resolve Isabelle components
|
|
6 |
|
|
7 |
|
|
8 |
## diagnostics
|
|
9 |
|
|
10 |
PRG="$(basename "$0")"
|
|
11 |
|
|
12 |
function usage()
|
|
13 |
{
|
|
14 |
echo
|
|
15 |
echo "Usage: isabelle $PRG [OPTIONS] [COMPONENTS ...]"
|
|
16 |
echo
|
|
17 |
echo " Options are:"
|
|
18 |
echo " -R URL component repository (default \$ISABELLE_COMPONENT_REPOSITORY)"
|
|
19 |
echo " -a all missing components"
|
|
20 |
echo " -l list status"
|
|
21 |
echo
|
|
22 |
echo " Resolve Isabelle components via download and installation."
|
|
23 |
echo " COMPONENTS are identified via base name."
|
|
24 |
echo
|
|
25 |
echo " ISABELLE_COMPONENT_REPOSITORY=\"$ISABELLE_COMPONENT_REPOSITORY\""
|
|
26 |
echo
|
|
27 |
exit 1
|
|
28 |
}
|
|
29 |
|
|
30 |
function fail()
|
|
31 |
{
|
|
32 |
echo "$1" >&2
|
|
33 |
exit 2
|
|
34 |
}
|
|
35 |
|
|
36 |
|
|
37 |
## process command line
|
|
38 |
|
|
39 |
#options
|
|
40 |
|
|
41 |
COMPONENT_REPOSITORY="$ISABELLE_COMPONENT_REPOSITORY"
|
|
42 |
ALL_MISSING=""
|
|
43 |
LIST_ONLY=""
|
|
44 |
|
|
45 |
while getopts "R:al" OPT
|
|
46 |
do
|
|
47 |
case "$OPT" in
|
|
48 |
R)
|
|
49 |
COMPONENT_REPOSITORY="$OPTARG"
|
|
50 |
;;
|
|
51 |
a)
|
|
52 |
ALL_MISSING="true"
|
|
53 |
;;
|
|
54 |
l)
|
|
55 |
LIST_ONLY="true"
|
|
56 |
;;
|
|
57 |
\?)
|
|
58 |
usage
|
|
59 |
;;
|
|
60 |
esac
|
|
61 |
done
|
|
62 |
|
|
63 |
shift $(($OPTIND - 1))
|
|
64 |
|
|
65 |
|
|
66 |
# args
|
|
67 |
|
|
68 |
[ "$#" -eq 0 -a -z "$ALL_MISSING" -a -z "$LIST_ONLY" ] && usage
|
|
69 |
|
|
70 |
if [ -z "$ALL_MISSING" ]; then
|
|
71 |
splitarray ":" "$@"
|
|
72 |
else
|
|
73 |
splitarray ":" "$ISABELLE_COMPONENTS_MISSING" "$@"
|
|
74 |
fi
|
|
75 |
declare -a SELECTED_COMPONENTS=("${SPLITARRAY[@]}")
|
|
76 |
|
|
77 |
|
|
78 |
## main
|
|
79 |
|
|
80 |
splitarray ":" "$ISABELLE_COMPONENTS"; declare -a AVAILABLE_COMPONENTS=("${SPLITARRAY[@]}")
|
|
81 |
splitarray ":" "$ISABELLE_COMPONENTS_MISSING"; declare -a MISSING_COMPONENTS=("${SPLITARRAY[@]}")
|
|
82 |
|
|
83 |
if [ -n "$LIST_ONLY" ]; then
|
|
84 |
echo
|
|
85 |
echo "Available components:"
|
|
86 |
for NAME in "${AVAILABLE_COMPONENTS[@]}"; do echo " $NAME"; done
|
|
87 |
echo
|
|
88 |
echo "Missing components:"
|
|
89 |
for NAME in "${MISSING_COMPONENTS[@]}"; do echo " $NAME"; done
|
|
90 |
else
|
|
91 |
for NAME in "${SELECTED_COMPONENTS[@]}"
|
|
92 |
do
|
|
93 |
BASE_NAME="$(basename "$NAME")"
|
|
94 |
FULL_NAME=""
|
|
95 |
for X in "${AVAILABLE_COMPONENTS[@]}" "${MISSING_COMPONENTS[@]}"
|
|
96 |
do
|
|
97 |
[ -z "$FULL_NAME" -a "$BASE_NAME" = "$(basename "$X")" ] && FULL_NAME="$X"
|
|
98 |
done
|
|
99 |
if [ -z "$FULL_NAME" ]; then
|
|
100 |
echo "Ignoring irrelevant component \"$NAME\""
|
|
101 |
elif [ -d "$FULL_NAME" ]; then
|
|
102 |
echo "Skipping existing component \"$FULL_NAME\""
|
|
103 |
else
|
|
104 |
if [ ! -e "${FULL_NAME}.tar.gz" ]; then
|
|
105 |
REMOTE="$COMPONENT_REPOSITORY/${BASE_NAME}.tar.gz"
|
|
106 |
echo "Getting \"$REMOTE\""
|
48841
|
107 |
mkdir -p "$(dirname "$FULL_NAME")"
|
48840
|
108 |
perl -MLWP::Simple -e "getprint '$REMOTE';" > "${FULL_NAME}.tar.gz"
|
|
109 |
if perl -e "exit((stat('${FULL_NAME}.tar.gz'))[7] == 0 ? 0 : 1);"
|
|
110 |
then
|
|
111 |
rm -f "${FULL_NAME}.tar.gz"
|
|
112 |
fi
|
|
113 |
fi
|
|
114 |
if [ -e "${FULL_NAME}.tar.gz" ]; then
|
|
115 |
echo "Unpacking \"${FULL_NAME}.tar.gz\""
|
|
116 |
tar -C "$(dirname "$FULL_NAME")" -x -f "${FULL_NAME}.tar.gz"
|
|
117 |
fi
|
|
118 |
fi
|
|
119 |
done
|
|
120 |
fi
|
|
121 |
|