From 06b53ae438f6370e1c8fdd911d126f22a84c871a Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 22 Sep 2026 13:16:30 +0900 Subject: [PATCH] bundle: Ship install/uninstall scripts and enable remote server provisioning --- crates/zed/resources/install.sh | 48 +++++++++++++++ crates/zed/resources/uninstall.sh | 99 +++++++++++++++++++++++++++++++ script/bundle-linux | 8 ++- 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100755 crates/zed/resources/install.sh create mode 100755 crates/zed/resources/uninstall.sh diff --git a/crates/zed/resources/install.sh b/crates/zed/resources/install.sh new file mode 100755 index 0000000000..83d3aee2fa --- /dev/null +++ b/crates/zed/resources/install.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh +set -eu + +# Installs the Zed bundle this script ships with into ~/.local. +# Run from inside the extracted bundle directory: ./install.sh + +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +app_dir="" +for dir in "$script_dir"/zed-*.app; do + if [ -d "$dir" ]; then + app_dir=$dir + break + fi +done +if [ -z "$app_dir" ]; then + echo "Error: no zed-*.app bundle found in $script_dir" >&2 + exit 1 +fi + +app_name=${app_dir##*/} +suffix=${app_name#zed} +suffix=${suffix%.app} +target="$HOME/.local/zed$suffix.app" + +rm -rf "$target" +mkdir -p "$HOME/.local" +cp -R "$app_dir" "$target" + +# Ship the uninstaller inside the installation so the archive isn't needed to remove Zed +cp "$script_dir/uninstall.sh" "$target/uninstall.sh" + +mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications" +ln -sf "$target/bin/zed" "$HOME/.local/bin/zed" + +for desktop_file in "$target"/share/applications/*.desktop; do + installed_desktop="$HOME/.local/share/applications/${desktop_file##*/}" + cp "$desktop_file" "$installed_desktop" + # sed anchors on Exec to avoid rewriting TryExec + sed -i "s|^Exec=zed |Exec=$HOME/.local/bin/zed |g" "$installed_desktop" + sed -i "s|^Icon=zed|Icon=$target/share/icons/hicolor/512x512/apps/zed.png|g" "$installed_desktop" +done + +case ":$PATH:" in + *":$HOME/.local/bin:"*) ;; + *) echo "Note: add $HOME/.local/bin to your PATH to run zed from the command line." ;; +esac +echo "Zed installed to $target" diff --git a/crates/zed/resources/uninstall.sh b/crates/zed/resources/uninstall.sh new file mode 100755 index 0000000000..16f932ef0e --- /dev/null +++ b/crates/zed/resources/uninstall.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env sh +set -eu + +# Uninstalls a Zed installation created by the accompanying install.sh. +# Detects the installed channel automatically; override with ZED_CHANNEL. + +self_dir=$(CDPATH= cd -- "$(dirname -- "$0")" 2>/dev/null && pwd) || self_dir="" + +channel="${ZED_CHANNEL:-}" +suffix="" +if [ -n "$channel" ] && [ "$channel" != stable ]; then + suffix="-$channel" +fi + +app_dir="$HOME/.local/zed$suffix.app" +if [ -z "$channel" ]; then + app_dir="" + case "$self_dir" in + "$HOME"/.local/zed*.app) app_dir=$self_dir ;; + esac + if [ -z "$app_dir" ]; then + for dir in "$HOME"/.local/zed*.app; do + if [ -d "$dir" ]; then + app_dir=$dir + break + fi + done + fi + if [ -z "$app_dir" ]; then + echo "Zed is not installed in $HOME/.local" + exit 0 + fi + app_name=${app_dir##*/} + suffix=${app_name#zed} + suffix=${suffix%.app} + channel=${suffix#-} + if [ -z "$channel" ]; then + channel=stable + fi +fi + +appid="" +db_suffix="stable" +case "$channel" in + stable) + appid="dev.zed.Zed" + ;; + nightly) + appid="dev.zed.Zed-Nightly" + db_suffix="nightly" + ;; + preview) + appid="dev.zed.Zed-Preview" + db_suffix="preview" + ;; + dev) + appid="dev.zed.Zed-Dev" + db_suffix="dev" + ;; + *) + echo "Unknown release channel: ${channel}. Using stable app ID." + appid="dev.zed.Zed" + ;; +esac + +rm -rf "$app_dir" + +rm -f "$HOME/.local/bin/zed" + +rm -f "$HOME/.local/share/applications/${appid}.desktop" + +rm -rf "$HOME/.local/share/zed/db/0-$db_suffix" +rm -f "$HOME/.local/share/zed/zed-$db_suffix.sock" + +remaining=0 +for dir in "$HOME"/.local/zed*.app; do + if [ -d "$dir" ]; then + remaining=1 + fi +done +if [ "$remaining" -eq 0 ]; then + rm -rf "$HOME/.local/share/zed" + if [ -t 0 ]; then + printf "Do you want to keep your Zed preferences? [Y/n] " + read -r response + case "$response" in + [nN] | [nN][oO]) + rm -rf "$HOME/.config/zed" + echo "Preferences removed." + ;; + *) + echo "Preferences kept." + ;; + esac + fi + rm -rf "$HOME/.zed_server" +fi + +echo "Zed ($channel) has been uninstalled" diff --git a/script/bundle-linux b/script/bundle-linux index 1664fbf5dc..8b2967e1f7 100755 --- a/script/bundle-linux +++ b/script/bundle-linux @@ -83,7 +83,7 @@ if [[ "$(uname -m)" == "aarch64" ]]; then else export RUSTFLAGS="${RUSTFLAGS:-} -C link-args=-Wl,--disable-new-dtags,-rpath,\$ORIGIN/../lib" fi -cargo --config .cargo/bundle-config.toml build --release --target "${target_triple}" --package zed --package cli +cargo --config .cargo/bundle-config.toml build --release --target "${target_triple}" --package zed --package cli --features remote/build-remote-server-binary # Build remote_server in separate invocation to prevent feature unification from other crates # from influencing dynamic libraries required by it. if [[ "$remote_server_triple" == "$musl_triple" ]]; then @@ -199,6 +199,10 @@ mkdir -p "${zed_dir}/share/applications" envsubst < "crates/zed/resources/zed.desktop.in" > "${zed_dir}/share/applications/$APP_ID.desktop" chmod +x "${zed_dir}/share/applications/$APP_ID.desktop" +# Install/uninstall scripts ship in the archive root so it is self-contained +cp "crates/zed/resources/install.sh" "crates/zed/resources/uninstall.sh" "${temp_dir}/" +chmod 755 "${temp_dir}/install.sh" "${temp_dir}/uninstall.sh" + # Copy generated licenses so they'll end up in archive too cp "assets/licenses.md" "${zed_dir}/licenses.md" @@ -209,6 +213,6 @@ archive="zed-linux-${arch}.tar.gz" rm -rf "${archive}" remove_match="zed(-[a-zA-Z0-9]+)?-linux-$(uname -m)\.tar\.gz" ls "${target_dir}/release" | grep -E ${remove_match} | xargs -d "\n" -I {} rm -f "${target_dir}/release/{}" || true -tar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app" +tar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app" install.sh uninstall.sh gzip -f --stdout --best "${target_dir}/${remote_server_triple}/release/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"