mirror of
https://github.com/zed-industries/zed.git
synced 2026-08-09 00:53:44 +00:00
# Objective Prevent successful installations on 32-bit Linux architectures where the `zed` binary will **fail to execute** post-installation. Rather, fail at installation time with a proper verdict. `script/install.sh` maps `uname -m` onto the two architectures Zed publishes builds for. Two of the matchers named 32-bit userlands and mapped them onto a 64-bit tarball: - `linux-armhf` mapped to `aarch64` - `linux-i686*` mapped to `x86_64` Neither can execute the binary it selected. Tested on i386 Debian Trixie container: the installer downloaded, unpacked, symlinked and reported success, and the failure surfaced later as an exec error -- see [Showcase](##showcase). Thus the installer's correct behavior would be to reject the 32-bit architecture and terminate with an "unsupported" verdict. ## Solution Remove the case-statement-based mapping of `linux-armhf` to `aarch64`, and of `linux-i686*` to `x86_64`. ## Testing Tested in isolation, simulating supported and unsupported platforms, and supported and unsupported architectures: | Platform | `uname -m` | Outcome | | --- | --- | --- | | Linux | `x86_64` | ✅ Installed — resolves to `x86_64`, symlink created | | Linux | `i386` | ❌ Unsupported — `i386` doesn't match glob `x86*` (no case handles plain i386 anyway | | Linux | `i686` | ❌ Unsupported — same reason | | Linux | `aarch64` | ✅ Installed — resolves to `aarch64` | | Linux | `arm64` | ✅ Installed — resolves to `aarch64` | | Linux | `armv7l` | ❌ Unsupported — no 32-bit ARM case | | Linux | `riscv64` | ❌ Unsupported | | Darwin | `arm64` | ✅ Installed — resolves to `aarch64`, copied to real `/Applications/Zed.app`, symlink created; | | Darwin | `x86_64` | ✅ Installed — resolves to `x86_64`, copied to real `/Applications/Zed.app`, symlink created | | Darwin | `i386` | ❌ Unsupported — no case for macOS 32-bit | | FreeBSD | `x86_64` | ❌ Unsupported platform - expected | This is all correct behavior. Successful installations are expected to work. Unsupported architectures are detected and rejected as unsupported during installation. ## Showcase ```plaintext ~# file /usr/bin/dash # a sample executable showing the 32-bit arch /usr/bin/dash: ELF 32-bit LSB pie executable, Intel i386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=7e2e8652114c8c2ae595b6f78798716a9ba07671, for GNU/Linux 3.2.0, stripped ~# file .local/zed.app/bin/zed .local/zed.app/bin/zed: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=e550eeb1d97f0cdac2460de672bfa36e9e3f6e25, not stripped ~# .local/zed.app/bin/zed bash: .local/zed.app/bin/zed: cannot execute: required file not found # It cannot find ELF 64-bit interpreter /lib64/ld-linux-x86-64.so.2 -- this is # a 32-bit container on a 64-bit host. On a genuine 32-bit host it would fail with: # `Exec format error`. ``` ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Locally conducted tests cover the new/changed behavior --- Release Notes: - N/A
161 lines
4.8 KiB
Bash
Executable file
161 lines
4.8 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
# Downloads a tarball from https://zed.dev/releases and unpacks it
|
|
# into ~/.local/. If you'd prefer to do this manually, instructions are at
|
|
# https://zed.dev/docs/linux.
|
|
|
|
main() {
|
|
platform="$(uname -s)"
|
|
arch="$(uname -m)"
|
|
channel="${ZED_CHANNEL:-stable}"
|
|
ZED_VERSION="${ZED_VERSION:-latest}"
|
|
# Use TMPDIR if available (for environments with non-standard temp directories)
|
|
if [ -n "${TMPDIR:-}" ] && [ -d "${TMPDIR}" ]; then
|
|
temp="$(mktemp -d "$TMPDIR/zed-XXXXXX")"
|
|
else
|
|
temp="$(mktemp -d "/tmp/zed-XXXXXX")"
|
|
fi
|
|
|
|
if [ "$platform" = "Darwin" ]; then
|
|
platform="macos"
|
|
elif [ "$platform" = "Linux" ]; then
|
|
platform="linux"
|
|
else
|
|
echo "Unsupported platform $platform"
|
|
exit 1
|
|
fi
|
|
|
|
case "$platform-$arch" in
|
|
macos-arm64* | linux-arm64* | linux-aarch64)
|
|
arch="aarch64"
|
|
;;
|
|
macos-x86* | linux-x86*)
|
|
arch="x86_64"
|
|
;;
|
|
*)
|
|
echo "Unsupported platform or architecture"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
if command -v curl >/dev/null 2>&1; then
|
|
curl () {
|
|
command curl -fL "$@"
|
|
}
|
|
elif command -v wget >/dev/null 2>&1; then
|
|
curl () {
|
|
wget -O- "$@"
|
|
}
|
|
else
|
|
echo "Could not find 'curl' or 'wget' in your path"
|
|
exit 1
|
|
fi
|
|
|
|
"$platform" "$@"
|
|
|
|
if [ "$(command -v zed)" = "$HOME/.local/bin/zed" ]; then
|
|
echo "Zed has been installed. Run with 'zed'"
|
|
else
|
|
echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
|
|
echo "Run:"
|
|
|
|
case "$SHELL" in
|
|
*zsh)
|
|
echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.zshrc"
|
|
echo " source ~/.zshrc"
|
|
;;
|
|
*fish)
|
|
echo " fish_add_path -U $HOME/.local/bin"
|
|
;;
|
|
*)
|
|
echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
|
|
echo " source ~/.bashrc"
|
|
;;
|
|
esac
|
|
|
|
echo "To run Zed now, '~/.local/bin/zed'"
|
|
fi
|
|
}
|
|
|
|
linux() {
|
|
if [ -n "${ZED_BUNDLE_PATH:-}" ]; then
|
|
cp "$ZED_BUNDLE_PATH" "$temp/zed-linux-$arch.tar.gz"
|
|
else
|
|
echo "Downloading Zed version: $ZED_VERSION"
|
|
curl "https://cloud.zed.dev/releases/$channel/$ZED_VERSION/download?asset=zed&arch=$arch&os=linux&source=install.sh" > "$temp/zed-linux-$arch.tar.gz"
|
|
fi
|
|
|
|
suffix=""
|
|
if [ "$channel" != "stable" ]; then
|
|
suffix="-$channel"
|
|
fi
|
|
|
|
appid=""
|
|
case "$channel" in
|
|
stable)
|
|
appid="dev.zed.Zed"
|
|
;;
|
|
nightly)
|
|
appid="dev.zed.Zed-Nightly"
|
|
;;
|
|
preview)
|
|
appid="dev.zed.Zed-Preview"
|
|
;;
|
|
dev)
|
|
appid="dev.zed.Zed-Dev"
|
|
;;
|
|
*)
|
|
echo "Unknown release channel: ${channel}. Using stable app ID."
|
|
appid="dev.zed.Zed"
|
|
;;
|
|
esac
|
|
|
|
# Unpack
|
|
rm -rf "$HOME/.local/zed$suffix.app"
|
|
mkdir -p "$HOME/.local/zed$suffix.app"
|
|
tar -xzf "$temp/zed-linux-$arch.tar.gz" -C "$HOME/.local/"
|
|
|
|
# Setup ~/.local directories
|
|
mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
|
|
|
|
# Link the binary
|
|
if [ -f "$HOME/.local/zed$suffix.app/bin/zed" ]; then
|
|
ln -sf "$HOME/.local/zed$suffix.app/bin/zed" "$HOME/.local/bin/zed"
|
|
else
|
|
# support for versions before 0.139.x.
|
|
ln -sf "$HOME/.local/zed$suffix.app/bin/cli" "$HOME/.local/bin/zed"
|
|
fi
|
|
|
|
# Copy .desktop file
|
|
desktop_file_path="$HOME/.local/share/applications/${appid}.desktop"
|
|
src_dir="$HOME/.local/zed$suffix.app/share/applications"
|
|
if [ -f "$src_dir/${appid}.desktop" ]; then
|
|
cp "$src_dir/${appid}.desktop" "${desktop_file_path}"
|
|
else
|
|
# Fallback for older tarballs
|
|
cp "$src_dir/zed$suffix.desktop" "${desktop_file_path}"
|
|
fi
|
|
sed -i "s|Icon=zed|Icon=$HOME/.local/zed$suffix.app/share/icons/hicolor/512x512/apps/zed.png|g" "${desktop_file_path}"
|
|
sed -i "s|Exec=zed|Exec=$HOME/.local/zed$suffix.app/bin/zed|g" "${desktop_file_path}"
|
|
}
|
|
|
|
macos() {
|
|
echo "Downloading Zed version: $ZED_VERSION"
|
|
curl "https://cloud.zed.dev/releases/$channel/$ZED_VERSION/download?asset=zed&os=macos&arch=$arch&source=install.sh" > "$temp/Zed-$arch.dmg"
|
|
hdiutil attach -quiet "$temp/Zed-$arch.dmg" -mountpoint "$temp/mount"
|
|
app="$(cd "$temp/mount/"; echo *.app)"
|
|
echo "Installing $app"
|
|
if [ -d "/Applications/$app" ]; then
|
|
echo "Removing existing $app"
|
|
rm -rf "/Applications/$app"
|
|
fi
|
|
ditto "$temp/mount/$app" "/Applications/$app"
|
|
hdiutil detach -quiet "$temp/mount"
|
|
|
|
mkdir -p "$HOME/.local/bin"
|
|
# Link the binary
|
|
ln -sf "/Applications/$app/Contents/MacOS/cli" "$HOME/.local/bin/zed"
|
|
}
|
|
|
|
main "$@"
|