2024-04-30 23:25:12 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
main() {
|
|
|
|
platform="$(uname -s)"
|
|
|
|
arch="$(uname -m)"
|
2024-05-02 06:51:38 +03:00
|
|
|
channel="${ZED_CHANNEL:-stable}"
|
2024-04-30 23:25:12 +03:00
|
|
|
temp="$(mktemp -d "/tmp/zed-XXXXX")"
|
|
|
|
|
|
|
|
if [[ $platform == "Darwin" ]]; then
|
|
|
|
platform="macos"
|
|
|
|
elif [[ $platform == "Linux" ]]; then
|
|
|
|
platform="linux"
|
2024-05-02 06:51:38 +03:00
|
|
|
channel="${ZED_CHANNEL:-preview}"
|
2024-04-30 23:25:12 +03:00
|
|
|
else
|
|
|
|
echo "Unsupported platform $platform"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $platform == "macos" ]] && [[ $arch == arm64* ]]; then
|
|
|
|
arch="aarch64"
|
|
|
|
elif [[ $arch = x86* || $arch == i686* ]]; then
|
|
|
|
arch="x86_64"
|
|
|
|
else
|
|
|
|
echo "Unsupported architecture $arch"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if which curl >/dev/null 2>&1; then
|
|
|
|
curl () {
|
|
|
|
command curl -fL "$@"
|
|
|
|
}
|
|
|
|
elif which wget >/dev/null 2>&1; then
|
|
|
|
curl () {
|
|
|
|
wget -O- "$@"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
echo "Could not find 'curl' or 'wget' in your path"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
"$platform" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
linux() {
|
2024-05-01 01:01:07 +03:00
|
|
|
echo "Downloading Zed"
|
2024-04-30 23:25:12 +03:00
|
|
|
curl "https://zed.dev/api/releases/$channel/latest/zed-linux-$arch.tar.gz" > "$temp/zed-linux-$arch.tar.gz"
|
|
|
|
|
2024-05-01 01:01:07 +03:00
|
|
|
suffix=""
|
|
|
|
if [[ $channel != "stable" ]]; then
|
|
|
|
suffix="-$channel"
|
|
|
|
fi
|
|
|
|
|
2024-05-03 12:03:55 +03:00
|
|
|
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
|
2024-05-02 06:51:38 +03:00
|
|
|
rm -rf "$HOME/.local/zed$suffix.app"
|
2024-05-01 01:01:07 +03:00
|
|
|
mkdir -p "$HOME/.local/zed$suffix.app"
|
2024-04-30 23:25:12 +03:00
|
|
|
tar -xzf "$temp/zed-linux-$arch.tar.gz" -C "$HOME/.local/"
|
|
|
|
|
2024-05-03 12:03:55 +03:00
|
|
|
# Setup ~/.local directories
|
2024-04-30 23:25:12 +03:00
|
|
|
mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
|
2024-05-03 12:03:55 +03:00
|
|
|
|
|
|
|
# Link the binary
|
2024-05-03 12:19:11 +03:00
|
|
|
binary_name="zed${suffix}"
|
|
|
|
ln -sf ~/.local/zed$suffix.app/bin/zed "$HOME/.local/bin/${binary_name}"
|
2024-05-03 12:03:55 +03:00
|
|
|
|
|
|
|
# Copy .desktop file
|
|
|
|
desktop_file_path="$HOME/.local/share/applications/${appid}.desktop"
|
|
|
|
cp ~/.local/zed$suffix.app/share/applications/zed$suffix.desktop "${desktop_file_path}"
|
|
|
|
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}"
|
2024-04-30 23:25:12 +03:00
|
|
|
|
2024-05-03 12:19:11 +03:00
|
|
|
if which "${binary_name}" >/dev/null 2>&1; then
|
|
|
|
echo "Zed has been installed. Run with '${binary_name}'"
|
2024-05-02 06:51:38 +03:00
|
|
|
else
|
2024-05-03 12:19:11 +03:00
|
|
|
echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
|
2024-05-01 01:01:07 +03:00
|
|
|
echo "Run:"
|
|
|
|
echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
|
|
|
|
echo " source ~/.bashrc"
|
2024-05-03 12:19:11 +03:00
|
|
|
echo "To run Zed now, '~/.local/bin/${binary_name}'"
|
2024-04-30 23:25:12 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
macos() {
|
2024-05-01 01:01:07 +03:00
|
|
|
echo "Downloading Zed"
|
2024-04-30 23:25:12 +03:00
|
|
|
curl "https://zed.dev/api/releases/$channel/latest/Zed-$arch.dmg" > "$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
|
2024-05-02 06:51:38 +03:00
|
|
|
ditto "$temp/mount/$app" "/Applications/$app"
|
2024-04-30 23:25:12 +03:00
|
|
|
hdiutil detach -quiet "$temp/mount"
|
2024-05-02 06:51:38 +03:00
|
|
|
|
|
|
|
echo "Zed has been installed. Run with 'open /Applications/$app'"
|
2024-04-30 23:25:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|