-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
80 lines (60 loc) · 1.94 KB
/
install.sh
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
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
set -eu
# allow overriding the version
VERSION=${CODECRAFTERS_CLI_VERSION:-v35}
PLATFORM=$(uname -s)
ARCH=$(uname -m)
if [ "$PLATFORM" = "Darwin" ]; then
OS=darwin
elif [ "${PLATFORM%% *}" = "Linux" ]; then
OS=linux
else
echo "This installer is only supported on Linux and MacOS."
exit 1
fi
case "$ARCH" in
x86_64)
ARCH=amd64
;;
armv8* | arm64* | aarch64*)
ARCH=arm64
;;
*)
echo "unsupported arch: $ARCH"
exit 1
;;
esac
INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin}
INSTALL_PATH=${INSTALL_PATH:-$INSTALL_DIR/codecrafters}
DOWNLOAD_URL="https://github.com/codecrafters-io/cli/releases/download/${VERSION}/${VERSION}_${OS}_${ARCH}.tar.gz"
echo "This script will automatically install codecrafters (${VERSION}) for you."
echo "You will be prompted for your password by sudo if needed."
echo "Installation path: ${INSTALL_PATH}"
if [ "$(id -u)" = "0" ]; then
echo "Warning: this script is currently running as root. This is dangerous. "
echo " Instead run it as normal user. We will sudo as needed."
fi
if ! command -v curl >/dev/null; then
echo "error: you do not have 'curl' installed which is required for this script."
exit 1
fi
TEMP_FILE=$(mktemp "${TMPDIR:-/tmp}/.codecrafterscli.XXXXXXXX")
TEMP_FOLDER=$(mktemp -d "${TMPDIR:-/tmp}/.codecrafterscli-headers.XXXXXXXX")
cleanup() {
rm -f "$TEMP_FILE"
rm -rf "$TEMP_FOLDER"
}
trap cleanup EXIT
echo Downloading CodeCrafters CLI...
HTTP_CODE=$(curl -SL --progress-bar "$DOWNLOAD_URL" --output "$TEMP_FILE" --write-out "%{http_code}")
if [ "$HTTP_CODE" -lt 200 ] || [ "$HTTP_CODE" -gt 299 ]; then
echo "error: your platform and architecture (${PLATFORM}-${ARCH}) is unsupported."
exit 1
fi
tar xzf "$TEMP_FILE" -C "$TEMP_FOLDER" codecrafters
chmod 0755 "$TEMP_FOLDER/codecrafters"
if ! mv "$TEMP_FOLDER/codecrafters" "$INSTALL_PATH" 2>/dev/null; then
sudo -k mv "$TEMP_FOLDER/codecrafters" "$INSTALL_PATH"
fi
echo "Installed $("$INSTALL_PATH" --version)"
echo 'Done!'