Make install.sh sh-compatible (#12899)

Co-Authored-By: Max <max@zed.dev>

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
Co-authored-by: Shyim <github@shyim.de>
This commit is contained in:
Conrad Irwin 2024-06-11 19:12:14 -06:00 committed by GitHub
parent ab41eddd8b
commit e16bbe048f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
#!/usr/bin/env sh
set -eu
main() {
platform="$(uname -s)"
@ -7,9 +7,9 @@ main() {
channel="${ZED_CHANNEL:-stable}"
temp="$(mktemp -d "/tmp/zed-XXXXX")"
if [[ $platform == "Darwin" ]]; then
if [ "$platform" = "Darwin" ]; then
platform="macos"
elif [[ $platform == "Linux" ]]; then
elif [ "$platform" = "Linux" ]; then
platform="linux"
channel="${ZED_CHANNEL:-preview}"
else
@ -17,14 +17,18 @@ main() {
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
case "$platform-$arch" in
macos-arm64*)
arch="aarch64"
;;
macos-x86* | linux-x86* | linux-i686*)
arch="x86_64"
;;
*)
echo "Unsupported platform or architecture"
exit 1
;;
esac
if which curl >/dev/null 2>&1; then
curl () {
@ -33,7 +37,7 @@ main() {
elif which wget >/dev/null 2>&1; then
curl () {
wget -O- "$@"
}
}
else
echo "Could not find 'curl' or 'wget' in your path"
exit 1
@ -51,7 +55,7 @@ linux() {
fi
suffix=""
if [[ $channel != "stable" ]]; then
if [ "$channel" != "stable" ]; then
suffix="-$channel"
fi
@ -84,16 +88,16 @@ linux() {
mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
# Link the binary
if [ -f ~/.local/zed$suffix.app/bin/zed ]; then
ln -sf ~/.local/zed$suffix.app/bin/zed "$HOME/.local/bin/zed"
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 ~/.local/zed$suffix.app/bin/cli "$HOME/.local/bin/zed"
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"
cp ~/.local/zed$suffix.app/share/applications/zed$suffix.desktop "${desktop_file_path}"
cp "$HOME/.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/libexec/zed-editor|g" "${desktop_file_path}"
@ -114,7 +118,7 @@ macos() {
hdiutil attach -quiet "$temp/Zed-$arch.dmg" -mountpoint "$temp/mount"
app="$(cd "$temp/mount/"; echo *.app)"
echo "Installing $app"
if [[ -d "/Applications/$app" ]]; then
if [ -d "/Applications/$app" ]; then
echo "Removing existing $app"
rm -rf "/Applications/$app"
fi
@ -123,7 +127,7 @@ macos() {
mkdir -p "$HOME/.local/bin"
# Link the binary
ln -sf /Applications/$app/Contents/MacOS/cli "$HOME/.local/bin/zed"
ln -sf "/Applications/$app/Contents/MacOS/cli" "$HOME/.local/bin/zed"
if which "zed" >/dev/null 2>&1; then
echo "Zed has been installed. Run with 'zed'"