install.sh

 1#!/usr/bin/env bash
 2set -euo pipefail
 3
 4main() {
 5    platform="$(uname -s)"
 6    arch="$(uname -m)"
 7    channel="stable"
 8    temp="$(mktemp -d "/tmp/zed-XXXXX")"
 9
10    if [[ $platform == "Darwin" ]]; then
11        platform="macos"
12    elif [[ $platform == "Linux" ]]; then
13        platform="linux"
14        channel="nightly"
15    else
16        echo "Unsupported platform $platform"
17        exit 1
18    fi
19
20    if [[ $platform == "macos" ]] && [[ $arch == arm64* ]]; then
21        arch="aarch64"
22    elif [[ $arch = x86* || $arch == i686* ]]; then
23        arch="x86_64"
24    else
25        echo "Unsupported architecture $arch"
26        exit 1
27    fi
28
29    if which curl >/dev/null 2>&1; then
30        curl () {
31            command curl -fL "$@"
32        }
33    elif which wget >/dev/null 2>&1; then
34        curl () {
35    	    wget -O- "$@"
36         }
37    else
38    	echo "Could not find 'curl' or 'wget' in your path"
39    	exit 1
40    fi
41
42    "$platform" "$@"
43}
44
45linux() {
46    echo "Downloading zed.tar.gz"
47    # curl "https://zed.dev/api/download/zed.tar.gz?platform=$platform&arch=$arch&channel=$channel" > "$temp/zed.tar.gz"
48
49    curl "https://zed.dev/api/releases/$channel/latest/zed-linux-$arch.tar.gz" > "$temp/zed-linux-$arch.tar.gz"
50
51    mkdir -p "$HOME/.local/zed.app"
52    tar -xzf "$temp/zed-linux-$arch.tar.gz" -C "$HOME/.local/"
53
54    # Set up xdg links so that app shows in the dock
55    mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
56    ln -sf ~/.local/zed.app/bin/zed ~/.local/bin/
57    cp ~/.local/zed.app/share/applications/zed.desktop ~/.local/share/applications/
58    sed -i "s|Icon=zed|Icon=$HOME/.local/zed.app/share/icons/hicolor/512x512/apps/zed.png|g" ~/.local/share/applications/zed.desktop
59    sed -i "s|Exec=zed|Exec=$HOME/.local/zed.app/bin/zed|g" ~/.local/share/applications/zed.desktop
60
61    if which zed >/dev/null 2>&1; then
62    else
63        echo "To run zed from your terminal, you must add ~/.local/bin to your PATH"
64        exit 1
65    fi
66
67    ~/.local/bin/zed
68}
69
70macos() {
71    echo "Downloading Zed.dmg..."
72    curl "https://zed.dev/api/releases/$channel/latest/Zed-$arch.dmg" > "$temp/Zed-$arch.dmg"
73    hdiutil attach -quiet "$temp/Zed-$arch.dmg" -mountpoint "$temp/mount"
74    app="$(cd "$temp/mount/"; echo *.app)"
75    echo "Installing $app"
76    if [[ -d "/Applications/$app" ]]; then
77        echo "Removing existing $app"
78        rm -rf "/Applications/$app"
79    fi
80    ditto -v "$temp/mount/$app" "/Applications/$app"
81    hdiutil detach -quiet "$temp/mount"
82    open "/Applications/$app"
83}
84
85main "$@"