Skip to content

Commit

Permalink
feat: installer offer to replace local nodekit binary; windows error …
Browse files Browse the repository at this point in the history
…more information
  • Loading branch information
Tasos Bitsios committed Jan 9, 2025
1 parent 51b8e76 commit b19d685
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Bold_Green=''
Reset=''

if [[ -t 1 ]]; then
Reset='\033[0m'
Red='\033[0;31m'
Green='\033[0;32m'
Yellow='\033[0;33m'
Blue='\033[0;34m'
Bold_Green='\033[1;32m'
Bold_White='\033[1m'
Opaque='\033[0;2m'
Reset='\033[0m'
Red='\033[0;31m'
Green='\033[0;32m'
Yellow='\033[0;33m'
Blue='\033[0;34m'
Bold_Green='\033[1;32m'
Bold_White='\033[1m'
Opaque='\033[0;2m'
fi

success() {
Expand All @@ -39,40 +39,58 @@ warn() {
}

error() {
echo -e "${Red}ERROR${Reset}:" "${Yellow}" "$@" "${Reset}" >&2
exit 1
echo -e "${Red}ERROR${Reset}:" "${Yellow}" "$@" "${Reset}" >&2
exit 1
}

prompt_default_no() {
echo -n "$1 (y/N) "
read -rn1 prompt_response
echo ""
if [[ "$prompt_response" =~ "y" ]]; then
return 0
fi
return 1
}

if [ -f nodekit ]; then
error "An nodekit file already exists in the current directory. Delete or rename it before installing."
warn "A nodekit file already exists in the current directory."
if prompt_default_no "Do you want to upgrade it to the latest nodekit?"; then
rm nodekit
else
info "Not upgrading nodekit.\n\nYou can run nodekit with:\n\n./nodekit\n\nOr start the installer with:\n\n./nodekit bootstrap"
exit 0
fi
fi


if [[ ${OS:-} = Windows_NT ]]; then
error "Unsupported platform"
error "Unsupported platform. Windows is supported only via WSL.\n\nFor WSL installation instructions, see here: https://learn.microsoft.com/en-us/windows/wsl/install"
fi

trap "warn SIGINT received." int
trap "info Exiting the installation" exit

case $os in
'Darwin x86_64')
target=nodekit-amd64-darwin
;;
platform=amd64-darwin
;;
'Darwin arm64')
target=nodekit-arm64-darwin
;;
platform=arm64-darwin
;;
'Linux aarch64' | 'Linux arm64')
target=nodekit-arm64-linux
;;
platform=arm64-linux
;;
'Linux x86_64' | *)
target=nodekit-amd64-linux
;;
platform=amd64-linux
;;
esac

echo -e "${Opaque}Downloading:${Reset}${Bold_White} $target $version${Reset}"
curl --fail --location --progress-bar --output nodekit "$release/$version/$target" ||
error "Failed to download ${target} from ${release}"
target="nodekit-$platform"
url="$release/$target"

echo -e "${Opaque}Downloading:${Reset}${Bold_White} $target ${Reset}from $url"
curl --fail --location --progress-bar --output nodekit "$url" ||
error "Failed to download ${target} from ${release} ${url}"

chmod +x nodekit

Expand Down

0 comments on commit b19d685

Please sign in to comment.