diff --git a/install.sh b/install.sh index a630e2f7..e7f38e14 100755 --- a/install.sh +++ b/install.sh @@ -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() { @@ -39,17 +39,32 @@ 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 @@ -57,22 +72,25 @@ 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