|
| 1 | +#!/bin/sh |
| 2 | +set -eu |
| 3 | + |
| 4 | +#region logging setup |
| 5 | +if [ "${MISE_DEBUG-}" = "true" ] || [ "${MISE_DEBUG-}" = "1" ]; then |
| 6 | + debug() { |
| 7 | + echo "$@" >&2 |
| 8 | + } |
| 9 | +else |
| 10 | + debug() { |
| 11 | + : |
| 12 | + } |
| 13 | +fi |
| 14 | + |
| 15 | +if [ "${MISE_QUIET-}" = "1" ] || [ "${MISE_QUIET-}" = "true" ]; then |
| 16 | + info() { |
| 17 | + : |
| 18 | + } |
| 19 | +else |
| 20 | + info() { |
| 21 | + echo "$@" >&2 |
| 22 | + } |
| 23 | +fi |
| 24 | + |
| 25 | +error() { |
| 26 | + echo "$@" >&2 |
| 27 | + exit 1 |
| 28 | +} |
| 29 | +#endregion |
| 30 | + |
| 31 | +#region environment setup |
| 32 | +get_os() { |
| 33 | + os="$(uname -s)" |
| 34 | + if [ "$os" = Darwin ]; then |
| 35 | + echo "macos" |
| 36 | + elif [ "$os" = Linux ]; then |
| 37 | + echo "linux" |
| 38 | + else |
| 39 | + error "unsupported OS: $os" |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +get_arch() { |
| 44 | + musl="" |
| 45 | + if type ldd >/dev/null 2>/dev/null; then |
| 46 | + if [ "${MISE_INSTALL_MUSL-}" = "1" ] || [ "${MISE_INSTALL_MUSL-}" = "true" ]; then |
| 47 | + musl="-musl" |
| 48 | + elif [ "$(uname -o)" = "Android" ]; then |
| 49 | + # Android (Termux) always uses musl |
| 50 | + musl="-musl" |
| 51 | + else |
| 52 | + libc=$(ldd /bin/ls | grep 'musl' | head -1 | cut -d ' ' -f1) |
| 53 | + if [ -n "$libc" ]; then |
| 54 | + musl="-musl" |
| 55 | + fi |
| 56 | + fi |
| 57 | + fi |
| 58 | + arch="$(uname -m)" |
| 59 | + if [ "$arch" = x86_64 ]; then |
| 60 | + echo "x64$musl" |
| 61 | + elif [ "$arch" = aarch64 ] || [ "$arch" = arm64 ]; then |
| 62 | + echo "arm64$musl" |
| 63 | + elif [ "$arch" = armv7l ]; then |
| 64 | + echo "armv7$musl" |
| 65 | + else |
| 66 | + error "unsupported architecture: $arch" |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +get_ext() { |
| 71 | + if [ -n "${MISE_INSTALL_EXT:-}" ]; then |
| 72 | + echo "$MISE_INSTALL_EXT" |
| 73 | + elif [ -n "${MISE_VERSION:-}" ] && echo "$MISE_VERSION" | grep -q '^v2024'; then |
| 74 | + # 2024 versions don't have zstd tarballs |
| 75 | + echo "tar.gz" |
| 76 | + elif tar_supports_zstd; then |
| 77 | + echo "tar.zst" |
| 78 | + elif command -v zstd >/dev/null 2>&1; then |
| 79 | + echo "tar.zst" |
| 80 | + else |
| 81 | + echo "tar.gz" |
| 82 | + fi |
| 83 | +} |
| 84 | + |
| 85 | +tar_supports_zstd() { |
| 86 | + # tar is bsdtar or version is >= 1.31 |
| 87 | + if tar --version | grep -q 'bsdtar' && command -v zstd >/dev/null 2>&1; then |
| 88 | + true |
| 89 | + elif tar --version | grep -q '1\.(3[1-9]|[4-9][0-9]'; then |
| 90 | + true |
| 91 | + else |
| 92 | + false |
| 93 | + fi |
| 94 | +} |
| 95 | + |
| 96 | +shasum_bin() { |
| 97 | + if command -v shasum >/dev/null 2>&1; then |
| 98 | + echo "shasum" |
| 99 | + elif command -v sha256sum >/dev/null 2>&1; then |
| 100 | + echo "sha256sum" |
| 101 | + else |
| 102 | + error "mise install requires shasum or sha256sum but neither is installed. Aborting." |
| 103 | + fi |
| 104 | +} |
| 105 | + |
| 106 | +get_checksum() { |
| 107 | + version=$1 |
| 108 | + os=$2 |
| 109 | + arch=$3 |
| 110 | + ext=$4 |
| 111 | + url="https://github.com/jdx/mise/releases/download/v${version}/SHASUMS256.txt" |
| 112 | + |
| 113 | + # For current version use static checksum otherwise |
| 114 | + # use checksum from releases |
| 115 | + if [ "$version" = "v2026.2.19" ]; then |
| 116 | + checksum_linux_x86_64="a52b57e2694d3c22abe0f1ecc5e5b8b00aded34b7b4f570c8d1eb0737167656a ./mise-v2026.2.19-linux-x64.tar.gz" |
| 117 | + checksum_linux_x86_64_musl="72e95fefc55e4d665543d13e76175853c2ef87365ecdd7b00ca99683de1c252a ./mise-v2026.2.19-linux-x64-musl.tar.gz" |
| 118 | + checksum_linux_arm64="6fbab4e5aed4975144b000ae8a509404ef0a9304ccec3d2411465fbc98215441 ./mise-v2026.2.19-linux-arm64.tar.gz" |
| 119 | + checksum_linux_arm64_musl="74bd261911f1fd094053fa64fc0b41e7bc7b29b03ca75c82d742c0b22f0a90d8 ./mise-v2026.2.19-linux-arm64-musl.tar.gz" |
| 120 | + checksum_linux_armv7="ce2c00807c9edad790ee5a0ccfc4b6abf1b2191fe6b72bff3d43ef8b950042a7 ./mise-v2026.2.19-linux-armv7.tar.gz" |
| 121 | + checksum_linux_armv7_musl="a919054c71db13f35b104f34c2835d6e18984f9284c5cdc4249e5e6c52c42990 ./mise-v2026.2.19-linux-armv7-musl.tar.gz" |
| 122 | + checksum_macos_x86_64="a378879003ba0e0667b8bc39c02c90adc926f5211ccfae17bc755b3768842f50 ./mise-v2026.2.19-macos-x64.tar.gz" |
| 123 | + checksum_macos_arm64="dd4370e96dea209d7c091f8bba7239233bcbc8889b94263a0ea7d6adab23826d ./mise-v2026.2.19-macos-arm64.tar.gz" |
| 124 | + checksum_linux_x86_64_zstd="8de4b319d532b81d0d4bb1726a8416d7476db6d149423b440fa385858b2c3c3a ./mise-v2026.2.19-linux-x64.tar.zst" |
| 125 | + checksum_linux_x86_64_musl_zstd="e2b36e184291e7df09a59c3e603ccbb3595fbe68aec8528b707770835817811b ./mise-v2026.2.19-linux-x64-musl.tar.zst" |
| 126 | + checksum_linux_arm64_zstd="0951f589e658ab243bab37d76d7839d255d61f17e9bdcd43a16a0fe2e0cfd8fe ./mise-v2026.2.19-linux-arm64.tar.zst" |
| 127 | + checksum_linux_arm64_musl_zstd="36d58f2836815f6e931afe522b60921989abfd6bf78cf6645c995036fa0f1f4d ./mise-v2026.2.19-linux-arm64-musl.tar.zst" |
| 128 | + checksum_linux_armv7_zstd="f729eff0d95bfa01f6f8828f17e0d9c084cf9c16b27304cbb1357003f3fb589d ./mise-v2026.2.19-linux-armv7.tar.zst" |
| 129 | + checksum_linux_armv7_musl_zstd="7cff38b2a32a98af1daf5d264d5170555365e6466522f4ff83e02bca6833f79a ./mise-v2026.2.19-linux-armv7-musl.tar.zst" |
| 130 | + checksum_macos_x86_64_zstd="a8cf9a993eee2cc6ef5eb398e628fb9a757f3bb9129f4d852aded94dcd1d0f7d ./mise-v2026.2.19-macos-x64.tar.zst" |
| 131 | + checksum_macos_arm64_zstd="1f38d5ab0c89ddb4f090738070519a00a308ad7c385eb1d019f684d1465acbc4 ./mise-v2026.2.19-macos-arm64.tar.zst" |
| 132 | + |
| 133 | + # TODO: refactor this, it's a bit messy |
| 134 | + if [ "$ext" = "tar.zst" ]; then |
| 135 | + if [ "$os" = "linux" ]; then |
| 136 | + if [ "$arch" = "x64" ]; then |
| 137 | + echo "$checksum_linux_x86_64_zstd" |
| 138 | + elif [ "$arch" = "x64-musl" ]; then |
| 139 | + echo "$checksum_linux_x86_64_musl_zstd" |
| 140 | + elif [ "$arch" = "arm64" ]; then |
| 141 | + echo "$checksum_linux_arm64_zstd" |
| 142 | + elif [ "$arch" = "arm64-musl" ]; then |
| 143 | + echo "$checksum_linux_arm64_musl_zstd" |
| 144 | + elif [ "$arch" = "armv7" ]; then |
| 145 | + echo "$checksum_linux_armv7_zstd" |
| 146 | + elif [ "$arch" = "armv7-musl" ]; then |
| 147 | + echo "$checksum_linux_armv7_musl_zstd" |
| 148 | + else |
| 149 | + warn "no checksum for $os-$arch" |
| 150 | + fi |
| 151 | + elif [ "$os" = "macos" ]; then |
| 152 | + if [ "$arch" = "x64" ]; then |
| 153 | + echo "$checksum_macos_x86_64_zstd" |
| 154 | + elif [ "$arch" = "arm64" ]; then |
| 155 | + echo "$checksum_macos_arm64_zstd" |
| 156 | + else |
| 157 | + warn "no checksum for $os-$arch" |
| 158 | + fi |
| 159 | + else |
| 160 | + warn "no checksum for $os-$arch" |
| 161 | + fi |
| 162 | + else |
| 163 | + if [ "$os" = "linux" ]; then |
| 164 | + if [ "$arch" = "x64" ]; then |
| 165 | + echo "$checksum_linux_x86_64" |
| 166 | + elif [ "$arch" = "x64-musl" ]; then |
| 167 | + echo "$checksum_linux_x86_64_musl" |
| 168 | + elif [ "$arch" = "arm64" ]; then |
| 169 | + echo "$checksum_linux_arm64" |
| 170 | + elif [ "$arch" = "arm64-musl" ]; then |
| 171 | + echo "$checksum_linux_arm64_musl" |
| 172 | + elif [ "$arch" = "armv7" ]; then |
| 173 | + echo "$checksum_linux_armv7" |
| 174 | + elif [ "$arch" = "armv7-musl" ]; then |
| 175 | + echo "$checksum_linux_armv7_musl" |
| 176 | + else |
| 177 | + warn "no checksum for $os-$arch" |
| 178 | + fi |
| 179 | + elif [ "$os" = "macos" ]; then |
| 180 | + if [ "$arch" = "x64" ]; then |
| 181 | + echo "$checksum_macos_x86_64" |
| 182 | + elif [ "$arch" = "arm64" ]; then |
| 183 | + echo "$checksum_macos_arm64" |
| 184 | + else |
| 185 | + warn "no checksum for $os-$arch" |
| 186 | + fi |
| 187 | + else |
| 188 | + warn "no checksum for $os-$arch" |
| 189 | + fi |
| 190 | + fi |
| 191 | + else |
| 192 | + if command -v curl >/dev/null 2>&1; then |
| 193 | + debug ">" curl -fsSL "$url" |
| 194 | + checksums="$(curl --compressed -fsSL "$url")" |
| 195 | + else |
| 196 | + if command -v wget >/dev/null 2>&1; then |
| 197 | + debug ">" wget -qO - "$url" |
| 198 | + checksums="$(wget -qO - "$url")" |
| 199 | + else |
| 200 | + error "mise standalone install specific version requires curl or wget but neither is installed. Aborting." |
| 201 | + fi |
| 202 | + fi |
| 203 | + # TODO: verify with minisign or gpg if available |
| 204 | + |
| 205 | + checksum="$(echo "$checksums" | grep "$os-$arch.$ext")" |
| 206 | + if ! echo "$checksum" | grep -Eq "^([0-9a-f]{32}|[0-9a-f]{64})"; then |
| 207 | + warn "no checksum for mise $version and $os-$arch" |
| 208 | + else |
| 209 | + echo "$checksum" |
| 210 | + fi |
| 211 | + fi |
| 212 | +} |
| 213 | + |
| 214 | +#endregion |
| 215 | + |
| 216 | +download_file() { |
| 217 | + url="$1" |
| 218 | + download_dir="$2" |
| 219 | + filename="$(basename "$url")" |
| 220 | + file="$download_dir/$filename" |
| 221 | + |
| 222 | + info "mise: installing mise..." |
| 223 | + |
| 224 | + if command -v curl >/dev/null 2>&1; then |
| 225 | + debug ">" curl -#fLo "$file" "$url" |
| 226 | + curl -#fLo "$file" "$url" |
| 227 | + else |
| 228 | + if command -v wget >/dev/null 2>&1; then |
| 229 | + debug ">" wget -qO "$file" "$url" |
| 230 | + stderr=$(mktemp) |
| 231 | + wget -O "$file" "$url" >"$stderr" 2>&1 || error "wget failed: $(cat "$stderr")" |
| 232 | + rm "$stderr" |
| 233 | + else |
| 234 | + error "mise standalone install requires curl or wget but neither is installed. Aborting." |
| 235 | + fi |
| 236 | + fi |
| 237 | + |
| 238 | + echo "$file" |
| 239 | +} |
| 240 | + |
| 241 | +install_mise() { |
| 242 | + version="${MISE_VERSION:-v2026.2.19}" |
| 243 | + version="${version#v}" |
| 244 | + os="${MISE_INSTALL_OS:-$(get_os)}" |
| 245 | + arch="${MISE_INSTALL_ARCH:-$(get_arch)}" |
| 246 | + ext="${MISE_INSTALL_EXT:-$(get_ext)}" |
| 247 | + install_path="${MISE_INSTALL_PATH:-$HOME/.local/bin/mise}" |
| 248 | + install_dir="$(dirname "$install_path")" |
| 249 | + install_from_github="${MISE_INSTALL_FROM_GITHUB:-}" |
| 250 | + if [ "$version" != "v2026.2.19" ] || [ "$install_from_github" = "1" ] || [ "$install_from_github" = "true" ]; then |
| 251 | + tarball_url="https://github.com/jdx/mise/releases/download/v${version}/mise-v${version}-${os}-${arch}.${ext}" |
| 252 | + elif [ -n "${MISE_TARBALL_URL-}" ]; then |
| 253 | + tarball_url="$MISE_TARBALL_URL" |
| 254 | + else |
| 255 | + tarball_url="https://mise.jdx.dev/v${version}/mise-v${version}-${os}-${arch}.${ext}" |
| 256 | + fi |
| 257 | + |
| 258 | + download_dir="$(mktemp -d)" |
| 259 | + cache_file=$(download_file "$tarball_url" "$download_dir") |
| 260 | + debug "mise-setup: tarball=$cache_file" |
| 261 | + |
| 262 | + debug "validating checksum" |
| 263 | + cd "$(dirname "$cache_file")" && get_checksum "$version" "$os" "$arch" "$ext" | "$(shasum_bin)" -c >/dev/null |
| 264 | + |
| 265 | + # extract tarball |
| 266 | + mkdir -p "$install_dir" |
| 267 | + rm -rf "$install_path" |
| 268 | + extract_dir="$(mktemp -d)" |
| 269 | + cd "$extract_dir" |
| 270 | + if [ "$ext" = "tar.zst" ] && ! tar_supports_zstd; then |
| 271 | + zstd -d -c "$cache_file" | tar -xf - |
| 272 | + else |
| 273 | + tar -xf "$cache_file" |
| 274 | + fi |
| 275 | + mv mise/bin/mise "$install_path" |
| 276 | + |
| 277 | + # cleanup |
| 278 | + cd / # Move out of $extract_dir before removing it |
| 279 | + rm -rf "$download_dir" |
| 280 | + rm -rf "$extract_dir" |
| 281 | + |
| 282 | + info "mise: installed successfully to $install_path" |
| 283 | +} |
| 284 | + |
| 285 | +after_finish_help() { |
| 286 | + case "${SHELL:-}" in |
| 287 | + */zsh) |
| 288 | + info "mise: run the following to activate mise in your shell:" |
| 289 | + info "echo \"eval \\\"\\\$($install_path activate zsh)\\\"\" >> \"${ZDOTDIR-$HOME}/.zshrc\"" |
| 290 | + info "" |
| 291 | + info "mise: run \`mise doctor\` to verify this is set up correctly" |
| 292 | + ;; |
| 293 | + */bash) |
| 294 | + info "mise: run the following to activate mise in your shell:" |
| 295 | + info "echo \"eval \\\"\\\$($install_path activate bash)\\\"\" >> ~/.bashrc" |
| 296 | + info "" |
| 297 | + info "mise: run \`mise doctor\` to verify this is set up correctly" |
| 298 | + ;; |
| 299 | + */fish) |
| 300 | + info "mise: run the following to activate mise in your shell:" |
| 301 | + info "echo \"$install_path activate fish | source\" >> ~/.config/fish/config.fish" |
| 302 | + info "" |
| 303 | + info "mise: run \`mise doctor\` to verify this is set up correctly" |
| 304 | + ;; |
| 305 | + *) |
| 306 | + info "mise: run \`$install_path --help\` to get started" |
| 307 | + ;; |
| 308 | + esac |
| 309 | +} |
| 310 | + |
| 311 | +install_mise |
| 312 | +if [ "${MISE_INSTALL_HELP-}" != 0 ]; then |
| 313 | + after_finish_help |
| 314 | +fi |
0 commit comments