|
| 1 | +@echo off |
| 2 | +setlocal enabledelayedexpansion |
| 3 | + |
| 4 | +:: JuliaHub CLI (jh) installer script for Windows |
| 5 | +:: This script downloads and installs the latest release of jh from GitHub |
| 6 | + |
| 7 | +:: Configuration |
| 8 | +set REPO_OWNER=JuliaComputing |
| 9 | +set REPO_NAME=jh |
| 10 | +set BINARY_NAME=jh |
| 11 | +if "%INSTALL_DIR%"=="" set INSTALL_DIR=%USERPROFILE%\.local\bin |
| 12 | + |
| 13 | +:: Create install directory if it doesn't exist |
| 14 | +if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%" |
| 15 | + |
| 16 | +echo JuliaHub CLI (%BINARY_NAME%) Installer for Windows |
| 17 | +echo ================================================ |
| 18 | + |
| 19 | +:: Check if curl is available (Windows 10 1803+ has curl built-in) |
| 20 | +curl --version >nul 2>&1 |
| 21 | +if %errorlevel% neq 0 ( |
| 22 | + echo ERROR: curl is required but not found. Please install curl or use PowerShell. |
| 23 | + echo You can install curl from: https://curl.se/download.html |
| 24 | + echo Or use the PowerShell install script instead. |
| 25 | + exit /b 1 |
| 26 | +) |
| 27 | + |
| 28 | +echo INFO: Fetching latest release information... |
| 29 | + |
| 30 | +:: Get latest version from GitHub API |
| 31 | +for /f "tokens=*" %%i in ('curl -s "https://api.github.com/repos/%REPO_OWNER%/%REPO_NAME%/releases/latest" ^| findstr "tag_name" ^| for /f "tokens=2 delims=:," %%j in ('findstr "tag_name"') do @echo %%~j') do set VERSION=%%i |
| 32 | +set VERSION=%VERSION:"=% |
| 33 | +set VERSION=%VERSION: =% |
| 34 | + |
| 35 | +if "%VERSION%"=="" ( |
| 36 | + echo ERROR: Failed to get latest version information |
| 37 | + exit /b 1 |
| 38 | +) |
| 39 | + |
| 40 | +echo INFO: Latest version: %VERSION% |
| 41 | + |
| 42 | +:: Detect architecture |
| 43 | +set ARCH=amd64 |
| 44 | +if "%PROCESSOR_ARCHITECTURE%"=="ARM64" set ARCH=arm64 |
| 45 | + |
| 46 | +:: Construct download URL and filenames |
| 47 | +set BINARY_FILE=%BINARY_NAME%-windows-%ARCH%.exe |
| 48 | +set DOWNLOAD_URL=https://github.com/%REPO_OWNER%/%REPO_NAME%/releases/download/%VERSION%/%BINARY_FILE% |
| 49 | +set TEMP_FILE=%INSTALL_DIR%\%BINARY_FILE%.tmp |
| 50 | +set FINAL_FILE=%INSTALL_DIR%\%BINARY_NAME%.exe |
| 51 | + |
| 52 | +echo INFO: Downloading %BINARY_NAME% %VERSION% for windows-%ARCH%... |
| 53 | +echo INFO: Download URL: %DOWNLOAD_URL% |
| 54 | + |
| 55 | +:: Check if binary already exists |
| 56 | +if exist "%FINAL_FILE%" ( |
| 57 | + echo INFO: Checking current installation... |
| 58 | + for /f "tokens=*" %%i in ('"%FINAL_FILE%" --version 2^>nul') do set CURRENT_VERSION=%%i |
| 59 | + if not "%CURRENT_VERSION%"=="" ( |
| 60 | + echo INFO: Current installation: !CURRENT_VERSION! |
| 61 | + echo !CURRENT_VERSION! | findstr "%VERSION%" >nul |
| 62 | + if !errorlevel! equ 0 ( |
| 63 | + echo INFO: Latest version is already installed |
| 64 | + exit /b 0 |
| 65 | + ) |
| 66 | + ) |
| 67 | + echo WARNING: Existing installation found. It will be replaced. |
| 68 | +) |
| 69 | + |
| 70 | +:: Download binary |
| 71 | +curl -L -o "%TEMP_FILE%" "%DOWNLOAD_URL%" |
| 72 | +if %errorlevel% neq 0 ( |
| 73 | + echo ERROR: Failed to download binary from %DOWNLOAD_URL% |
| 74 | + if exist "%TEMP_FILE%" del "%TEMP_FILE%" |
| 75 | + exit /b 1 |
| 76 | +) |
| 77 | + |
| 78 | +:: Verify download was successful |
| 79 | +if not exist "%TEMP_FILE%" ( |
| 80 | + echo ERROR: Downloaded file not found |
| 81 | + exit /b 1 |
| 82 | +) |
| 83 | + |
| 84 | +:: Move to final location |
| 85 | +move "%TEMP_FILE%" "%FINAL_FILE%" >nul |
| 86 | +if %errorlevel% neq 0 ( |
| 87 | + echo ERROR: Failed to install binary to %FINAL_FILE% |
| 88 | + exit /b 1 |
| 89 | +) |
| 90 | + |
| 91 | +echo SUCCESS: Installed %BINARY_NAME% to %FINAL_FILE% |
| 92 | + |
| 93 | +:: Check if install directory is in PATH |
| 94 | +echo %PATH% | findstr /C:"%INSTALL_DIR%" >nul |
| 95 | +if %errorlevel% neq 0 ( |
| 96 | + echo WARNING: %INSTALL_DIR% is not in your PATH. |
| 97 | + echo To add it permanently, run: |
| 98 | + echo setx PATH "%%PATH%%;%INSTALL_DIR%" |
| 99 | + echo Or add it to your current session: |
| 100 | + echo set PATH=%%PATH%%;%INSTALL_DIR% |
| 101 | + echo. |
| 102 | +) |
| 103 | + |
| 104 | +:: Verify installation |
| 105 | +if exist "%FINAL_FILE%" ( |
| 106 | + echo INFO: Verifying installation... |
| 107 | + for /f "tokens=*" %%i in ('"%FINAL_FILE%" --version 2^>nul') do set VERSION_OUTPUT=%%i |
| 108 | + if not "!VERSION_OUTPUT!"=="" ( |
| 109 | + echo SUCCESS: Installation verified: !VERSION_OUTPUT! |
| 110 | + echo INFO: Run '%BINARY_NAME% --help' to get started |
| 111 | + ) else ( |
| 112 | + echo WARNING: Binary installed but version check failed |
| 113 | + ) |
| 114 | +) else ( |
| 115 | + echo ERROR: Installation failed: binary not found |
| 116 | + exit /b 1 |
| 117 | +) |
| 118 | + |
| 119 | +echo. |
| 120 | +echo SUCCESS: Installation complete! |
| 121 | +echo INFO: You can now use '%BINARY_NAME%' to interact with JuliaHub |
| 122 | +echo INFO: Start with: %BINARY_NAME% auth login |
| 123 | + |
| 124 | +endlocal |
0 commit comments