github.com/tcncloud/wollemi@v0.8.1/pleasew (about)

     1  #!/usr/bin/env bash
     2  set -u
     3  
     4  RED="\x1B[31m"
     5  GREEN="\x1B[32m"
     6  YELLOW="\x1B[33m"
     7  RESET="\x1B[0m"
     8  
     9  DEFAULT_URL_BASE="https://get.please.build"
    10  # We might already have it downloaded...
    11  LOCATION=`grep -i "^location" .plzconfig | cut -d '=' -f 2 | tr -d ' '`
    12  if [ -z "$LOCATION" ]; then
    13      if [ -z "$HOME" ]; then
    14  	    echo -e "${RED}\$HOME not set, not sure where to look for Please.${RESET}"
    15  	    exit 1
    16      fi
    17      LOCATION="${HOME}/.please"
    18  fi
    19  # If this exists at any version, let it handle any update.
    20  TARGET="${LOCATION}/please"
    21  if [ -f "$TARGET" ]; then
    22      exec "$TARGET" $@
    23  fi
    24  
    25  URL_BASE="`grep -i "^downloadlocation" .plzconfig | cut -d '=' -f 2 | tr -d ' '`"
    26  if [ -z "$URL_BASE" ]; then
    27      URL_BASE=$DEFAULT_URL_BASE
    28  fi
    29  URL_BASE="${URL_BASE%/}"
    30  
    31  VERSION="`grep -i "^version[^a-z]" .plzconfig`"
    32  VERSION="${VERSION#*=}"    # Strip until after first =
    33  VERSION="${VERSION/ /}"    # Remove all spaces
    34  VERSION="${VERSION#>=}"    # Strip any initial >=
    35  if [ -z "$VERSION" ]; then
    36      echo -e "${YELLOW}Can't determine version, will use latest.${RESET}"
    37      VERSION=`curl -fsSL ${URL_BASE}/latest_version`
    38  fi
    39  
    40  # Find the os / arch to download. You can do this quite nicely with go env
    41  # but we use this script on machines that don't necessarily have Go itself.
    42  OS=`uname`
    43  if [ "$OS" = "Linux" ]; then
    44      GOOS="linux"
    45  elif [ "$OS" = "Darwin" ]; then
    46      GOOS="darwin"
    47  else
    48      echo -e "${RED}Unknown operating system $OS${RESET}"
    49      exit 1
    50  fi
    51  # Don't have any builds other than amd64 at the moment.
    52  ARCH="amd64"
    53  
    54  PLEASE_URL="${URL_BASE}/${GOOS}_${ARCH}/${VERSION}/please_${VERSION}.tar.xz"
    55  DIR="${LOCATION}/${VERSION}"
    56  # Potentially we could reuse this but it's easier not to really.
    57  if [ ! -d "$DIR" ]; then
    58      rm -rf "$DIR"
    59  fi
    60  echo -e "${GREEN}Downloading Please ${VERSION} to ${DIR}...${RESET}"
    61  mkdir -p "$DIR"
    62  curl -fsSL "${PLEASE_URL}" | tar -xJpf- --strip-components=1 -C "$DIR"
    63  # Link it all back up a dir
    64  for x in `ls "$DIR"`; do
    65      ln -sf "${DIR}/${x}" "$LOCATION"
    66  done
    67  ln -sf "${DIR}/please" "${LOCATION}/plz"
    68  echo -e "${GREEN}Should be good to go now, running plz...${RESET}"
    69  exec "$TARGET" $@