| author | wenzelm | 
| Thu, 08 Dec 2022 16:05:02 +0100 | |
| changeset 76603 | f10e6af0264f | 
| parent 74499 | 059743bc8311 | 
| child 77053 | c839b84ee66f | 
| permissions | -rwxr-xr-x | 
| 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:" | |
| 50653 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 18 | echo " -I init user settings" | 
| 48840 | 19 | echo " -R URL component repository (default \$ISABELLE_COMPONENT_REPOSITORY)" | 
| 53435 | 20 | echo " -a resolve all missing components" | 
| 48840 | 21 | echo " -l list status" | 
| 73308 | 22 | echo " -u DIR update \$ISABELLE_HOME_USER/etc/components: add directory" | 
| 23 | echo " -x DIR update \$ISABELLE_HOME_USER/etc/components: remove directory" | |
| 48840 | 24 | echo | 
| 73172 | 25 | echo " Resolve Isabelle components via download and installation: given COMPONENTS" | 
| 26 | echo " are identified via base name. Further operations manage etc/settings and" | |
| 27 | echo " etc/components in \$ISABELLE_HOME_USER." | |
| 48840 | 28 | echo | 
| 29 | echo " ISABELLE_COMPONENT_REPOSITORY=\"$ISABELLE_COMPONENT_REPOSITORY\"" | |
| 73172 | 30 | echo " ISABELLE_HOME_USER=\"$ISABELLE_HOME_USER\"" | 
| 48840 | 31 | echo | 
| 32 | exit 1 | |
| 33 | } | |
| 34 | ||
| 35 | function fail() | |
| 36 | {
 | |
| 37 | echo "$1" >&2 | |
| 38 | exit 2 | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | ## process command line | |
| 43 | ||
| 44 | #options | |
| 45 | ||
| 50653 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 46 | INIT_SETTINGS="" | 
| 48840 | 47 | COMPONENT_REPOSITORY="$ISABELLE_COMPONENT_REPOSITORY" | 
| 48 | ALL_MISSING="" | |
| 49 | LIST_ONLY="" | |
| 73172 | 50 | declare -a UPDATE_COMPONENTS=() | 
| 48840 | 51 | |
| 73172 | 52 | while getopts "IR:alu:x:" OPT | 
| 48840 | 53 | do | 
| 54 | case "$OPT" in | |
| 50653 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 55 | I) | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 56 | INIT_SETTINGS="true" | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 57 | ;; | 
| 48840 | 58 | R) | 
| 59 | COMPONENT_REPOSITORY="$OPTARG" | |
| 60 | ;; | |
| 61 | a) | |
| 62 | ALL_MISSING="true" | |
| 63 | ;; | |
| 64 | l) | |
| 65 | LIST_ONLY="true" | |
| 66 | ;; | |
| 73172 | 67 | u) | 
| 68 |       UPDATE_COMPONENTS["${#UPDATE_COMPONENTS[@]}"]="+$OPTARG"
 | |
| 69 | ;; | |
| 70 | x) | |
| 71 |       UPDATE_COMPONENTS["${#UPDATE_COMPONENTS[@]}"]="-$OPTARG"
 | |
| 72 | ;; | |
| 48840 | 73 | \?) | 
| 74 | usage | |
| 75 | ;; | |
| 76 | esac | |
| 77 | done | |
| 78 | ||
| 79 | shift $(($OPTIND - 1)) | |
| 80 | ||
| 81 | ||
| 82 | # args | |
| 83 | ||
| 73172 | 84 | [ "$#" -eq 0 -a -z "$INIT_SETTINGS" -a -z "$ALL_MISSING" -a -z "$LIST_ONLY" -a "${#UPDATE_COMPONENTS[@]}" -eq 0 ] && usage
 | 
| 48840 | 85 | |
| 86 | if [ -z "$ALL_MISSING" ]; then | |
| 87 | splitarray ":" "$@" | |
| 88 | else | |
| 89 | splitarray ":" "$ISABELLE_COMPONENTS_MISSING" "$@" | |
| 90 | fi | |
| 91 | declare -a SELECTED_COMPONENTS=("${SPLITARRAY[@]}")
 | |
| 92 | ||
| 93 | ||
| 94 | ## main | |
| 95 | ||
| 96 | splitarray ":" "$ISABELLE_COMPONENTS"; declare -a AVAILABLE_COMPONENTS=("${SPLITARRAY[@]}")
 | |
| 97 | splitarray ":" "$ISABELLE_COMPONENTS_MISSING"; declare -a MISSING_COMPONENTS=("${SPLITARRAY[@]}")
 | |
| 98 | ||
| 50653 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 99 | if [ -n "$INIT_SETTINGS" ]; then | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 100 | SETTINGS="$ISABELLE_HOME_USER/etc/settings" | 
| 73484 | 101 |   SETTINGS_CONTENT='init_components "${ISABELLE_COMPONENTS_BASE:-$USER_HOME/.isabelle/contrib}" "$ISABELLE_HOME/Admin/components/main"'
 | 
| 102 | if [ ! -e "$SETTINGS" ]; then | |
| 103 | echo "Initializing \"$SETTINGS\"" | |
| 104 | mkdir -p "$(dirname "$SETTINGS")" | |
| 105 |     {
 | |
| 106 | echo "#-*- shell-script -*- :mode=shellscript:" | |
| 107 | echo | |
| 108 | echo "$SETTINGS_CONTENT" | |
| 109 | } > "$SETTINGS" | |
| 110 | elif grep "init_components.*components/main" "$SETTINGS" >/dev/null 2>/dev/null | |
| 111 | then | |
| 112 | : | |
| 113 | else | |
| 50653 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 114 | echo "User settings file already exists!" | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 115 | echo | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 116 | echo "Edit \"$SETTINGS\" manually" | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 117 | echo "and add the following line near its start:" | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 118 | echo | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 119 | echo " $SETTINGS_CONTENT" | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 120 | echo | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 121 | fi | 
| 
5c85f8b80b95
simplified quick start via "isabelle components -I";
 wenzelm parents: 
48841diff
changeset | 122 | elif [ -n "$LIST_ONLY" ]; then | 
| 48840 | 123 | echo | 
| 124 | echo "Available components:" | |
| 125 |   for NAME in "${AVAILABLE_COMPONENTS[@]}"; do echo "  $NAME"; done
 | |
| 126 | echo | |
| 127 | echo "Missing components:" | |
| 128 |   for NAME in "${MISSING_COMPONENTS[@]}"; do echo "  $NAME"; done
 | |
| 73172 | 129 | elif [ "${#UPDATE_COMPONENTS[@]}" -ne 0 ]; then
 | 
| 74038 
b4f57bfe82e7
more robust "isabelle build_scala" as separate tool;
 wenzelm parents: 
74017diff
changeset | 130 | isabelle scala_build || exit $? | 
| 73172 | 131 |   exec isabelle java isabelle.Components "${UPDATE_COMPONENTS[@]}"
 | 
| 48840 | 132 | else | 
| 133 |   for NAME in "${SELECTED_COMPONENTS[@]}"
 | |
| 134 | do | |
| 135 | BASE_NAME="$(basename "$NAME")" | |
| 136 | FULL_NAME="" | |
| 137 |     for X in "${AVAILABLE_COMPONENTS[@]}" "${MISSING_COMPONENTS[@]}"
 | |
| 138 | do | |
| 139 | [ -z "$FULL_NAME" -a "$BASE_NAME" = "$(basename "$X")" ] && FULL_NAME="$X" | |
| 140 | done | |
| 141 | if [ -z "$FULL_NAME" ]; then | |
| 142 | echo "Ignoring irrelevant component \"$NAME\"" | |
| 143 | elif [ -d "$FULL_NAME" ]; then | |
| 144 | echo "Skipping existing component \"$FULL_NAME\"" | |
| 145 | else | |
| 146 |       if [ ! -e "${FULL_NAME}.tar.gz" ]; then
 | |
| 147 |         REMOTE="$COMPONENT_REPOSITORY/${BASE_NAME}.tar.gz"
 | |
| 63490 
9416333a17c2
prefer curl: presumably more portable and versatile;
 wenzelm parents: 
53435diff
changeset | 148 | type -p curl > /dev/null || fail "Cannot download files: missing curl" | 
| 48840 | 149 | echo "Getting \"$REMOTE\"" | 
| 48841 | 150 | mkdir -p "$(dirname "$FULL_NAME")" | 
| 74499 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 151 | |
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 152 | CURL_OPTIONS="--fail --silent --location" | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 153 | if [ "$ISABELLE_PLATFORM_FAMILY" = "macos" ]; then | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 154 | case $(sw_vers -productVersion) in | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 155 | 10.*) | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 156 | CURL_OPTIONS="$CURL_OPTIONS --insecure" | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 157 | ;; | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 158 | esac | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 159 | fi | 
| 
059743bc8311
workaround for old macOS versions, after change of Let's Encrypt root certificate --- see also https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 --- Java/Scala Isabelle_System.download() works, but curl doens't;
 wenzelm parents: 
74038diff
changeset | 160 |         if curl $CURL_OPTIONS "$REMOTE" > "${FULL_NAME}.tar.gz.part"
 | 
| 48840 | 161 | then | 
| 73402 | 162 |           mv -f "${FULL_NAME}.tar.gz.part" "${FULL_NAME}.tar.gz"
 | 
| 69379 | 163 | else | 
| 73402 | 164 |           rm -f "${FULL_NAME}.tar.gz.part"
 | 
| 165 | fail "Failed to download \"$REMOTE\"" | |
| 48840 | 166 | fi | 
| 167 | fi | |
| 168 |       if [ -e "${FULL_NAME}.tar.gz" ]; then
 | |
| 169 |         echo "Unpacking \"${FULL_NAME}.tar.gz\""
 | |
| 53314 | 170 |         tar -C "$(dirname "$FULL_NAME")" -x -f "${FULL_NAME}.tar.gz" || exit 2
 | 
| 48840 | 171 | fi | 
| 172 | fi | |
| 173 | done | |
| 174 | fi | |
| 175 |