|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Downloads optional library modules (e.g. dawn, metalangle) that are not part |
| 3 | +# of the core openFrameworksLibs packages. apothecary publishes them per library |
| 4 | +# on its latest-modular release as oF_<lib>_<target>_<arch>[_gcc<N>].tar.bz2 |
| 5 | +# (.zip for Visual Studio / MSYS2); each one unpacks to libs/<lib>/. |
| 6 | +# |
| 7 | +# Modules that aren't built for a target yet are skipped with a note. |
| 8 | +# |
| 9 | +# Usage: download_modules.sh -p <platform> [-a <arch>] [-t <tag>] [--require] <module> [<module>...] |
| 10 | +# download_modules.sh -p macos dawn metalangle |
| 11 | +# OF_LIB_MODULES=dawn,metalangle scripts/macos/download_libs.sh (via download_libs.sh --modules) |
| 12 | + |
| 13 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 14 | +OF_ROOT="$( cd "$SCRIPT_DIR/../.." && pwd )" |
| 15 | +REPO="openframeworks/apothecary" |
| 16 | +TAG="latest-modular" |
| 17 | +PLATFORM="" |
| 18 | +ARCH="" |
| 19 | +REQUIRE=0 |
| 20 | +SILENT_ARGS="" |
| 21 | +NO_SSL="" |
| 22 | +MODULES=() |
| 23 | + |
| 24 | +. "$SCRIPT_DIR/downloader.sh" |
| 25 | +. "$SCRIPT_DIR/sha_verify.sh" |
| 26 | + |
| 27 | +printHelp(){ |
| 28 | + sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//' |
| 29 | + cat <<EOF |
| 30 | +
|
| 31 | +Options: |
| 32 | + -p, --platform PLATFORM osx | macos | ios | tvos | vs | msys2 | linux64 | linuxaarch64 | linuxarmv6l | linuxarmv7l | emscripten |
| 33 | + -a, --arch ARCH vs: 64 | arm64 | arm64ec; emscripten: 32 | 64; msys2: ucrt64 | clang64 | clangarm64 |
| 34 | + -t, --tag TAG apothecary release (default latest-modular) |
| 35 | + --require fail if a module isn't built for this platform (default: skip it) |
| 36 | + -s, --silent / -k, --no-ssl passed to the downloader |
| 37 | +EOF |
| 38 | +} |
| 39 | + |
| 40 | +while [[ $# -gt 0 ]]; do |
| 41 | + case "$1" in |
| 42 | + -p|--platform) PLATFORM="$2"; shift 2 ;; |
| 43 | + -a|--arch) ARCH="$2"; shift 2 ;; |
| 44 | + -t|--tag) TAG="$2"; shift 2 ;; |
| 45 | + --require) REQUIRE=1; shift ;; |
| 46 | + -s|--silent) SILENT_ARGS="-s"; shift ;; |
| 47 | + -k|--no-ssl) NO_SSL="-k"; shift ;; |
| 48 | + -h|--help) printHelp; exit 0 ;; |
| 49 | + -*) echo "Unknown option $1"; printHelp; exit 1 ;; |
| 50 | + *) IFS=', ' read -r -a list <<< "$1"; MODULES+=("${list[@]}"); shift ;; |
| 51 | + esac |
| 52 | +done |
| 53 | + |
| 54 | +if [[ ${#MODULES[@]} -eq 0 ]]; then |
| 55 | + echo "No modules given"; printHelp; exit 1 |
| 56 | +fi |
| 57 | +[[ -z "$PLATFORM" ]] && { echo "No platform given (-p)"; exit 1; } |
| 58 | + |
| 59 | +# candidate package suffixes for this platform, most specific first; the first |
| 60 | +# one published on the release is used. Apple installs every Apple target that |
| 61 | +# is built, like the core macos package covers all of them. |
| 62 | +candidateSuffixes(){ |
| 63 | + local gcc |
| 64 | + case "$PLATFORM" in |
| 65 | + osx|macos|ios|tvos|catos|xros) |
| 66 | + echo "osx_64.tar.bz2|ios_64.tar.bz2|tvos_64.tar.bz2|catos_64.tar.bz2|xros_64.tar.bz2" ;; |
| 67 | + vs) |
| 68 | + case "$(echo "${ARCH:-64}" | tr '[:upper:]' '[:lower:]')" in |
| 69 | + arm64ec) echo "vs_arm64ec.zip" ;; |
| 70 | + arm64) echo "vs_arm64.zip" ;; |
| 71 | + *) echo "vs_64.zip" ;; |
| 72 | + esac ;; |
| 73 | + msys2) |
| 74 | + echo "msys2_$(echo "${ARCH:-${MSYSTEM:-ucrt64}}" | tr '[:upper:]' '[:lower:]').zip" ;; |
| 75 | + emscripten) |
| 76 | + echo "emscripten_${ARCH:-32}.tar.bz2" ;; |
| 77 | + linux64|linuxaarch64|linuxarmv6l|linuxarmv7l) |
| 78 | + gcc=$(gcc -dumpversion 2>/dev/null | cut -d. -f1) |
| 79 | + local first=gcc14 second=gcc10 |
| 80 | + [[ -n "$gcc" && "$gcc" -lt 14 ]] && { first=gcc10; second=gcc14; } |
| 81 | + case "$PLATFORM" in |
| 82 | + linux64) echo "linux_64_${first}.tar.bz2 linux_64_${second}.tar.bz2" ;; |
| 83 | + linuxaarch64) echo "linux_arm64_${first}.tar.bz2 linux_arm64_${second}.tar.bz2 linux_aarch64_gcc10.tar.bz2" ;; |
| 84 | + linuxarmv6l) echo "linux_armv6l_gcc10.tar.bz2" ;; |
| 85 | + linuxarmv7l) echo "linux_armv7l_gcc10.tar.bz2" ;; |
| 86 | + esac ;; |
| 87 | + *) echo "" ;; |
| 88 | + esac |
| 89 | +} |
| 90 | + |
| 91 | +MAP=$(mktemp 2>/dev/null || mktemp -t ofmodmap) |
| 92 | +HAVE_MAP=0 |
| 93 | +fetchGithubReleaseDigests "$REPO" "$TAG" "$MAP" && HAVE_MAP=1 |
| 94 | + |
| 95 | +isPublished(){ |
| 96 | + local asset="$1" |
| 97 | + if [[ $HAVE_MAP -eq 1 ]]; then |
| 98 | + [[ -n "$(lookupDigest "$MAP" "$asset")" ]] |
| 99 | + else |
| 100 | + curl -fsIL -o /dev/null "https://github.com/$REPO/releases/download/$TAG/$asset" |
| 101 | + fi |
| 102 | +} |
| 103 | + |
| 104 | +mkdir -p "$OF_ROOT/libs/download" |
| 105 | +cd "$OF_ROOT/libs/download" || exit 1 |
| 106 | + |
| 107 | +failed=0 |
| 108 | +installed=() |
| 109 | +for module in "${MODULES[@]}"; do |
| 110 | + [[ -z "$module" ]] && continue |
| 111 | + groups=$(candidateSuffixes) |
| 112 | + if [[ -z "$groups" ]]; then |
| 113 | + echo " ! [$module] modules aren't published for platform $PLATFORM" |
| 114 | + [[ $REQUIRE -eq 1 ]] && failed=1 |
| 115 | + continue |
| 116 | + fi |
| 117 | + found_any=0 |
| 118 | + # "|" separates targets that are all installed (Apple); spaces separate |
| 119 | + # alternatives for one target (first published wins) |
| 120 | + IFS='|' read -r -a targets <<< "$groups" |
| 121 | + for alternatives in "${targets[@]}"; do |
| 122 | + asset="" |
| 123 | + for suffix in $alternatives; do |
| 124 | + if isPublished "oF_${module}_${suffix}"; then asset="oF_${module}_${suffix}"; break; fi |
| 125 | + done |
| 126 | + [[ -z "$asset" ]] && continue |
| 127 | + found_any=1 |
| 128 | + echo " [$module] downloading $asset" |
| 129 | + rm -f "$asset" |
| 130 | + downloader "https://github.com/$REPO/releases/download/$TAG/$asset" $SILENT_ARGS $NO_SSL |
| 131 | + if [[ ! -s "$asset" ]]; then |
| 132 | + echo " ! [$module] download failed: $asset"; failed=1; continue |
| 133 | + fi |
| 134 | + if [[ $HAVE_MAP -eq 1 ]] && ! verifyPackagesAgainstMap "$asset" "$MAP" "GitHub apothecary $TAG digests"; then |
| 135 | + echo " ! [$module] SHA-256 mismatch: $asset"; rm -f "$asset"; failed=1; continue |
| 136 | + fi |
| 137 | + # replace the lib/<target> folders this package contains, keep the module's other targets |
| 138 | + case "$asset" in |
| 139 | + *.zip) entries=$(unzip -Z1 "$asset") ;; |
| 140 | + *) entries=$(tar -tjf "$asset") ;; |
| 141 | + esac |
| 142 | + for libdir in $(echo "$entries" | awk -F/ 'NF>=4 && $2=="lib" && $3!="" {print $1"/lib/"$3}' | sort -u); do |
| 143 | + rm -rf "$OF_ROOT/libs/$libdir" |
| 144 | + done |
| 145 | + case "$asset" in |
| 146 | + *.zip) unzip -qo "$asset" -d "$OF_ROOT/libs/" ;; |
| 147 | + *) tar -xjf "$asset" -C "$OF_ROOT/libs/" ;; |
| 148 | + esac || { echo " ! [$module] could not unpack $asset"; failed=1; continue; } |
| 149 | + installed+=("$asset") |
| 150 | + done |
| 151 | + if [[ $found_any -eq 0 ]]; then |
| 152 | + echo " ~ [$module] not built for $PLATFORM yet on $TAG — skipped" |
| 153 | + [[ $REQUIRE -eq 1 ]] && failed=1 |
| 154 | + fi |
| 155 | +done |
| 156 | +rm -f "$MAP" |
| 157 | + |
| 158 | +if [[ ${#installed[@]} -gt 0 ]]; then |
| 159 | + echo " openFrameworks modules installed: ${installed[*]}" |
| 160 | +fi |
| 161 | +exit $failed |
0 commit comments