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
44 changes: 22 additions & 22 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
set -eu

# allow overriding the version
VERSION=${CODECRAFTERS_CLI_VERSION:-v44}
VERSION=${CODECRAFTERS_CLI_VERSION:-v45}

PLATFORM=$(uname -s)
ARCH=$(uname -m)

if [ "$PLATFORM" = "Darwin" ]; then
OS=darwin
OS=darwin
elif [ "${PLATFORM%% *}" = "Linux" ]; then
OS=linux
OS=linux
else
echo "This installer is only supported on Linux and MacOS."
exit 1
echo "This installer is only supported on Linux and MacOS."
exit 1
fi

case "$ARCH" in
x86_64)
ARCH=amd64
;;
ARCH=amd64
;;
armv8* | arm64* | aarch64*)
ARCH=arm64
;;
ARCH=arm64
;;
*)
echo "unsupported arch: $ARCH"
exit 1
;;
echo "unsupported arch: $ARCH"
exit 1
;;
esac

INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin}
Expand All @@ -40,21 +40,21 @@ 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."
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
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"
rm -f "$TEMP_FILE"
rm -rf "$TEMP_FOLDER"
}

trap cleanup EXIT
Expand All @@ -63,19 +63,19 @@ 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
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 ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
sudo -k mkdir -p "$INSTALL_DIR"
sudo -k mkdir -p "$INSTALL_DIR"
fi
if ! mv "$TEMP_FOLDER/codecrafters" "$INSTALL_PATH" 2>/dev/null; then
sudo -k mv "$TEMP_FOLDER/codecrafters" "$INSTALL_PATH"
sudo -k mv "$TEMP_FOLDER/codecrafters" "$INSTALL_PATH"
fi

echo "Installed $("$INSTALL_PATH" --version)"
Expand Down