installer (#11224)

Conrad Irwin and Mikayla created

Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>

Change summary

script/bundle-linux | 27 +++++++-------
script/install.sh   | 86 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 14 deletions(-)

Detailed changes

script/bundle-linux 🔗

@@ -43,33 +43,34 @@ strip "target/${target_triple}/release/Zed"
 # Move everything that should end up in the final package
 # into a temp directory.
 temp_dir=$(mktemp -d)
+zed_dir="${temp_dir}/zed.app"
 
 # Binary
-mkdir "${temp_dir}/bin"
-cp "target/${target_triple}/release/Zed" "${temp_dir}/bin/zed"
+mkdir -p "${zed_dir}/bin"
+cp "target/${target_triple}/release/Zed" "${zed_dir}/zed"
 
 # Icons
-mkdir -p "${temp_dir}/share/icons/hicolor/512x512/apps"
-cp "crates/zed/resources/app-icon-nightly.png" "${temp_dir}/share/icons/hicolor/512x512/apps/zed.png"
-mkdir -p "${temp_dir}/share/icons/hicolor/1024x1024/apps"
-cp "crates/zed/resources/app-icon-nightly@2x.png" "${temp_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
+mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
+cp "crates/zed/resources/app-icon-nightly.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"
+mkdir -p "${zed_dir}/share/icons/hicolor/1024x1024/apps"
+cp "crates/zed/resources/app-icon-nightly@2x.png" "${zed_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
 
 # .desktop
-mkdir -p "${temp_dir}/share/applications"
-cp "crates/zed/resources/zed.desktop" "${temp_dir}/share/applications/zed.desktop"
+mkdir -p "${zed_dir}/share/applications"
+cp "crates/zed/resources/zed.desktop" "${zed_dir}/share/applications/zed.desktop"
 
 # Licenses
-cp "assets/licenses.md" "${temp_dir}/licenses.md"
+cp "assets/licenses.md" "${zed_dir}/licenses.md"
 
 # Create archive out of everything that's in the temp directory
-
+target="linux-$(uname -m)"
 
 if [[ "$channel" == "nightly" ]]; then
-  archive="zed-${channel}-${target_triple}.tar.gz"
+  archive="zed-${target}.tar.gz"
 elif  [[ "$channel" == "dev" ]]; then
-  archive="zed-${channel}-${commit}-${target_triple}.tar.gz"
+  archive="zed-${commit}-${target}.tar.gz"
 else
-  archive="zed-${version}-${target_triple}.tar.gz"
+  archive="zed-${target}.tar.gz"
 fi
 
 rm -rf "${archive}"

script/install.sh 🔗

@@ -1 +1,85 @@
-#!/bin/sh
+#!/usr/bin/env bash
+set -euo pipefail
+
+main() {
+    platform="$(uname -s)"
+    arch="$(uname -m)"
+    channel="stable"
+    temp="$(mktemp -d "/tmp/zed-XXXXX")"
+
+    if [[ $platform == "Darwin" ]]; then
+        platform="macos"
+    elif [[ $platform == "Linux" ]]; then
+        platform="linux"
+        channel="nightly"
+    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() {
+    echo "Downloading zed.tar.gz"
+    # curl "https://zed.dev/api/download/zed.tar.gz?platform=$platform&arch=$arch&channel=$channel" > "$temp/zed.tar.gz"
+
+    curl "https://zed.dev/api/releases/$channel/latest/zed-linux-$arch.tar.gz" > "$temp/zed-linux-$arch.tar.gz"
+
+    mkdir -p "$HOME/.local/zed.app"
+    tar -xzf "$temp/zed-linux-$arch.tar.gz" -C "$HOME/.local/"
+
+    # Set up xdg links so that app shows in the dock
+    mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
+    ln -sf ~/.local/zed.app/bin/zed ~/.local/bin/
+    cp ~/.local/zed.app/share/applications/zed.desktop ~/.local/share/applications/
+    sed -i "s|Icon=zed|Icon=$HOME/.local/zed.app/share/icons/hicolor/512x512/apps/zed.png|g" ~/.local/share/applications/zed.desktop
+    sed -i "s|Exec=zed|Exec=$HOME/.local/zed.app/bin/zed|g" ~/.local/share/applications/zed.desktop
+
+    if which zed >/dev/null 2>&1; then
+    else
+        echo "To run zed from your terminal, you must add ~/.local/bin to your PATH"
+        exit 1
+    fi
+
+    ~/.local/bin/zed
+}
+
+macos() {
+    echo "Downloading Zed.dmg..."
+    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
+    ditto -v "$temp/mount/$app" "/Applications/$app"
+    hdiutil detach -quiet "$temp/mount"
+    open "/Applications/$app"
+}
+
+main "$@"