|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | +VER=master |
| 4 | +PLATFORM="" |
| 5 | +ARCH="" |
| 6 | +OVERWRITE=1 |
| 7 | +SILENT_ARGS="" |
| 8 | +BLEEDING_EDGE=0 |
| 9 | + |
| 10 | +printHelp(){ |
| 11 | +cat << EOF |
| 12 | + Usage: download_pg.sh [OPTIONS] |
| 13 | +
|
| 14 | + Options: |
| 15 | +
|
| 16 | + -v, --version VERSION OF version to download the libraries for. Defaults to master |
| 17 | + -p, --platform PLATFORM Platorm among: android, emscritpen, ios, linux, linux64, linuxarmv6l, linuxarmv7l, msys2, osx, tvos, vs |
| 18 | + If not specified tries to autodetect the platform |
| 19 | + -s, --silent Silent download progress |
| 20 | + -h, --help Shows this message |
| 21 | +EOF |
| 22 | +} |
| 23 | + |
| 24 | +SCRIPT_DIR="${BASH_SOURCE%/*}" |
| 25 | +if [[ ! -d "$SCRIPT_DIR" ]]; then SCRIPT_DIR="$PWD"; fi |
| 26 | +. "$SCRIPT_DIR/downloader.sh" |
| 27 | + |
| 28 | +download(){ |
| 29 | + echo "Downloading $1" |
| 30 | + |
| 31 | + if [[ $BLEEDING_EDGE = 1 ]] ; then |
| 32 | + echo downloader https://github.com/openframeworks/projectGenerator/releases/download/bleeding/$1 $SILENT_ARGS |
| 33 | + downloader https://github.com/openframeworks/projectGenerator/releases/download/bleeding/$1 $SILENT_ARGS |
| 34 | + else |
| 35 | + echo downloader https://github.com/openframeworks/projectGenerator/releases/download/nightly/$1 |
| 36 | + downloader https://github.com/openframeworks/projectGenerator/releases/download/nightly/$1 |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +# trap any script errors and exit |
| 41 | +trap 'trapError ${LINENO}' ERR |
| 42 | +trap "trapError" SIGINT SIGTERM |
| 43 | + |
| 44 | +trapError() { |
| 45 | + local parent_lineno="$1" |
| 46 | + if [[ "$#" = "3" ]] ; then |
| 47 | + local message="$2" |
| 48 | + local code="${3:-1}" |
| 49 | + echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}" |
| 50 | + else |
| 51 | + local code="${2:-1}" |
| 52 | + echo "Error on or near line ${parent_lineno}; exiting with status ${code}" |
| 53 | + fi |
| 54 | + |
| 55 | + if [ -e openFrameworksLibs* ]; then |
| 56 | + echo "removing packages" |
| 57 | + rm openFrameworksLibs* |
| 58 | + fi |
| 59 | + exit "${code}" |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +while [[ $# -gt 0 ]]; do |
| 64 | + key="$1" |
| 65 | + case $key in |
| 66 | + -v|--version) |
| 67 | + VER="$2" |
| 68 | + shift # past argument |
| 69 | + ;; |
| 70 | + -p|--platform) |
| 71 | + PLATFORM="$2" |
| 72 | + shift # past argument |
| 73 | + ;; |
| 74 | + -a|--arch) |
| 75 | + ARCH="$2" |
| 76 | + shift # past argument |
| 77 | + ;; |
| 78 | + -n|--no-overwrite) |
| 79 | + OVERWRITE=0 |
| 80 | + ;; |
| 81 | + -b|--bleeding-edge) |
| 82 | + BLEEDING_EDGE=1 |
| 83 | + ;; |
| 84 | + -s|--silent) |
| 85 | + SILENT_ARGS=-nv |
| 86 | + ;; |
| 87 | + -h|--help) |
| 88 | + printHelp |
| 89 | + exit 0 |
| 90 | + ;; |
| 91 | + *) |
| 92 | + echo "Error: invalid argument: $key" |
| 93 | + printHelp |
| 94 | + exit 1 |
| 95 | + ;; |
| 96 | + esac |
| 97 | + shift # past argument or value |
| 98 | +done |
| 99 | + |
| 100 | +if [ "$PLATFORM" == "" ]; then |
| 101 | + OS=$(uname) |
| 102 | + if [ "$OS" == "Linux" ]; then |
| 103 | + PLATFORM="linux" |
| 104 | + elif [ "$OS" == "Darwin" ]; then |
| 105 | + PLATFORM="osx" |
| 106 | + elif [ "${OS:0:5}" == "MINGW" ]; then |
| 107 | + PLATFORM="msys2" |
| 108 | + else |
| 109 | + # otherwise we are on windows and will download vs |
| 110 | + PLATFORM="vs" |
| 111 | + fi |
| 112 | +fi |
| 113 | + |
| 114 | +if [ "$ARCH" == "" ]; then |
| 115 | + if [ "$PLATFORM" == "linux" ]; then |
| 116 | + ARCH=$(uname -m) |
| 117 | + if [ "$ARCH" == "x86_64" ]; then |
| 118 | + GCC_VERSION=$(gcc -dumpversion | cut -f1 -d.) |
| 119 | + if [ $GCC_VERSION -eq 4 ]; then |
| 120 | + ARCH=64gcc6 |
| 121 | + elif [ $GCC_VERSION -eq 5 ]; then |
| 122 | + ARCH=64gcc6 |
| 123 | + else |
| 124 | + ARCH=64gcc6 |
| 125 | + fi |
| 126 | + elif [ "$ARCH" == "armv7l" ]; then |
| 127 | + # Check for Raspberry Pi |
| 128 | + if [ -f /opt/vc/include/bcm_host.h ]; then |
| 129 | + ARCH=armv6l |
| 130 | + fi |
| 131 | + elif [ "$ARCH" == "i686" ] || [ "$ARCH" == "i386" ]; then |
| 132 | + cat << EOF |
| 133 | +32bit linux is not officially supported anymore but compiling |
| 134 | +the libraries using the build script in apothecary/scripts |
| 135 | +should compile all the dependencies without problem |
| 136 | +EOF |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | + elif [ "$PLATFORM" == "msys2" ]; then |
| 140 | + if [ "$MSYSTEM" == "MINGW64" ]; then |
| 141 | + ARCH=mingw64 |
| 142 | + elif [ "$MSYSTEM" == "MINGW32" ]; then |
| 143 | + ARCH=mingw32 |
| 144 | + elif [ "$MSYSTEM" == "UCRT64" ]; then |
| 145 | + ARCH=ucrt64 |
| 146 | + elif [ "$MSYSTEM" == "CLANG64" ]; then |
| 147 | + ARCH=clang64 |
| 148 | + fi |
| 149 | + fi |
| 150 | + |
| 151 | + if [ "$PLATFORM" == "osx" ]; then |
| 152 | + ARCH=x86_64 |
| 153 | + fi |
| 154 | +fi |
| 155 | + |
| 156 | + |
| 157 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 158 | +cd "$SCRIPT_DIR" |
| 159 | + |
| 160 | +OUTDIR=../../ |
| 161 | + |
| 162 | + |
| 163 | +if [[ $BLEEDING_EDGE = 1 ]] ; then |
| 164 | + VER=bleeding |
| 165 | +fi |
| 166 | + |
| 167 | +if [ "$PLATFORM" == "vs" ]; then |
| 168 | + EXT=".exe" |
| 169 | +else |
| 170 | + EXT=".app" |
| 171 | +fi |
| 172 | +OUTPUT=projectGenerator-$PLATFORM |
| 173 | +if [ "$PLATFORM" == "msys2" ] || [ "$PLATFORM" == "vs" ]; then |
| 174 | + GUI="-gui" |
| 175 | +else |
| 176 | + GUI="" |
| 177 | +fi |
| 178 | +PKG="projectGenerator-${PLATFORM}${GUI}.zip" |
| 179 | +download $PKG |
| 180 | + |
| 181 | +echo "Uncompressing Project Generator for $PLATFORM from $PKG" |
| 182 | +if [ "$PLATFORM" == "msys2" ] || [ "$PLATFORM" == "vs" ]; then |
| 183 | + unzip -q "$PKG" -d "$OUTPUT" |
| 184 | + rm $PKG |
| 185 | +else |
| 186 | + tar xjf "$PKG" |
| 187 | + rm $PKG |
| 188 | +fi |
| 189 | + |
| 190 | +if [ -d "${OUTDIR}/${OUTPUT}" ] || [ -f "${OUTDIR}/${OUTPUT}" ]; then |
| 191 | + rm -rf "${OUTDIR}/${OUTPUT}" |
| 192 | +fi |
| 193 | + |
| 194 | +if [ "$PLATFORM" == "msys2" ] || [ "$PLATFORM" == "vs" ]; then |
| 195 | + |
| 196 | + if ! command -v rsync &> /dev/null |
| 197 | + then |
| 198 | + cp -ar ${OUTPUT}/ ${OUTDIR}/${OUTPUT} |
| 199 | + else |
| 200 | + rsync -a ${OUTPUT}/ ${OUTDIR}/${OUTPUT} |
| 201 | + fi |
| 202 | + rm -rf $OUTPUT |
| 203 | +else |
| 204 | + if ! command -v rsync &> /dev/null |
| 205 | + then |
| 206 | + cp -ar $OUTPUT/projectGenerator$EXT $OUTDIR/ |
| 207 | + else |
| 208 | + rsync -a $OUTPUT/projectGenerator$EXT $OUTDIR |
| 209 | + fi |
| 210 | + rm -rf $OUTPUT/projectGenerator$EXT |
| 211 | + |
| 212 | +fi |
| 213 | + |
| 214 | +rm -rf $OUTPUT |
| 215 | +rm -rf $PKG |
| 216 | + |
| 217 | +echo "Completed projectGenerator in place" |
| 218 | + |
| 219 | + |
| 220 | + |
0 commit comments