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