Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions pleasew
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,44 @@ else
RESET=''
fi

OS=""
ARCH=""

case "$(uname)" in
Linux)
OS=linux
case "$(uname -m)" in
x86_64) ARCH=amd64 ;;
aarch64*|armv8b|armv8l) ARCH=arm64 ;;
esac
;;
Darwin)
OS=darwin
case "$(uname -m)" in
x86_64) ARCH=amd64 ;;
arm64) ARCH=arm64 ;;
esac
;;
FreeBSD)
OS=freebsd
case "$(uname -m)" in
amd64) ARCH=amd64 ;;
esac
;;
*)
printf >&2 '%bPlease does not support the %s operating system.%b\n' \
"${RED}" "$(uname)" "${RESET}"
exit 1
;;
esac

DEFAULT_URL_BASE='https://get.please.build'

OS="$(uname)"

if [ "${OS}" = 'Darwin' ]; then
# switch between mac amd64/arm64
ARCH="$(uname -m)"
else
# default to amd64 on other operating systems
# because we only build intel binaries
ARCH='amd64'
if [ -z "$ARCH" ]; then
printf >&2 '%bPlease does not support the %s architecture on %s.%b\n' \
"${RED}" "$(uname -m)" "$(uname)" "${RESET}"
exit 1
fi

case "${ARCH}" in
aarch64_be|aarch64|armv8b|armv8l) ARCH='arm64' ;;
x86_64) ARCH='amd64' ;;
esac
DEFAULT_URL_BASE='https://get.please.build'

has_command () {
command -v "${1}" > /dev/null 2>&1
Expand Down Expand Up @@ -141,20 +161,7 @@ if [ "${VERSION:+x}" != 'x' ]; then
VERSION=$(${TRANSFER_TOOL} ${TRANSFER_SILENT_OPTS} "${URL_BASE}"/latest_version)
fi

# Find the os / arch to download. You can do this quite nicely with go env
# but we use this script on machines that don't necessarily have Go itself.
if [ "${OS}" = 'Linux' ]; then
GOOS='linux'
elif [ "${OS}" = 'Darwin' ]; then
GOOS='darwin'
elif [ "${OS}" = 'FreeBSD' ]; then
GOOS='freebsd'
else
printf >&2 '%bUnknown operating system %s%b\n' "${RED}" "${OS}" "${RESET}"
exit 1
fi

PLEASE_URL="${URL_BASE}/${GOOS}_${ARCH}/${VERSION}/please_${VERSION}.tar.xz"
PLEASE_URL="${URL_BASE}/${OS}_${ARCH}/${VERSION}/please_${VERSION}.tar.xz"
DIR="${LOCATION}/${VERSION}"

# Potentially we could reuse this but it's easier not to really.
Expand All @@ -165,6 +172,10 @@ fi
printf >&2 '%bDownloading Please %s to %s...%b\n' "${GREEN}" "${VERSION}" "${DIR}" "${RESET}"
mkdir -p "${DIR}"
${TRANSFER_TOOL} ${TRANSFER_PROGRESS_OPTS} "${PLEASE_URL}" | tar -xJpf- --strip-components=1 -C "${DIR}"
if [ $? -ne 0 ]; then
printf >&2 '%bFailed to download Please%b\n' "${RED}" "${RESET}"
exit 1
fi

# Link it all back up a dir
for x in "${DIR}"/*; do
Expand Down