#!/bin/sh # Copyright 2026 Idyl Labs # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Installs the IDYL CLI for the current user on macOS or Linux. No root. # # curl -fsSL /cli | sh # curl -fsSL /cli | sh -s -- --channel latest # curl -fsSL /cli | sh -s -- --uninstall # # The release is verified before it is installed: the channel statement and # release manifest must be signed by a trusted IDYL key (checked with # OpenSSL on Linux), the binary must match the manifest, and on macOS the # binary must carry IDYL's Developer ID signature. # # Layout (the CLI keeps it current with background updates): # ~/.local/share/idyl/versions//idyl each installed version # ~/.local/share/idyl/install.json launcher, channel, updates # ~/.local/bin/idyl link to the current version # # When ~/.local/bin is not on PATH, the installer adds it with one marked # block at the end of the startup file of your shell ($SHELL): ~/.zshrc, # ~/.bashrc, ~/.bash_profile or ~/.profile, or a file in fish's conf.d. # Nothing outside your home directory is changed. --no-modify-path (or # IDYL_NO_MODIFY_PATH=1) leaves startup files alone. # # --uninstall removes the launcher, the installed versions, install.json, # the update state and the PATH block. Your configuration and credentials # (IDYL_HOME, or ~/.config/idyl) are kept, and an idyl a package manager # installed is never touched. # # The download site publishes this script with SITE_URL and TRUSTED_KEYS # filled in; the copy in the source repository is a template. set -eu SITE_URL="https://get.idyl.sh" # Comma-separated base64 raw Ed25519 public keys trusted to sign releases. TRUSTED_KEYS="UScMxGRAYL+gRmjgaD6mLtwuRUb9RI1/g3RhY9VbHpU=" # The Apple Developer team that signs IDYL's macOS releases. MACOS_TEAM_ID="2B6R3TC7HJ" log() { printf 'idyl-install: %s\n' "$*" >&2; } fail() { printf 'idyl-install: ERROR: %s\n' "$*" >&2; exit 1; } usage() { cat >&2 <<'USAGE' Usage: install.sh [--channel stable|latest] [--no-modify-path] install.sh --uninstall --channel the release channel to install and follow (default: stable) --no-modify-path do not add ~/.local/bin to PATH in your shell's startup file (or set IDYL_NO_MODIFY_PATH=1) --uninstall remove the script install and the PATH block it added; your configuration and credentials are kept USAGE } need() { command -v "$1" >/dev/null 2>&1 || fail "$1 is required; $2" } # fetch downloads a URL to a file, failing loudly on any HTTP error, with # retries and a hard time limit so a bad network cannot hang the install. fetch() { curl -fsSL --proto '=https' --tlsv1.2 --retry 3 --retry-delay 1 --max-time 300 -o "$2" "$1" \ || fail "download failed: $1" } sha512() { if command -v sha512sum >/dev/null 2>&1; then sha512sum "$1" | awk '{print $1}' else shasum -a 512 "$1" | awk '{print $1}' fi } # json_string FILE KEY prints the string value of KEY in a compact JSON # object written by the release tooling. json_string() { sed -n "s/.*\"$2\":\"\([^\"]*\)\".*/\1/p" "$1" | head -n 1 } # verify_signature FILE checks FILE.sig against the trusted keys with # OpenSSL. Ed25519 public keys are wrapped in their fixed DER prefix. verify_signature() { sig_b64="$(json_string "$1.sig" signature)" [ -n "$sig_b64" ] || fail "$(basename "$1").sig is not a signature file" printf '%s' "$sig_b64" | base64 -d >"$WORK/sig.bin" 2>/dev/null \ || fail "$(basename "$1").sig carries a malformed signature" old_ifs="$IFS" IFS=, for key in $TRUSTED_KEYS; do IFS="$old_ifs" { printf '\060\052\060\005\006\003\053\145\160\003\041\000' printf '%s' "$key" | base64 -d } >"$WORK/key.der" 2>/dev/null || continue if openssl pkeyutl -verify -pubin -keyform DER -inkey "$WORK/key.der" \ -rawin -in "$1" -sigfile "$WORK/sig.bin" >/dev/null 2>&1; then return 0 fi done IFS="$old_ifs" fail "$(basename "$1") is not signed by a trusted IDYL key; refusing to install" } # --- PATH ---------------------------------------------------------------------- # The block this installer adds to a shell startup file is this comment line # and the line path_line prints after it. Both lines identify the block, so # it is written once and removed exactly. PATH_MARK='# Added by the IDYL CLI installer; remove with its --uninstall option' # path_line FILE prints the second line of the block for FILE. $HOME and # $PATH stay literal for the startup file to expand. The sh line adds the # directory once however often the file is read; fish_add_path --path does # the same and leaves no universal variable behind. # shellcheck disable=SC2016 path_line() { case "$1" in *.fish) printf '%s\n' 'fish_add_path --path "$HOME/.local/bin"' ;; *) printf '%s\n' 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) export PATH="$HOME/.local/bin:$PATH" ;; esac' ;; esac } # on_path reports whether ~/.local/bin is on this process's PATH. on_path() { case ":${PATH:-}:" in *":$HOME/.local/bin:"* | *":$HOME/.local/bin/:"*) return 0 ;; esac return 1 } # fish_file prints the file the installer owns in fish's conf.d. fish_file() { printf '%s\n' "${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/idyl.fish" } # startup_files prints, one per line, the startup files that a new terminal # of the user's shell reads: where the block goes. startup_files() { case "$(basename "${SHELL:-sh}")" in zsh) printf '%s\n' "${ZDOTDIR:-$HOME}/.zshrc" ;; bash) if [ "$(uname -s)" = Darwin ]; then # Terminal windows on macOS start login shells, which read # the first of these that exists, and not ~/.bashrc. if [ -f "$HOME/.bash_profile" ]; then printf '%s\n' "$HOME/.bash_profile" elif [ -f "$HOME/.bash_login" ]; then printf '%s\n' "$HOME/.bash_login" else printf '%s\n' "$HOME/.profile" fi if [ -f "$HOME/.bashrc" ]; then printf '%s\n' "$HOME/.bashrc"; fi else printf '%s\n' "$HOME/.bashrc" fi ;; fish) fish_file ;; *) printf '%s\n' "$HOME/.profile" ;; esac } # has_block FILE reports whether FILE holds the block. has_block() { [ -f "$1" ] || return 1 MARK="$PATH_MARK" LINE="$(path_line "$1")" awk ' prev == ENVIRON["MARK"] && $0 == ENVIRON["LINE"] { found = 1 } { prev = $0 } END { exit !found }' "$1" 2>/dev/null } # add_block FILE appends the block to FILE after a blank line, creating # FILE, and fish's conf.d directory, when they do not exist yet. add_block() { case "$1" in *.fish) mkdir -p "$(dirname "$1")" 2>/dev/null || return 1 ;; esac line="$(path_line "$1")" blank='' if [ -s "$1" ]; then # A last line without a newline is ended first. if [ -n "$(tail -c 1 "$1")" ]; then blank=2; else blank=1; fi fi { case "$blank" in 2) printf '\n\n' ;; 1) printf '\n' ;; esac printf '%s\n%s\n' "$PATH_MARK" "$line" } 2>/dev/null >>"$1" } # remove_block FILE removes every block from FILE, each with the blank line # add_block put before it. FILE is rewritten in place, so a symbolic link # stays a link. The fish file holds nothing else and is deleted once empty. remove_block() { has_block "$1" || return 1 kept="$(mktemp "${TMPDIR:-/tmp}/idyl-install.XXXXXX")" || return 1 if MARK="$PATH_MARK" LINE="$(path_line "$1")" awk ' { line[NR] = $0 } END { for (i = 1; i <= NR; i++) { if (line[i] == ENVIRON["MARK"] && i < NR && line[i + 1] == ENVIRON["LINE"]) { if (i > 1 && line[i - 1] == "") drop[i - 1] = 1 drop[i] = 1 drop[i + 1] = 1 i++ } } for (i = 1; i <= NR; i++) if (!(i in drop)) print line[i] }' "$1" >"$kept" && cat "$kept" 2>/dev/null >"$1"; then rm -f "$kept" else rm -f "$kept" return 1 fi case "$1" in *.fish) if [ -z "$(tr -d ' \t\n' <"$1")" ]; then rm -f "$1"; fi ;; esac return 0 } # add_to_path adds the block to the startup files of the user's shell, # naming each file it changed, and fails when it could write none. add_to_path() { added=false old_ifs="$IFS" IFS=' ' for file in $(startup_files); do IFS="$old_ifs" if has_block "$file"; then log "$file already adds ~/.local/bin to PATH" added=true elif add_block "$file"; then log "added ~/.local/bin to PATH in $file" added=true else log "could not write to $file" fi done IFS="$old_ifs" $added } # remove_from_path removes the block from every startup file the installer # writes to, naming each file it changed, and fails when there was none. remove_from_path() { removed=false for file in "${ZDOTDIR:-$HOME}/.zshrc" "$HOME/.zshrc" "$HOME/.bashrc" "$HOME/.bash_profile" \ "$HOME/.bash_login" "$HOME/.profile" "$(fish_file)"; do if remove_block "$file"; then log "removed the PATH block from $file" removed=true elif has_block "$file"; then log "could not edit $file; remove the IDYL CLI installer's comment and the line after it yourself" fi done $removed } # --- uninstall ------------------------------------------------------------------- # managed_by FILE prints the package manager that owns FILE, if any. managed_by() { if command -v brew >/dev/null 2>&1; then prefix="$(brew --prefix 2>/dev/null || true)" if [ -n "$prefix" ]; then case "$1" in "$prefix"/*) echo Homebrew; return ;; esac fi fi if command -v dpkg >/dev/null 2>&1 && dpkg -S "$1" >/dev/null 2>&1; then echo dpkg; return; fi if command -v rpm >/dev/null 2>&1 && rpm -qf "$1" >/dev/null 2>&1; then echo rpm; return; fi } # uninstall removes what the installer put in place: the launcher, provided # it is the link into a script install's versions directory; that install's # versions, install.json and update state; and the PATH block. It removes # nothing when the launcher is anything else, and never touches the CLI's # configuration and credentials or another idyl on PATH. uninstall() { [ -n "${HOME:-}" ] || fail "HOME is not set" launcher="$HOME/.local/bin/idyl" root="${XDG_DATA_HOME:-$HOME/.local/share}/idyl" if [ -L "$launcher" ]; then link="$(readlink "$launcher")" case "$link" in /*/versions/*/idyl) root="${link%/versions/*}" ;; *) fail "$launcher links to $link, not to a script install of idyl; nothing was removed" ;; esac [ -f "$root/install.json" ] \ || fail "$launcher links to $link, but $root holds no script install of idyl; nothing was removed" elif [ -e "$launcher" ]; then owner="$(managed_by "$launcher")" fail "$launcher is not the link this installer makes${owner:+ (it belongs to $owner)}; nothing was removed" fi found=false if [ -L "$launcher" ]; then rm -f "$launcher" && log "removed $launcher" found=true fi if [ -d "$root/versions" ]; then rm -rf "${root:?}/versions" && log "removed $root/versions" found=true fi for file in install.json update-state.json update.lock; do if [ -e "$root/$file" ]; then rm -f "${root:?}/$file" && log "removed $root/$file" found=true fi done if [ -d "$root" ] && rmdir "$root" 2>/dev/null; then log "removed $root"; fi if remove_from_path; then found=true; fi $found || log "no script install of idyl was found" other="$(command -v idyl 2>/dev/null || true)" if [ -n "$other" ]; then owner="$(managed_by "$other")" log "another idyl remains at $other${owner:+, installed by $owner}; it was left alone" fi log "your configuration and credentials in ${IDYL_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}/idyl} were kept; to end your sign-in, run 'idyl logout --all' before uninstalling" } main() { channel=stable remove=false modify_path=true case "${IDYL_NO_MODIFY_PATH:-}" in '' | 0) ;; *) modify_path=false ;; esac while [ $# -gt 0 ]; do case "$1" in --channel) [ $# -ge 2 ] || { usage; exit 2; } channel="$2" shift 2 ;; --no-modify-path) modify_path=false; shift ;; --uninstall) remove=true; shift ;; -h|--help) usage; exit 0 ;; *) usage; fail "unknown argument: $1" ;; esac done case "$channel" in stable|latest) ;; *) fail "unknown channel '$channel' (want stable or latest)" ;; esac if $remove; then uninstall return fi case "$SITE_URL$TRUSTED_KEYS" in *@IDYL_*) fail "this copy of install.sh is a template; download the installer from IDYL's download site" ;; esac case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "unsupported operating system: $(uname -s); use install.ps1 on Windows" ;; esac case "$(uname -m)" in x86_64|amd64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; *) fail "unsupported architecture: $(uname -m)" ;; esac platform="${os}_${arch}" need curl "install curl and run the installer again" if [ "$os" = linux ]; then need openssl "it verifies the release signature; install OpenSSL 1.1.1 or newer and run the installer again" else need codesign "it verifies the release's Developer ID signature" fi [ -n "${HOME:-}" ] || fail "HOME is not set" root="${XDG_DATA_HOME:-$HOME/.local/share}/idyl" launcher="$HOME/.local/bin/idyl" mkdir -p "$root/versions" "$(dirname "$launcher")" WORK="$(mktemp -d "$root/versions/.staging-XXXXXX")" trap 'rm -rf "$WORK"' EXIT INT TERM # The channel statement names the release and its manifest's digest. fetch "$SITE_URL/cli/channels/$channel.json" "$WORK/channel.json" fetch "$SITE_URL/cli/channels/$channel.json.sig" "$WORK/channel.json.sig" if [ "$os" = linux ]; then verify_signature "$WORK/channel.json"; fi [ "$(json_string "$WORK/channel.json" product)" = idyl ] || fail "the channel statement is not for the IDYL CLI" [ "$(json_string "$WORK/channel.json" channel)" = "$channel" ] || fail "the channel statement is not for $channel" version="$(json_string "$WORK/channel.json" version)" manifest_sha="$(json_string "$WORK/channel.json" manifestSha512)" case "$version" in '' | *[!0-9.]*) fail "the channel statement names an invalid version" ;; esac # The manifest is the one the statement commits to. fetch "$SITE_URL/cli/releases/$version/manifest.json" "$WORK/manifest.json" fetch "$SITE_URL/cli/releases/$version/manifest.json.sig" "$WORK/manifest.json.sig" [ "$(sha512 "$WORK/manifest.json")" = "$manifest_sha" ] \ || fail "the manifest for $version does not match its channel statement; refusing to install" if [ "$os" = linux ]; then verify_signature "$WORK/manifest.json"; fi entry="$(sed -n "s/.*\"$platform\":{\"path\":\"\([^\"]*\)\",\"sha512\":\"\([0-9a-f]*\)\",\"size\":\([0-9]*\)}.*/\1 \2 \3/p" "$WORK/manifest.json")" [ -n "$entry" ] || fail "release $version has no binary for $platform" # Split "path sha512 size"; none of the fields contain spaces. # shellcheck disable=SC2086 set -- $entry path="$1" want_sha="$2" [ "$path" = "$platform/idyl" ] || fail "the manifest lists an unexpected path for $platform" log "downloading idyl $version ($channel, $platform)" fetch "$SITE_URL/cli/releases/$version/$path" "$WORK/idyl" [ "$(sha512 "$WORK/idyl")" = "$want_sha" ] \ || fail "the downloaded binary does not match the release manifest; refusing to install" chmod 0755 "$WORK/idyl" if [ "$os" = darwin ]; then codesign --verify --strict "$WORK/idyl" 2>/dev/null \ || fail "the downloaded binary carries no valid code signature; refusing to install" codesign -dvv "$WORK/idyl" 2>&1 | grep -qx "TeamIdentifier=$MACOS_TEAM_ID" \ || fail "the downloaded binary is not signed by IDYL (team $MACOS_TEAM_ID); refusing to install" fi # Keep the user's choice about background updates across reinstalls. background=true if [ -f "$root/install.json" ] && grep -q '"backgroundUpdates": *false' "$root/install.json"; then background=false fi target="$root/versions/$version" if [ ! -x "$target/idyl" ]; then rm -rf "$target" mkdir "$WORK/release" mv "$WORK/idyl" "$WORK/release/idyl" mv "$WORK/release" "$target" fi ln -s "$target/idyl" "$launcher.new-$$" mv -f "$launcher.new-$$" "$launcher" printf '{\n "launcher": "%s",\n "channel": "%s",\n "backgroundUpdates": %s\n}\n' \ "$launcher" "$channel" "$background" >"$root/install.json.new-$$" mv -f "$root/install.json.new-$$" "$root/install.json" "$launcher" version >/dev/null || fail "the installed idyl does not run" log "installed idyl $version ($channel channel) at $launcher" # A piped installer cannot change the PATH of the shell that runs it; a # new terminal, or a new login shell in this one, reads the startup file. if on_path; then log "get started: idyl login" elif $modify_path && add_to_path; then if [ -n "${SHELL:-}" ]; then log "open a new terminal (or run 'exec $SHELL -l'), then get started: idyl login" else log "open a new terminal, then get started: idyl login" fi else log "$HOME/.local/bin is not on your PATH; add this line to your shell profile:" # The literal $PATH is what the user's profile needs. # shellcheck disable=SC2016 printf '\n export PATH="$HOME/.local/bin:$PATH"\n\n' >&2 log "get started: idyl login" fi } main "$@"